Programmatically Setting Advanced Permissions Example
Permalink 6 users found helpful
since this isn't too well documented yet I'm just adding this as reference in case anyone else is looking for it.
$c = $this->getCollectionObj(); $pxml->guests['canRead'] = false; $pxml->registered['canRead'] = false; $pxml->group[0]['gID'] = ADMIN_GROUP_ID; $pxml->group[0]['canRead'] = true; $pxml->group[0]['canWrite'] = true; $pxml->group[0]['canApproveVersions'] = true; $pxml->group[0]['canDelete'] = true; $pxml->group[0]['canAdmin'] = true; $pxml->user[0]['uID']=$this->getUID(); $pxml->user[0]['canRead'] = true; $pxml->user[0]['canWrite'] = false; $pxml->user[0]['canAdmin'] = false; $c->assignPermissionSet($pxml);
guess it would be something like:
$pxml->guests['canRead'] = false;
$pxml->registered['canRead'] = true;
$page->assignPermissionSet($pxml);
as far as that error goes, just make sure you've got that class included:
Loader::model('collection_attributes');
$pxml->guests['canRead'] = false;
$pxml->registered['canRead'] = true;
$page->assignPermissionSet($pxml);
as far as that error goes, just make sure you've got that class included:
Loader::model('collection_attributes');
Thanks Tony, I will give it a shot.
Is there an example of doing something similar with simple permissions?
Tony,
Can you tell me where I can modify these permissions within the core?
Can you tell me where I can modify these permissions within the core?
what are you trying to do? where you make these changes depends on that.
have you tried just turning on advanced permissions and seeing what the user interface provides?
have you tried just turning on advanced permissions and seeing what the user interface provides?
what he/she is trying to do is to disable users from moving pages they don't have permissions for.
the permissions that you can access via advanced permissions are all the permissions, there are no others,
if that's the case, I'm not sure if the sitemap allows for that kind of thing. It may just have the one permission setting for access to the sitemap, and all those who have access to that page have the ability to move pages around. If he/she is trying to modify the sitemap core code to prevent that kind of thing, then she wouldn't need any of the code shown above, just a check to see if that page was editable by that user.
yea, as Tony said, i checked the core, there is nothing hidden permission wise, everything you can do in the code, you can do in the CMS,
my bad, i thought there might be a permission setting canMove for pages, but it looks not. don't see how the check would help though, if you can't restrict it after checking.
Hi Tony,
I was wondering if you know of a way to set area permissions on a newly created page?
(version 5.5.2)
I was wondering if you know of a way to set area permissions on a newly created page?
(version 5.5.2)
Nowadays (5.6) you can do things like the following:
Note that assignPermissions() isn't as flexible as setting up the permission keys/assignments from scratch. You can only assign permissions to single users, groups, or group combinations and not other access entities like group sets, page creator, etc; also, you can't set "details" for permission access objects like collection type restrictions for add_subpage or property restrictions for edit_page_properties. To control these you need to dig deeper and manipulate the PermissionAccess objects manually (at least as far as I've found—if someone knows a shortcut I'd very much like to hear about it since it can be a pain to do things at the lower level).
// If the page isn't already set to override, $page->assignPermissions() will // do that for us and clear out all pre-existing permissions. In this case we // want to *add* to pre-existing permissions, so we have to do it ourselves. $page->setPermissionsToManualOverride(); $allPagePermissionKeys = PermissionKey::getList('page'); $allPagePermissionKeyHandles = array_map(function($permissionKey) { return $permissionKey->getPermissionKeyHandle(); }, $allPagePermissionKeys); // Ninjas can do anything to the page. $page->assignPermissions(Group::getByName('Ninjas'), $allPagePermissionKeyHandles); // Proofreaders can only do some things. $page->assignPermissions(Group::getByName('Proofreaders'), array( 'view_page_versions', 'approve_page_versions', 'delete_page_versions',
Viewing 15 lines of 20 lines. View entire code block.
Note that assignPermissions() isn't as flexible as setting up the permission keys/assignments from scratch. You can only assign permissions to single users, groups, or group combinations and not other access entities like group sets, page creator, etc; also, you can't set "details" for permission access objects like collection type restrictions for add_subpage or property restrictions for edit_page_properties. To control these you need to dig deeper and manipulate the PermissionAccess objects manually (at least as far as I've found—if someone knows a shortcut I'd very much like to hear about it since it can be a pain to do things at the lower level).
Here's a list of all permission keys:
http://www.concrete5.org/community/forums/customizing_c5/how-to-set...
http://www.concrete5.org/community/forums/customizing_c5/how-to-set...
what is the easiest way to remove a page from the public eyes? like make it for guests unavailable?
I was using the following but sometimes I am getting an error...
my error is
Help :)..