Jump to content

[solved] Is there a 'page-add-created' permission or something similar?


Recommended Posts

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:

image.thumb.png.b182f320d651d42fa8a8e1277f4657e3.png

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 by poljpocket
solved
Link to comment
Share on other sites

  • poljpocket changed the title to Is there a 'page-add-created' permission or something similar?
Posted (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 by poljpocket
typo
  • Like 1
Link to comment
Share on other sites

  • poljpocket changed the title to [solved] Is there a 'page-add-created' permission or something similar?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...