biotech Posted April 25, 2012 Share Posted April 25, 2012 Hi there, Pretty new to PW so excuse the ignorance. Just exploring the possibilities with the Roles and Permissions but can't quite see how custom made Roles relate actions performed inside the CP. Anyone have examples or 'Permission 101' link they can share? My goal is to create a workflow where 'user' can only create a page and then 'editor' can 'publish' the page: - either by native "Settings ->Status" or - be able to change a custom field value = that is set to default to 'user' as 'unpublished' while 'editor' would be able to toggle it. Lastly, how would my 'editor' filter for those entries/pages awaiting to be 'published'? Note: I am getting a feeling that even CP is nothing more than collection of templates (like the front end) I just can't seem to find them. Thank you. Link to comment Share on other sites More sharing options...
alan Posted April 26, 2012 Share Posted April 26, 2012 @biotech I'm not a super-experienced person myself either, but I've learnt how to do one thing with permissions, in case that helps. I found out how to allow a non-superuser to use a module. Also this post may be of help. Beyond that, others who are cleverer here then me will be able to help much more I am sure. Oh and the Admin system is built with PW, note when viewing Admin > Setup > Templates (and for Files too) there is a faded collapsed section at the top you can click to reveal System Templates (and Fields). Good luck, I've found PW amazingly powerful, it's just a case of working out how to drive it, but so worth it as you get up to speed. Link to comment Share on other sites More sharing options...
apeisa Posted April 26, 2012 Share Posted April 26, 2012 Permission system is tied to templates. So you need to edit template and there you can click which roles do have page-edit permission. If you have simple site, then it is most probably home template that you are looking for. For having permission to publish pages: in default installation it is tied to page-create permission. But if you create page-publish permission, then that is used instead (which allows your scenario to have some people add new pages but not possibility to publish them). Link to comment Share on other sites More sharing options...
biotech Posted April 26, 2012 Author Share Posted April 26, 2012 @alan Thanks, I did see that thread by nieldiamond but it did not really explain in what template to place the snip. Just starting to wrap my head around PW and having ability to tweak the CP is great but adds a layer of complexity. But, every CMS is different and getting the concepts and lingo down is 1/2 of the battle The "Admin > Setup > Templates" part is where I looked before but they are just placeholders...still can't find where to actual php files are located or where to use "permission" => "page-edit" @apeisa Yes I am just working with the default install...and still can't find much. I looked at "wire/templates-admin" and "site/templates" and not a whole lot there related to admin section. I did find the 'home.php' in 'site/templates' folder but all it does is call for header and footer includes. Thank you. Link to comment Share on other sites More sharing options...
apeisa Posted April 26, 2012 Share Posted April 26, 2012 biotech: that tiny code snippet is used only when building process modules, which are kind of custom admin modules. For basic permission management workflow is this: a) Create role b) Add permissions to role c) Add role for a user d) Edit template -> access tab -> and "activate" page view / edit / create / add permissions for each roles there. Link to comment Share on other sites More sharing options...
biotech Posted April 26, 2012 Author Share Posted April 26, 2012 biotech: that tiny code snippet is used only when building process modules, which are kind of custom admin modules. For basic permission management workflow is this: a) Create role B) Add permissions to role c) Add role for a user d) Edit template -> access tab -> and "activate" page view / edit / create / add permissions for each roles there. Good to know...for now, I don't need to know about modules About the permissions management...I got that part before posting. But my newly created Permission of eg. "Change Page Status Permission" is completely irrelevant and I could not find any docs to where it IS used. Thank you. Link to comment Share on other sites More sharing options...
apeisa Posted April 26, 2012 Share Posted April 26, 2012 You can use it in your template code and in your modules like this: $permission = $permissions->get("change_status"); if ($user->hasPermission($permission)) { echo "You have a permission for something"; } else { echo "You don't"; } I guess there is only one additional permission that you can add and it has a meaning, and that is "page-publish" I mentioned earlier. If that permission is created, then that is also required to publish pages. Link to comment Share on other sites More sharing options...
biotech Posted April 26, 2012 Author Share Posted April 26, 2012 I am sorry I am still having hard time following...where are these templates (physical php files) in Admin that control the entry and workflow? Eg. I looked at Settings of the page shown on the screencap "/processwire/page/add/" and nothing there...there is no actual file or folder. I am guessing that the if condition above would be wrapped around the 'Status' field? Link to comment Share on other sites More sharing options...
apeisa Posted April 26, 2012 Share Posted April 26, 2012 Those all use admin-template, and they all have processModule behind them. If you are looking for code, then they can be found /wire/modules/process/ (https://github.com/ryancramerdesign/ProcessWire/tree/master/wire/modules/Process). But modifying those files is not the way to go here (you should never edit files under /wire/). If you want to have this done: My goal is to create a workflow where 'user' can only create a page and then 'editor' can 'publish' the page Then you need to do this: Create two roles, user and editor Create new permission, give it name "page-publish" (name should be exactly that) Edit those two roles, but add page-publish permission only for editor, but page-edit for both of them. Other permissions as you see fit. Then edit home-template, access tab and allow edit / create / children for both editor and user roles. Now your user-role users should be able to create and edit pages, but not publish them. Editors should be able publish unpublished pages. Just for reference, there is the commit when this was added: https://github.com/ryancramerdesign/ProcessWire/commit/330d04d7054f27ce4cd8ed86952f270875488c55 (also be sure to run no more than 2 months old version of pw). 1 Link to comment Share on other sites More sharing options...
apeisa Posted April 26, 2012 Share Posted April 26, 2012 And for the record: I haven't used the page-publish permission myself, but that is my strong assumption on how it works. Please do report if it doesn't Link to comment Share on other sites More sharing options...
biotech Posted April 26, 2012 Author Share Posted April 26, 2012 Thank you Leave it to me to start with the most complex tasks...jeez do I have a gift. I just realized that this permission is NOT an arbitrary name you came up of 'page-publish' but rather something from the core in 'wire/modules/PagePermissions.module'. A follow up question and somewhat related is how would I filter my pages/entries that have not been published aka 'awaiting approval'? (other than expanding the whole tree and seeing them with Strike Through decor.) I have tried the concept and it doesn't quite work as the status field is not available - I may need to update my version. UPDATE: with the new version it is working correctly. Link to comment Share on other sites More sharing options...
Soma Posted April 26, 2012 Share Posted April 26, 2012 I think you're looking for something that isn't really there the way you maybe think. To my mind comes, that you could simply create a custom admin page and just output a markup table that list's all unpublished pages. There must be some thread about it with more examples how to create custom cp admin pages. Example: Create a new page under the Admin tree. Select the "admin" template and give it a title. After saving and publishing it will appear in the top navigation. If you go to the newly created admin page it will output "This page has no Process assigned." You then need to create a new Process Module. That Process Module would basicly look like this: (this is a quickly stripped example from a module I did a while ago) <?php /* * ProcessWire Module * Simple Example admin page Process module to output unpublished pages * * Put this module into you /site/modules folder * Create new admin page using "admin" template and assign this Process module * */ class ProcessUnpublishedList extends Process { protected $sel_unpublished = 'sort=-modified, status=unpublished'; public static function getModuleInfo() { return array( 'title' => 'Process Unpublished List', 'summary' => 'Show unpublished pages in the admin', 'version' => 100, 'permission' => 'page-edit' // or any other permission to manage access to this admin page ); } public function ___execute() { $out = ''; $fieldset = $this->modules->get("InputfieldFieldset"); $field = $this->modules->get("InputfieldMarkup"); $field->label = "Unpublished Pages"; $field->collapsed = Inputfield::collapsedNo; $table = $this->modules->get('MarkupAdminDataTable'); $table->setSortable(false); $table->setEncodeEntities(false); $header = array('Title','Status','modified','by user'); $table->headerRow($header); $rows = array(); $pageArr = $this->pages->find($this->sel_unpublished); foreach($pageArr as $p){ $status = ''; $status = $p->is(Page::statusUnpublished) ? "unpublished" : ''; $editUrl = "{$this->config->urls->admin}page/edit/?id={$p->id}"; $rows[] = $p->editable() ? "<a href='{$editUrl}' style='opacity:0.7'><s>".$p->get('title|name|id').'</s></a>' : $p->get('title|name|id'); $rows[] = $status; $rows[] = date('Y.m.d H:i:s',$p->modified); $rows[] = $p->modifiedUser->name; $table->row($rows); $rows = null; } $field->value = $table->render(); $fieldset->add($field); $out .= $fieldset->render(); return $out; } /** * example * accessing /processwire/adminpage_with_this_module/list2/ * will map to this function */ public function ___executeList2(){ $out = "List2"; return $out; } } Edit: This example shows that you can use certain processwire modules to create fieldsets or a MarkupAdminDataTable to generate markup. This is how PW itself does build all the admin pages pretty much. But you can also just create your own simple html markup and output that. 2 Link to comment Share on other sites More sharing options...
biotech Posted April 26, 2012 Author Share Posted April 26, 2012 Very nice, thanks Soma, I am sure I will have to refer to this but at least I know it is possible without hacking up the core. Link to comment Share on other sites More sharing options...
gebeer Posted July 30, 2014 Share Posted July 30, 2014 @Soma, thanks a lot for the module code. Very useful! I have created the module in site/modules/ProcessUnpublishedList.module I also created a new page under the admin tree. How do I assign the module to the Process for that page? It does not appear in the select field where all processes are listed and can be assigned. Cheers Gerhard Link to comment Share on other sites More sharing options...
gebeer Posted July 30, 2014 Share Posted July 30, 2014 To answer my own question: I had to install the module first (stupid me had forgotten that). After that I could select it as a Process. Simple as that 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