I've wondered how to do this for awhile. I knew about the $page->assignPermissionSet($xml) method, but that doesn't allow for setting sub-page permissions, IE what kinds of collections users and groups are allowed to add beneath a page. I did some digging today, and it appears there's a $page->updatePermissions($array) function that takes a much more detailed array and uses that. Here's kind of what that array should look like.
Here I'm basically assuming there's a form posting to this script with a few details. It's going to allow the groups "Administrators" and "Page Type Administrators" and then the user who is submitting the form. The user submitting the form is not allowed to delete.
Loader::model("collection_types");$data=$_POST;$parent= Page::getByPath($data['cParentID']);$page_data=array('cName'=>$data['cName'],'cDescription'=>$data['description'],'uID'=>$data['uID'],'cHandle'=>$data['handle']);$ct= CollectionType::getByHandle($data['ctHandle']);$newPage=$parent->add($ct,$page_data);$ptaID= Group::getByName("Page Type Administrators")->getGroupID();$perm=array();// Overall Permissions $perm['cInheritPermissionsFrom']="OVERRIDE";// subpages inherit permissions from this page
Loader::model("collection_types");$data=$_POST;$parent= Page::getByPath($data['cParentID']);$page_data=array('cName'=>$data['cName'],'cDescription'=>$data['description'],'uID'=>$data['uID'],'cHandle'=>$data['handle']);$ct= CollectionType::getByHandle($data['ctHandle']);$newPage=$parent->add($ct,$page_data);$ptaID= Group::getByName("Page Type Administrators")->getGroupID();$perm=array();// Overall Permissions $perm['cInheritPermissionsFrom']="OVERRIDE";// subpages inherit permissions from this page$perm['cOverrideTemplatePermissions']='1';// subpages inherit permissions from page type defaults in dashboard//$perm['cOverrideTemplatePermissions'] = 0;// edit permissions$perm['collectionRead']=array();$perm['collectionRead'][]="gID:". GUEST_GROUP_ID;$perm['collectionRead'][]="gID:". REGISTERED_GROUP_ID;$perm['collectionRead'][]="gID:". ADMIN_GROUP_ID;$perm['collectionRead'][]="gID:".$ptaID;$perm['collectionRead'][]="uID:".$data['uID'];$perm['collectionReadVersions']=array();$perm['collectionReadVersions'][]="gID:". ADMIN_GROUP_ID;$perm['collectionReadVersions'][]="gID:".$ptaID;$perm['collectionReadVersions'][]="uID:".$data['uID'];$perm['collectionWrite']=array();$perm['collectionWrite'][]="gID:". ADMIN_GROUP_ID;$perm['collectionWrite'][]="gID:".$ptaID;$perm['collectionWrite'][]="uID:".$data['uID'];$perm['collectionApprove']=array();$perm['collectionApprove'][]="gID:". ADMIN_GROUP_ID;$perm['collectionApprove'][]="gID:".$ptaID;$perm['collectionApprove'][]="uID:".$data['uID'];$perm['collectionDelete']=array();$perm['collectionDelete'][]="gID:". ADMIN_GROUP_ID;$perm['collectionDelete'][]="gID:".$ptaID;$perm['collectionAdmin']=array();$perm['collectionAdmin'][]="gID:". ADMIN_GROUP_ID;$perm['collectionAdmin'][]="gID:".$ptaID;$perm['collectionAdmin'][]="uID:".$data['uID'];// sub page permissions$ccalendarCTID= CollectionType::getByHandle('community_calendar')->getCollectionTypeID();$cgalleryCTID= CollectionType::getByHandle('community_gallery')->getCollectionTypeID();$cinfoCTID= CollectionType::getByHandle('community_info')->getCollectionTypeID();$clocationCTID= CollectionType::getByHandle('community_location')->getCollectionTypeID();$eventCTID= CollectionType::getByHandle('event_page')->getCollectionTypeID();$perm['collectionAddSubCollection']=array();$perm['collectionAddSubCollection'][$ccalendarCTID]=array();$perm['collectionAddSubCollection'][$ccalendarCTID][]="gID:". ADMIN_GROUP_ID;$perm['collectionAddSubCollection'][$ccalendarCTID][]="gID:".$ptaID;$perm['collectionAddSubCollection'][$ccalendarCTID][]="uID:".$data['uID'];$perm['collectionAddSubCollection'][$cgalleryCTID]=array();$perm['collectionAddSubCollection'][$cgalleryCTID][]="gID:". ADMIN_GROUP_ID;$perm['collectionAddSubCollection'][$cgalleryCTID][]="gID:".$ptaID;$perm['collectionAddSubCollection'][$cgalleryCTID][]="uID:".$data['uID'];$perm['collectionAddSubCollection'][$cinfoCTID]=array();$perm['collectionAddSubCollection'][$cinfoCTID][]="gID:". ADMIN_GROUP_ID;$perm['collectionAddSubCollection'][$cinfoCTID][]="gID:".$ptaID;$perm['collectionAddSubCollection'][$cinfoCTID][]="uID:".$data['uID'];$perm['collectionAddSubCollection'][$clocationCTID]=array();$perm['collectionAddSubCollection'][$clocationCTID][]="gID:". ADMIN_GROUP_ID;$perm['collectionAddSubCollection'][$clocationCTID][]="gID:".$ptaID;$perm['collectionAddSubCollection'][$clocationCTID][]="uID:".$data['uID'];$perm['collectionAddSubCollection'][$eventCTID]=array();$perm['collectionAddSubCollection'][$eventCTID][]="gID:". ADMIN_GROUP_ID;$perm['collectionAddSubCollection'][$eventCTID][]="gID:".$ptaID;$perm['collectionAddSubCollection'][$eventCTID][]="uID:".$data['uID'];$newPage->updatePermissions($perm);
I know this is kind of deprecated with the new 5.6 release, but not everyone is using that yet. I'm sure that others will need this kind of functionality as they work on legacy sites.
Code
Post Reply
Delete Post
You are allowed to delete your post for 5 minutes after it's posted.