Jump to content

Add User Edit Permission To A Page


davo
 Share

Recommended Posts

I've created a form that allows the current user to create a page (it's an event planning portal).

To edit the page, I intended for them to use the modal=1 argument for quick access.

I don't want to give all users access to edit all pages, only the ones they have been the creator for.

How do I achieve this?

For other type of page I had been using 'page edit per user' module, but that involves me manually adding a page to the user's account.

Link to comment
Share on other sites

If you've already got a form that allows the user to create a page.. why not simply make the form add the user access to edit created page too? :)

Unless that's possible, I'd suggest creating a new module based on Page Edit Per User; instead of current onMyBranch() method, simply check if given page was created by current user and based on that return true or false.

  • Like 1
Link to comment
Share on other sites

This isn't exactly what I had in mind (thought you had those users already, just wanted to give them permission to edit a page), but there's an example of creating an user at the bottom of the $user page.

If you just want to use Page Edit Per User and grant specific user access to a page via API, that looks more like this:

// I'm assuming that you're already creating pages via API; not going into detail about that..
$p = new Page;
$p->template = $templates->get("some-template");
$p->parent = $pages->get("/some-parent/");
$p->name = "some-page-name";
$p->save();

// give current current user access to edit previously created page
$user->editable_pages->add($p);
$user->save('editable_pages');
  • Like 4
Link to comment
Share on other sites

No, you're absolutely right. I do already have the user. I was trying to express 'add a user' to a page permission rather than 'add a role'.

So i think you're right; I just need to add the following to my api for creating the page. I'll give it a try a bit later. Thank you.

// give current current user access to edit previously created page

$user->editable_pages->add($p);

$user->save('editable_pages');

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...