Jump to content

Page Edit Per Role


pogidude
 Share

Recommended Posts

Just thought I'd share this module which I modified from the PageEditPerUser module by Ryan Cramer. I needed page-specific edit access by roles, not by user. So...

Overview

Assign edit access to roles on a per-page basis.

Description

The user must already have page-edit permission on one of their roles in order to get 

edit access to assigned pages. Otherwise, they will only gain view access.

This module is fully functional as-is, but intended as a proof-of-concept for those 

wanting to go further with adding custom edit and/or view access.

How to install

1. Copy the PageEditPerRole.module file to /site/modules/

2. Go to Modules in the ProcessWire admin and click "Check for new modules"

3. Click "install" for "Page Edit Per Role"

How to use

1. Create a new role called "editor" (or whatever you want to call it) and give the role "page-edit" permission. If you already have a role in place that you want to use, that is fine too.

2. Under "Access > Roles" locate the role you want to assign edit access to. Edit this role. 

3. For this roles's "Editable Pages" field: select one or more pages you want users with this role to be able to edit.

4. Save the role.

5. Under "Access > Users" locate the user you want to apply the role to. Edit this user.

6. For this user's "Roles" field, select the new role you added - "editor".

7. Save the user and your are done.

8. To test, login as the user you edited to confirm it works how you expect.

  • Like 3
Link to comment
Share on other sites

Thanks for sharing pogidude. Are you ware of this module? http://processwire.com/talk/topic/371-page-specific-permissions/?p=2787. This might would have been a good starting point for this module.

actually, I found this: http://modules.processwire.com/modules/custom-page-roles/ .... which only hooked to viewable.. no editable and other code that is in the thread you linked to.. by the way the code by @apeisa in the thread would have worked for me..

On the upside, I guess we have another way of doing something :)

Link to comment
Share on other sites

Yeah this is the module from that thread. Yes it's for page-view, but I just thought it could be extended for page-edit too... as mentioned in the thread that it's a start. 

Yeah another way of doing, but it would be nice to have one that does it all, instead of many that only do partial.

Link to comment
Share on other sites

hmmmm.. now that I've seen the thread, seems like I need an "addable" hook, and other permissions, and tests on my setup show that I do need it :D

I'll most likely update this module as I do like the idea of keeping all pages that a role has access to in one place..

aside from poring reading through the source code, is there any place where the hooks I need are documented? 

Link to comment
Share on other sites

uh, yeah, my next question was going to be about captain hook. In this thread http://processwire.com/talk/topic/371-page-specific-permissions/page-3 there is this code:

$this->addHookAfter("Page::viewable", $this, 'viewable');

and others like it. I would assume it would be listed under Page class..

Edit: Nevermind, grepped for it in the files.. I guess I'll just have to read the core :D lazy me.. sorry, I come from wp where I almost never have to go through core since most of info about functions I need is already in codex.

Link to comment
Share on other sites

Most of the time you want a hook to apply to all instances of a class. For instance, when you hook Page::viewable, you likely want your hook to be called regardless of what Page it is. Such hooks are defined by specifying the class and method (i.e. "Class::method") in the addHook() call. For example:

:)

Link to comment
Share on other sites

uh, yeah, my next question was going to be about captain hook. In this thread http://processwire.com/talk/topic/371-page-specific-permissions/page-3 there is this code:

$this->addHookAfter("Page::viewable", $this, 'viewable');

and others like it. I would assume it would be listed under Page class..

Edit: Nevermind, grepped for it in the files.. I guess I'll just have to read the core :D lazy me.. sorry, I come from wp where I almost never have to go through core since most of info about functions I need is already in codex.

Those permission hooks are in PagePermissions.module, and they're defined using hooks, so there's no methods ___viewable.

Link to comment
Share on other sites

Those permission hooks are in PagePermissions.module, and they're defined using hooks, so there's no methods ___viewable.

Hmmm.. you're right. so, to clarify, the methods Page::editable, Page::viewable, etc.. were all added in the PagePermissions module by calling:

$this->addHook('Page::editable', $this, 'editable');

correct?

which means, in my module, I could essentially *add* my own method hook to the Page class like this?

$this->addHook('Page::pogidudemethod', $this, 'pogidudeSomeMethod');

to which other modules can also hook into and which could also be used like:

$var = $page->pogidudemethod();

very coool... :)

This is the latest incarnation of CustomPageRoles (view & edit access per page): https://github.com/apeisa/CustomPageRoles/blob/master/CustomPageRoles.module

Not totally happy with it yet, so that is the reason it's not in modules dir.

yeah, sorry I was only skimming over the modules/threads since I wanted something I could implement quickly. But what you have going here is pretty neat too. thanks!

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I think this module has a little bit too much categories http://modules.processwire.com/modules/page-edit-per-role/ :D

yeah, probably a bit much like this module http://modules.processwire.com/modules/page-edit-per-user/ from which this module was modified from and which I'm pretty sure behaves much the same except that this module applies to roles and not to users ;)

So I guess you could pretty much say the same thing for the other module :D

Link to comment
Share on other sites

oh.. woops! that must have been when I updated the info for the modules. I'm pretty sure I set it to the same categories as the Page Edit Per User module. yeah now that I look at it, I see that compatibility has been set for 2.0, 2.1, 2.2 and 2.3. I've only set it for 2.3.



I just tried editing the module info and I saw that all categories are checked. same goes for compatibility. Is this something to discourage *editing*? :D

Link to comment
Share on other sites

I just tried editing the module info and I saw that all categories are checked. same goes for compatibility. Is this something to discourage *editing*?

I'm not seeing that here. What browser/version are you using? Just wondering if we have some browser issue that is causing them to all be checked when you try to edit?

Has anyone else run into this issue?

Link to comment
Share on other sites

  • 2 weeks later...

Just pushed out an update to the module on github https://github.com/ryannmicua/PageEditPerRole and thought I'd ask for feedback.

I did hack core though. The module needs ProcessPageAdd::getAllowedTemplates() to be hookable - required for #2 below.

Right now, you can do the following:

  1. Select pages that role can edit. (I'll just say "role" instead of "users with role" but hope you understand)
  2. Select pages that role can add child pages to. requires the parent page to be editable by role (set in #1) and in module config, requires permissions to be considered further up the branch - if you don't, you can't edit the child page after you add.

Next:

- Improve #2. I'm thinking of adding another field - "Parent page where role can edit child pages". This is for situations where you'd like to allow users to create pages under a parent but not allow them to edit the parent page. This way, you don't have to enable the permissions to be considered further up the branch in module config.

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

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

×
×
  • Create New...