pogidude Posted May 22, 2013 Share Posted May 22, 2013 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. Download http://modules.processwire.com/modules/page-edit-per-role/ 3 Link to comment Share on other sites More sharing options...
Soma Posted May 22, 2013 Share Posted May 22, 2013 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. Link to comment Share on other sites More sharing options...
pogidude Posted May 22, 2013 Author Share Posted May 22, 2013 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 More sharing options...
Soma Posted May 22, 2013 Share Posted May 22, 2013 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 More sharing options...
pogidude Posted May 22, 2013 Author Share Posted May 22, 2013 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 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 More sharing options...
kongondo Posted May 22, 2013 Share Posted May 22, 2013 You mean this http://processwire.com/api/hooks/captain-hook/ and probably this http://processwire.com/api/hooks/ too? Link to comment Share on other sites More sharing options...
arjen Posted May 22, 2013 Share Posted May 22, 2013 (edited) Ryan just posted this page about hooks on the main website. Edit: nevermind seems kongondo is a lot quicker than I am Edited May 22, 2013 by arjen Link to comment Share on other sites More sharing options...
pogidude Posted May 22, 2013 Author Share Posted May 22, 2013 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 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 More sharing options...
kongondo Posted May 22, 2013 Share Posted May 22, 2013 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 More sharing options...
Soma Posted May 22, 2013 Share Posted May 22, 2013 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 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 More sharing options...
apeisa Posted May 22, 2013 Share Posted May 22, 2013 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. Link to comment Share on other sites More sharing options...
pogidude Posted May 22, 2013 Author Share Posted May 22, 2013 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! 1 Link to comment Share on other sites More sharing options...
ryan Posted May 25, 2013 Share Posted May 25, 2013 Pogidude, you are correct in all of that. Link to comment Share on other sites More sharing options...
Soma Posted June 3, 2013 Share Posted June 3, 2013 I think this module has a little bit too much categories http://modules.processwire.com/modules/page-edit-per-role/ Link to comment Share on other sites More sharing options...
pogidude Posted June 3, 2013 Author Share Posted June 3, 2013 I think this module has a little bit too much categories http://modules.processwire.com/modules/page-edit-per-role/ 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 Link to comment Share on other sites More sharing options...
Soma Posted June 4, 2013 Share Posted June 4, 2013 Page edit per user module has 3 categories that make sense. Yours had 10+ and some nothing to do with this module. Link to comment Share on other sites More sharing options...
pogidude Posted June 4, 2013 Author Share Posted June 4, 2013 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*? Link to comment Share on other sites More sharing options...
ryan Posted June 6, 2013 Share Posted June 6, 2013 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 More sharing options...
Soma Posted June 6, 2013 Share Posted June 6, 2013 I'm guessing some autofill plugin. Link to comment Share on other sites More sharing options...
pogidude Posted June 6, 2013 Author Share Posted June 6, 2013 Hey @ryan, see http://processwire.com/talk/topic/3763-editing-module-info-checks-everything/?p=36825 it was lastpass. Link to comment Share on other sites More sharing options...
pogidude Posted June 19, 2013 Author Share Posted June 19, 2013 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: Select pages that role can edit. (I'll just say "role" instead of "users with role" but hope you understand) 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. 1 Link to comment Share on other sites More sharing options...
ryan Posted June 20, 2013 Share Posted June 20, 2013 ProcessPageAdd::getAllowedTemplates() now hookable on the dev branch. 1 Link to comment Share on other sites More sharing options...
pogidude Posted June 20, 2013 Author Share Posted June 20, 2013 ProcessPageAdd::getAllowedTemplates() now hookable on the dev branch. Thanks! Link to comment Share on other sites More sharing options...
kixe Posted August 26, 2015 Share Posted August 26, 2015 The module doesn't work with latest PW Version. Please update or remove from directory. 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