davo Posted July 30, 2014 Share Posted July 30, 2014 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 More sharing options...
teppo Posted July 30, 2014 Share Posted July 30, 2014 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. 1 Link to comment Share on other sites More sharing options...
davo Posted July 30, 2014 Author Share Posted July 30, 2014 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? Link to comment Share on other sites More sharing options...
teppo Posted July 30, 2014 Share Posted July 30, 2014 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'); 4 Link to comment Share on other sites More sharing options...
davo Posted July 30, 2014 Author Share Posted July 30, 2014 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 More sharing options...
davo Posted July 31, 2014 Author Share Posted July 31, 2014 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? Link to comment Share on other sites More sharing options...
teppo Posted July 31, 2014 Share Posted July 31, 2014 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now