Tricky area permissions question
Permalink
I have kind of a funky situation - I am setting up an external form block that adds a page based on a text field. Once the page is created, I'm setting the permissions on that page to OVERRIDE:
This works great for locking down the new page to be only editable/viewable by the logged in user. The problem is that then all of my area permissions on the page are set to full access, instead of the page defaults in the dashboard.
The biggest thing is the blocks that are allowed on each area, I'm less concerned about other permissions. It's kind of a gallery page, so I want people to be able to add image, flickr or gallery blocks to one area, and nothing else.
Anyone have some good code snippets on setting permissions like this? I'm thinking I might have to hook into the on_page_view event for the page type and see if it's the first time the page is being viewed, and set the permissions manually then, but I'm not 100% sure.
It would be nice if there were some set functions in the permissions model :(
$_c = Page::getByID($args['parent_cID'], "RECENT"); $data = array(); $data['name'] = $txt->sanitize($args['bicycle_porn_title']); $data['cHandle'] = $txt->sanitizeFileSystem($args['bicycle_porn_title']); $u = new User(); $uID = $u->getUserID(); $data['uID'] = $uID; $np = $_c->add($apct, $data); $_cID = $np->getCollectionID(); $db = Loader::db(); $q = $q = "UPDATE Pages SET cInheritPermissionsFromCID = {$_cID}, cInheritPermissionsFrom = 'OVERRIDE' where cID = {$_cID}"; $db->query($q); $q = "INSERT into PagePermissions (cID, gID, uID, cgPermissions) values (?,?,?,?)"; $v = array($_cID, 0, $uID, "r:wa:db:av"); $db->query($q, $v);
This works great for locking down the new page to be only editable/viewable by the logged in user. The problem is that then all of my area permissions on the page are set to full access, instead of the page defaults in the dashboard.
The biggest thing is the blocks that are allowed on each area, I'm less concerned about other permissions. It's kind of a gallery page, so I want people to be able to add image, flickr or gallery blocks to one area, and nothing else.
Anyone have some good code snippets on setting permissions like this? I'm thinking I might have to hook into the on_page_view event for the page type and see if it's the first time the page is being viewed, and set the permissions manually then, but I'm not 100% sure.
It would be nice if there were some set functions in the permissions model :(
Maybe Page::assignPermissionSet() will do what you want. Run it on the new page created. Something like
$px = new stdClass; $px->user[0]['uID'] = $u->getUserID(); $px->user[0]['canRead'] = true; $px->user[0]['canWrite'] = true; $px->user[0]['canDelete'] = true; $px->user[0]['canAdmin'] = true; $np->assignPermissionSet($px);
Nice.
Thanks Andrew.
Thanks Andrew.
Hrm, not quite, sorry for the late reply on this. I'm still getting the issue where the areas now allow all the different block types instead of just the ones allowed to the group, mostly I think because the group now has no page level permissions, so area permissions are ignored?
Not a huge deal, but kind of a pain for me, I'd like to only allow page list and content blocks, only in a few areas, and it doesn't seem possible with the API?
Not a huge deal, but kind of a pain for me, I'd like to only allow page list and content blocks, only in a few areas, and it doesn't seem possible with the API?
http://pastie.org/1028693
That's my external form form controller, it's just processing a single text input field and then doing all the area copying stuff.