poljpocket Posted June 12 Share Posted June 12 (edited) Hi all, I am adding a new capabilities system for artists to edit only their own profile. This boils down to them needing to be able to edit their profile page, manage their own event calendar and their own sounds. The page will thus have child pages with 'event' and 'sound' template. Using core and optional permissions available in 3.0.246, I can't get this exact scenario configured. I can get close by setting the user who created the profiles to be the artists' users and enabling 'page-edit-created' for the 'artist' role accordingly. This is what it looks like in the almost-working state: This configuration will allow the artist to also add new events and sounds to other artists' profiles. Which isn't quite what I need. It seems as I would need something like a 'page-add-created' permission which will only allow children to be added to pages the user has created - analogous to the 'page-edit-created' permission. Am I missing or misunderstanding something? Thanks a lot, Julian Edited June 13 by poljpocket solved Link to comment Share on other sites More sharing options...
poljpocket Posted June 13 Author Share Posted June 13 (edited) I have solved this with following hook (after manually creating the page-add-created permission). Note that this only applies to the artist template and the permission name is actually a bit misleading since it's not applied to all addable checks. In my case, the result will be the same since artists would never be the creator of anything other than their profile tree. <?php $wire->addHook('Page(template=artist)::addable', function ($event) { /** @var Page $page */ $page = $event->object; /** @var Wire $wire */ $wire = $event->wire; $user = $wire->user; // only continue checks if user has page-add since just like page-edit-created, we want to reduce the permission scope. // At this point, PagePermissions will have checked for addable already, so use its result to check if (!$event->return) return; if ($wire->permissions->has('page-add-created') && $user->hasPermission('page-add-created', $page)) { $event->return = $page->created_users_id == $user->id; } }, [ 'priority' => 999, ]); Edited June 13 by poljpocket typo 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now