Jump to content

Problem with "page moving" permission


Recommended Posts

Hi there!

I try to add a permission to a certain group so each user will be able to edit his OWN page(wich will be created programmatically). And they must not move the page, even within the same parent.

First, the group have only view-page and edit-page permission.

And I created a module with this code:

public function init() {
	$this->addHookAfter('Page::editable', $this, 'editable');

public function editable($event){
	$page = $event->object;

        if($event->return) return;

	// if it's the role I want to edit permission
	if($this->user->hasRole("commercant")) {
		// if it's his page
		if ($page->created_users_id == $this->user->id) {
			$event->return = true;

I found this strange that there's a button for moving the page (on the page listing).. So I tried it and it doesn't worked, even within the same parent. Not so bad, but I would hope to find a solution to remove the "Move" button.

After, I tried to change the parent when editing the page(under settings tab) and it did it with success :huh: .

So I wonder, is my code have done anything wrong? Quite strange!

I use the last dev version.

Thank's for your time!

Link to comment
Share on other sites

It's hard to tell for sure without knowing the full scope of your user, role and permission settings as well as other things about the context. Keep in mind that a user can have multiple roles, and they will gain the combined set of permissions from those roles. Also keep in mind that these roles are activated for pages on a per-template basis with each templates' settings. If the combined permissions for a user don't allow them page-move or page-sort permission, then they shouldn't see a "move" link in the page list, nor should the see a "change parent" section in the page editor. Of course, this can all be overridden by modules and hooks. But I don't see anything in the code you've posted that would indicate it's overriding either of those permissions. 

  • Like 1
Link to comment
Share on other sites

Hi and thank's for your answer!

I understand this is quite hard to tell what is causing this problem without precise information. When I'll have a some time in the next weeks, I'll try to replicate what I've done in a fresh install and document each step one by one(and give a .zip). It's probably that I assume wrongly a behavior. For now the problem is "fixed" as I've hidden the settings tab :).

Thank's for your time!

  • Like 1
Link to comment
Share on other sites

I found some code in this forum that helped me:

$this->addHookAfter("ProcessPageEdit::buildForm", $this, "hookBuildForm"); // to add to init()

public function hookBuildForm(HookEvent $event) {
	$form = $event->return;

	if($this->user->hasRole("commercant")) {
		$fieldset = $form->find("id=ProcessPageEditSettings")->first();

I hope this is a correct way to do this :).

Link to comment
Share on other sites

If that works, I think it should be fine. Another way to do it is to enable $config->advanced=true; in your /site/config.php temporarily, and you'll see a new "system" tab appear when editing a template. There is a checkbox there to disable the settings tab. But note that applies for everyone, not just a single role. If you use this, remember to change $config->advanced=false; as it's not intended to be something you leave on and some settings it offers are irreversible (thus can be dangerous). 

  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Guy Incognito
      I'm trying to build a search selector that includes a checkbox multiple option field (clinicdetails_specialisms). The whole selector works fine if I don't include the checkbox field. With it included I get errors like "Error: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters (in wire/core/PageFinder.php line 627)".
      This is the selector as it currently stands.
      subscription_status=active,(template=user,clinicdetails_description|clinicdetails_short_description|clinicdetails_clinic_name|clinicdetails_first_name|clinicdetails_last_name*=$query),(clinicdetails_specialisms.title=$query) I've also tried setting the specialisms field in one string rather than groups and have also tried with/without the '.title' property.
      Oddly the selector works if specialisms is the only field being searched. It seems to fail when mixed with other selectors.
      Can anyone advise what stupid mistake I'm making!
    • By jonatan
      "Permission “page-sort” for template “ ... ” not allowed (requires “page-edit” permission)"

      – This lovely error message is thrown at me, if, as implied by it, I try to add (to my "editor" role) the permission "page-sort" for a specific template, without the permission "page-edit" enabled for the same template.
      Seems like it's been mentioned a few times before but never properly answered, by e.g. @Robin S ... :  
      "Allow the granting of page-sort permission independent of page-edit": https://github.com/processwire/processwire-requests/issues/29

      Why do I wanna do this?:

      I have a page tree structure  🌳  as so:


      Category [C1]
      – Page a [C1_p] – Page b [C1_p] Different category [C2]
      – Page c [C2_p] – Page d [C2_p] ________________________

      The page "Category" has the page-template "C1",
      the pages "Page a" and "Page b" both have the page-template "C1_p".
      The page "Different category" has the page-template "C2"
      the pages "Page c" and "Page d" both have the page-template "C2_p".
      The two pages called "Category" and "Different category" do not have any content, they only serve as containers for pages belonging to that category.
      I want my "editor" role not to be able to do anything at all with these pages "Category" and "Different category"; i.e. I do not want my editor to be able to edit, move, unpublish, hide, lock, delete (or do anything else to) these category pages. 
      – So, I want my "editor" role to have the "page-edit" permission for pages with the templates "C1_p" and "C2_p", but not for the pages with the category templates "C1" and "C2",
      Also, I want my "editor" role to be able to move the pages with the templates "C1_p" and "C2_p" within their parent-pages. 


      But if I just simply add the "page-edit" and the "page-move" permissions for the "C1_p" and "C2_p" templates, then, using the "editor" role, I am not able to move these "C1_p" (and "C2_p") -template-based pages. I can actually click "MOVE" next to them and then move them, but... then I will be met by the error message "You do not have permission to sort pages using this parent - /Category/".  
      – So, I try to add the "page-sort" (description: "permission to sort child pages") permission to the "C1" and "C2" templates... but then trying to do so I am met by the initially mentioned error message   ! Permission “page-sort” for template “C1” not allowed (requires “page-edit” permission)  . 
      And, as mentioned, I do not want my editor role users to be able to edit these category ("C1" and "C2") pages...
      – what to do about this? 😅 
      All the best,
    • By snck
      Hey there,
      for a client website I need to implement a "reviewer" role. "Reviewers" should be able to review new (unpublished) articles to give feedback to editors, but not have the permission to change them. 
      I built a new "reviewer" role that only has page-view permissions for the respective templates, but this permission does not include viewing unpublished pages. How can I grant them access to the unpublished articles without giving them page-edit permission?
    • By spercy16
      After doing a Google search for the issue I saw several previous posts mentioning this same issue but cannot figure out how to fix it and shouldn't have to spend a half hour trying to. ProcessWire frequently logs out of the admin area after less than five minutes. It shouldn't time-out ever, and if someone wanted that option for security reasons they should be able to enable it through the settings in their admin panel. In addition to it not being the default setting, users also shouldn't need to edit your config files manually to change these kinds of settings. Please fix the major issue in a future release. It's absured imho that developers don't realize the inconvenience it places on other people if they have to login every time they switch back to that page. It has also logged me out without warning without any visual que that it did so. If someone was working on paragraphs of content they could easily lose their work do to this bug as well... Please don't refer me to a forum with a dozen possible solutions to the issue and fix it yourselves. I'm sick of looking at them. It's your job to troubleshoot your software, not your users!
    • By benbyf
      Hello, and welcome to what I though was either my client being silly and changing things, or some evil doer. Turns out its reproducible and therefore something in Proceswire (I checked my templates and modules but couldnt find anything that would be doing this...). So what is it doing? Check out the video for evidence.
      A repeater field is interacting with a page template and another repeater field somehow to swap the fields in the template and repeater over...
      I have a template called team, and a repeater field called team_repeater with label Team. Some how and for some reason, when I change my fields on repeater called main_menu_links my team template gets those fields and when I try and revert the team template fields to the fields it should have, they get given to the repeater main_menu_links. Also this to say HELP!!!!!
      video: https://www.dropbox.com/s/exkdhc6n7x0xpsa/strange-repeater-PW-mega-bug.mov?dl=0
  • Create New...