caribou Posted March 13, 2013 Share Posted March 13, 2013 Hey all, I would like to give a user role permission to create pages, but only with certain templates in certain branches. Using Page Edit per User, let's say I give a role permission to edit pages in /foo/. If I don't give them permission to create pages under Template > access, they can edit, but not create pages in /foo/. If I do give them create pages under Template > access, they can create pages in /foo/, but also in /bar/ and all the other branches that use that template. So what I'd like to do is extend the branch limitation of the module to creation, not just editing. Is the best way to accomplish that by editing the Page Edit module? Thanks! Link to comment Share on other sites More sharing options...
ryan Posted March 14, 2013 Share Posted March 14, 2013 Since you are using the PageEditPerUser module, I'm thinking you'd want to edit that one rather than Page Edit. Another alternative is that you could just setup alternate templates, since access is managed there by default. But if you go the PageEditPerUser route, you'd want to modify it to hook into "Page::addable" in addition to the existing Page::editable. The "Page::addable" hook works in basically the same way as the editable one. If you want to see the default logic built into it, the Page::addable function can be found in: /wire/modules/PagePermissions.module Link to comment Share on other sites More sharing options...
Philipp Posted March 19, 2013 Share Posted March 19, 2013 Same question here. I've got a site were special users should only edit a selected site (with all children in it). I want them to be able to create new pages aswell in their branch. I followed your steps and modified the Module. So far it works. But when I want to create a new page, I can't select the template for the new page. http://d.pr/i/e5QA The user/role has the right to modify the template. I cannot use a per-template approach because multiple pages with the same template (like "basic-page") should be editable by different users. Link to comment Share on other sites More sharing options...
ryan Posted March 20, 2013 Share Posted March 20, 2013 I followed your steps and modified the Module. So far it works. But when I want to create a new page, I can't select the template for the new page. Does the user have a role that has "create" permission for the template needed there? Also check the template's family settings for both the parent page and child page you intend to create. If that still doesn't seem to be the problem, let me know and I can make the ProcessPageAdd::getAllowedTemplates(); function hookable. Link to comment Share on other sites More sharing options...
Philipp Posted March 20, 2013 Share Posted March 20, 2013 When I'm enabling the permissions on the template, they can add pages on all pages (or all pages with that special template). As described before, I want to enable the permissions for a selected branch of pages - independent of the template of the site because the template may be used multiple times. Link to comment Share on other sites More sharing options...
ryan Posted March 21, 2013 Share Posted March 21, 2013 When I'm enabling the permissions on the template, they can add pages on all pages (or all pages with that special template). As described before, I want to enable the permissions for a selected branch of pages - independent of the template of the site because the template may be used multiple times. In this case, you'd probably have the reverse the logic of the addable() hook. You'd give them the template access. But your addable() and editable() hooks would take it away. That's one approach you could take anyway... But if the blank templates list was the only issue before, you might just want to edit that /wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module file and prepend the getAllowedTemplates() function with 3 underscores, renaming it to: ___getAllowedTemplates(). Then it becomes hookable, and you can modify the value that it returns from your module. Currently in your case, it's returning nothing (since they have no edit access on the template). So you'd want to make your hook modify the return value to include the templates you want them to be able to select from. If you find this worthwhile, let me know and I will update the core to have that function hookable. 1 Link to comment Share on other sites More sharing options...
Philipp Posted April 1, 2013 Share Posted April 1, 2013 Sorry for the long delay between my last answer. I've changed the /wire module and made the getAllowedTemplates() hookable. However I'm not able to use this hook in the PageEditPerUser.module. I think I'm missing the right name for the hook. Thanks in advance for your help. Link to comment Share on other sites More sharing options...
ryan Posted April 1, 2013 Share Posted April 1, 2013 You probably want to hook the method via something like this in an init() function with an autoload module: $this->addHook('ProcessPageAdd::getAllowedTemplates', $this, 'myHookFunction'); Link to comment Share on other sites More sharing options...
Marvin Scharle Posted April 22, 2013 Share Posted April 22, 2013 Hi ryan I'm working together with Philipp. I tried to hook your code into the init() method of wire/modules/PagePermissions.module. It results into a fatal error: Notice: Trying to get property of non-object in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/PagePermissions.module on line 251 Notice: Trying to get property of non-object in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/PagePermissions.module on line 251 Warning: Invalid argument supplied for foreach() in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module on line 207 Notice: Trying to get property of non-object in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/PagePermissions.module on line 251 Warning: reset() expects parameter 1 to be array, boolean given in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module on line 230 Catchable fatal error: Argument 1 passed to ProcessPageAdd::getTemplateLabel() must be an instance of Template, null given, called in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module on line 231 and defined in /home/httpd/vhosts/conclurer.com/subdomains/werkgymnasium/wire/modules/Process/ProcessPageAdd/ProcessPageAdd.module on line 241 I hope you are able to find out whats wrong here. Thanks in advance for your help. Link to comment Share on other sites More sharing options...
ryan Posted April 24, 2013 Share Posted April 24, 2013 When I post code in here, I'm usually writing it in the browser. That means it's a starting point that may need testing and debugging, rather than a full working solution. Those error messages should help to get to the bottom of it, but I think we need to see the code that is actually in use. Can you post or paste the file here? Link to comment Share on other sites More sharing options...
Soma Posted April 24, 2013 Share Posted April 24, 2013 It's simple... "getAllowedTemplates" isn't hookable (just read that philipp made it hookable... sorry) I tried to hook your code into the init() method of wire/modules/PagePermissions.module. That sentence doesn't make much sense to me... (as some of my own sometimes ) Link to comment Share on other sites More sharing options...
Marvin Scharle Posted July 8, 2013 Share Posted July 8, 2013 It looks like I figured out, how to deal with it. I just commented out the lines in ProcessPageAdd.module that prove the user's right to access a specific template /* if($t->useRoles && !$user->hasPermission('page-create', $t)) continue; if(!$t->useRoles && !$parentEditable) continue; if(!$t->useRoles && !$user->hasPermission('page-create', $this->parent)) continue; */ Yeah, It's dirty, but it works ;-) 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