Jump to content

Recommended Posts

Posted

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.

Posted

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
Posted

The first option I think is what I'm after. I couldn't find in any documentation an api call to add a user; I only found one to add a roll. Is this possible?

Posted

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
Posted

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');

Posted

That worked very well thank you.

Just out of interest, does that api feature rely on page edit module or does it work out the box with the core?

Posted

Field 'editable_pages' is added by Page Edit Per User, if that's what you're referring to. Otherwise this is just standard API usage :)

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.
×
×
  • Create New...