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
Thanks in advance
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;
Viewing 15 lines of 43 lines. View entire code block.
....
You can use Advanced Permissions! it is 100x easier!
You can use Advanced Permissions! it is 100x easier!
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.
For advanced perms setting see:
http://blog.codedef.com/?p=40/
http://blog.codedef.com/?p=40/
That URL is no longer valid it seems Dave. But hope it helped others before it went offline.
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.
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.
thanks a lot.
these Permission properties should really be documented somewhere, for people who need to set theses programmatically.
these Permission properties should really be documented somewhere, for people who need to set theses programmatically.
http://www.concrete5.org/community/forums/customizing_c5/programmatically_setting_advanced_permissions_example/#23267
http://www.concrete5.org/help/building_with_concrete5/installation/...