How to programatically assign sub-page permissions?

Permalink 1 user found helpful
I'm trying to explicitly set the permissions on a page at creation so that only the user can edit it, nobody else can. This works, but the pages are inheriting the sub-page permissions from the top page, meaning that users can add pages more than one level deep, which I don't want. I want them to be able to add and edit the page, but not add sub pages under the new page.

Anyway, this is my on_page_add:

public function on_page_add($c) {
      // don't allow any body and everybody to see it until someone publishes
      $pxml->guests['canRead'] = false;
      $pxml->registered['canRead'] = false;
      // admins get everything
      $pxml->group[0]['gID'] = ADMIN_GROUP_ID;
      $pxml->group[0]['canRead'] = true;
      $pxml->group[0]['canWrite'] = true;
      $pxml->group[0]['canReadVersions'] = true;
      $pxml->group[0]['canApproveVersions'] = true;
      $pxml->group[0]['canDelete'] = true;
      $pxml->group[0]['canAdmin'] = true;
      // moderators also get everything
      $g = Group::getByName('Moderators');
      $pxml->group[1]['gID'] = $g->getGroupID();


As near as I can tell the array for assignPermissionSet can't include any information about sub-collection permissions, so I assume this must be set somewhere else. I need to know how to update the sub-page permissions to not allow any sub-pages inside of this function.

Any help would be appreciated.

hereNT
 
hereNT replied on at Permalink Best Answer Reply
hereNT
Actually I just set the permissions for sub pages to inherit from page type defaults instead of the page I was adding the pages under and the permissions appear to be the way I want them to be. I think I'm actually good on this.
hereNT replied on at Permalink Reply
hereNT
Though if anyone knows what the code to do what I originally wanted to do is, I'd appreciate knowing it, I could see this being useful in the future...
Zelgadis replied on at Permalink Reply
Hi!

I haven't found a function to do that, so I did that by inserting appropriate values into DB:

// SET PERMISSIONS
$db = Loader::db();
$v = array('OVERRIDE', $cID, $cID);
$q = "update Pages set cInheritPermissionsFrom = ?, cInheritPermissionsFromCID = ? where cID = ?";
$r = $db->query($q, $v);
// Notice, that the lines above will completely erase all 
// permissions for created page, so we need to specify them manually
// Page permissions
//  readonly for mortals
$pxml->guests['canRead'] = true;
$pxml->registered['canRead'] = true;
//  admins get everything
$pxml->group[0]['gID'] = ADMIN_GROUP_ID;
$pxml->group[0]['canRead'] = true;
$pxml->group[0]['canWrite'] = true;