set permissions programatically

Permalink 3 users found helpful
Anyone know how to set a pages permissions programmatically? Specifically, how to set a page to be accessible only to one user, and all its subpages inherit those permissions...

Thanks in advance

focus43
View Replies: View Best Answer
Mnkras replied on at Permalink Reply
Mnkras
focus43 replied on at Permalink Reply
focus43
I actually figured it out. This was a b*tch to say the least. For anyone who needs the code to do something similar, try this:

class CustomEvents extends Controller {
    public function setupClientPages($ui,$groupIDs){
        Loader::model('collection_types');
        $ct = CollectionType::getByHandle('client_pages'); // page type handle
        $u = $ui->getUserObject();
        $username = $u->getUserName();
        Loader::model('groups');
        $gObj = Group::getByName('Client');
        $cGroupID = $gObj->getGroupID();
        if(in_array($cGroupID,$groupIDs)){
            /*
             * Create new page w/ username as the page title
             */
            $clientArea = Page::getByPath('/client_area');
            $data['cName'] = $username;
Mnkras replied on at Permalink Reply
Mnkras
....

You can use Advanced Permissions! it is 100x easier!
focus43 replied on at Permalink Reply
focus43
Thanks for the responses. Believe me, I'm already well aware of advanced permissions. But I don't want to be setting up individual pages for each client every time a new one is added... much better to do it programatically.
DavidMIRV replied on at Permalink Reply
DavidMIRV
For advanced perms setting see:
http://blog.codedef.com/?p=40/
mcmspi replied on at Permalink Reply
mcmspi
That URL is no longer valid it seems Dave. But hope it helped others before it went offline.
lunatik replied on at Permalink Reply
Thanks so much,
I don't get (and, actually, don't wanna get) how concrete page permissions work: it's not really documented and the code is hard to read.

And you saved me a lot of time. Thanks for that.
francoiscote replied on at Permalink Reply
francoiscote
thanks a lot.

these Permission properties should really be documented somewhere, for people who need to set theses programmatically.
Mnkras replied on at Permalink Best Answer Reply
Mnkras
http://www.concrete5.org/community/forums/customizing_c5/programmatically_setting_advanced_permissions_example/#23267