Jump to content

Allow user to edit a page but not delete it


Joe
 Share

Recommended Posts

Hi all! A quick question, if it has been treated somewhere else I´m thankful for the link...

Is it possible to permit users to edit certain pages but keep them from deleting them?

I´ve looked at the "Page Edit Per User" module, but that doesn´t seem to make this possible.

This should only apply to specific pages, not all of them.

Thanks!

Link to comment
Share on other sites

If you don't want a user deleting pages, then it should be as simple as not giving them page-delete permission. If you want to change the behavior on a per-template basis, then come up with two roles... one that has delete permission and another that doesn't. Give the user both roles. On templates where you want them to be able to delete pages, assign both roles. On templates where you don't want them to be able to delete, then only assign edit permission to the role without page-delete permission. 

  • Like 5
Link to comment
Share on other sites

:) Thank you Ryan!

Well, I meant just one specific page that uses the same template as others. I suppose then, I would have to not use the same template for it but a renamed copy thereof and assign permissions for that new template accordingly.

Link to comment
Share on other sites

ProcessWire's permissions system is designed to deal with groups of pages (by template). When you get into wanting to assign permission for a specific individual page, the best way is to use your own code to identify the page. An example would be a hook in /site/templates/admin.php

wire()->addHook('Page::editable', function($event) {
  if($event->return) return;
  $page = $event->object;
  $user = wire('user'); 
  // if page ID is 123 and user is "joe" allow edit access
  if($page->id == 123 && $user->name == 'joe') $event->return = true;  
}); 
  • Like 4
Link to comment
Share on other sites

:) Oh thanks, Ryan! Hadn´t thought of something like that - it looks very simple to do it this way!

I´m really happy about how easily solutions for special situations in Processwire can be found! The more I get to know it the happier I am with it. And also I find this forum a really friendly and helpful place!

  • Like 1
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...