Forum

Thread tagged as: Problem, Configuration, Runway

Include Page Creator in Allowed Roles for Perch Content Create

Hello,

I have a client's website built on Runway and I'm using perch_content_create. I want to give users the ability to add subpages to their own pre-assigned pages. The master pages they can select from have the following:

perch_content_create ('Staff Listing', array(
        'template'   => 'staff_select.html',
        'multiple'    => false,
        'edit-mode' => 'singlepage',
        'roles'        => 'Admin, Operations',
    ));

I have a question and an issue though.

  1. Since the default Admin role has access to all content, do I need to add Admin to the list of roles?

  2. When a user creates a subpage, everything functions great, except the page creator doesn't have access to the page's regions. Is this due to the user not being listed by default for roles in the perch_content_create function? If so, is it possible to configure perch_content_create so that a subpage inherits the same permissions defined by the parent page?

There will be multiple users, each with permissions to edit/manage their pre-assigned page and any subpages they create. For example, John Smith would have permissions to edit his pre-assigned page johnsmith.php and any subpages he creates under his page like, /johnsmith/english-101 and/or /johnsmith/literature-102. The admin would create and configure his page, but John Smith would create/manage the subpages he creates.

I figured it would make sense that even if the page creator isn't listed as an allowed role in perch_content_create, they would, by default, have permission to edit a page they created, right?

Thank you

Joshua Rodriguez

Joshua Rodriguez 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Since the default Admin role has access to all content, do I need to add Admin to the list of roles?

That's right - the Admin role has permissions to everything, so you can skip it. It's automatic.

But that's not how the roles option works. You need to pass it role IDs, not titles. If you click through to the edit page for a Role in the control panel, the ID is in the URL.

I thought that by default the permissions from the parent page were inherited, so it may be that you're overriding that behaviour by setting them explicitly.

Drew,

Very helpful explanation. I found the role ID's and updated my code. Works great.

Now, I logged in as my test user and created a subpage with the following on my selected master page:

perch_content_create('Staff Listing', array(
        'template'  => 'staff_select.html',
        'multiple'  => false,
        'edit-mode' => 'singlepage',
        'roles'     => '3',
    ));

The result was that my test user had no access to the subpage region. Only role ID 3 (Operations) has editing permission to the subpage region, even though role ID 4 (Test User) was the subpage creator.

I commented out the roles line of code and the Test User did inherit permissions to edit the region. I also learned that the role option to Edit page details was also required in this scenario, not the Configure page settings option, which is what I had enabled.

Would it be possible to modify the perch_content_create function to include the page creator by default...so that like the default Admin role, the page creator is also automatic?

Maybe I'm missing something, but I can't think of a scenario where a page creator would/should not have automatic permission to a page or subpage they created, even when roles are being defined in the function.

In my case, I have single users who are similar to my Test User with only access to create subpages under their own predefined page created by an Admin. Then I have grouped users like Operations or Administrative Team, that would need access to edit all regions, including the pages created by any single user.

For now, I'll just keep watch for new pages users create, and then modify their permissions manually to include the grouped users.

Oh something else I just though of too, maybe in Role Actions when using the Grant role permission option, would it be possible to make sure the role continues to have permission to all existing regions/creating subpages, but also to all future regions/creating subpages permissions.

Maybe this route would make more sense, since if a role is granted permission or revoked permission on a global level, then it should be applied to all current and future pages and regions. Of course, unless manually specified otherwise directly from a region as is the case now.

Something like this could work, but is it possible?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The idea of Role Actions is that it performs a batch of changes at once without the need to click through lots of control panel pages individually. It doesn't have any affect on future changes - it just sets the current state.

Ok, makes sense and has been very helpful.

Is there a way to get the role ID of a user when they're logged in to the CMS?

What I'm thinking is that when they're logged in, if/when they create a subpage, maybe I can pass the value of their role ID into the perch_content_create function.

By the way, role ID's, are they like _id in that they are always unique and do not change...or are they more like perch_item_index?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Role IDs don't change unless you do something like delete and recreate the role.

perch_item_index is an index - i.e. a position in a list, not an identifier.

I'll check the defaults, as it makes sense that if someone creates a page they should be able to edit the regions.

Hi Drew,

Thanks for explaining the difference between the two.

I'm sure you have plenty going on, but I just wanted to check in to see if you possibly had a chance to take a look at the defaults...??

Any good news of a possible change coming, or maybe even a work around I could use for the time being?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If we do make a change it won't be until Perch 2.9.

Drew,

Just wanted to follow up on this issue I'm still experiencing. I'm not sure how soon Perch 2.9 is to being released and if this issue will be resolved at that time, but I do need some type of work-around that I can use.

Is there a way for me to retrieve the role ID of a user when they are logged in to the CMS? This way I can pass that value into my perch_content_create function of the master pages allowed to be used for this user to create subpages under their pre-assigned main page.

OR

Is there a way to retrieve the role permissions assigned to the parent page maybe as an array, and pass this into the subpages created under that parent page?

Please help.

Thank you!!

Drew McLellan

Drew McLellan 2638 points
Perch Support

As a workaround, you can do this in your page:

$Users       = new PerchUsers;
$CurrentUser = $Users->get_current_user();

perch_content_create('Staff Listing', array(
        'template'  => 'staff_select.html',
        'multiple'  => false,
        'edit-mode' => 'singlepage',
        'roles'     => $CurrentUser->roleID(),
    ));

Drew,

Works great. You're a life saver!

Thank you!