Jump to content

Problem with "page moving" permission


underk
 Share

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();
		$form->remove($fieldset);
	}
}

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
 Share

×
×
  • Create New...