Jump to content

hasPermission page-edit-created


Recommended Posts

I use the page-edit-created Permission for the blog that users can only edit there own post.
At the front end i've displayed a pencil in the user Menu for all pages where the user can edit.
I started with ``wire('user')->hasPermission('page-edit', $page)`` that works fine for all pages where the user has permission to edit but not at the blog!

At the Blog the pencil will shown to booth, article from the user and article from other users. When the user click this link, he got the message that he hasn't access to edit this post. I think that ``wire('user')->hasPermission('page-edit', $page)`` should check if user has permission to edit THIS page. Wrong? Is there another way i don't know?

To check the author (created User) ID is no option because on other templates the user has permission to all pages!

Link to comment
Share on other sites

Is this a container page that holds multiple blog posts? If so $page is likely to be the container page, not the blog post page.

In your loop that iterates the blog posts you would replace $page with whatever variable you have assigned to a single iteration. Something like:

$posts = $pages->find("template=blog_post");
foreach($posts as $post) {
    // output post content here...
    if($user->hasPermission('page-edit', $post)) {
        // output edit link here...


Link to comment
Share on other sites

Or you could check the session user....

//get all posts from the user
$posts = $pages->find("template=post, created_users_id=$user");

//check for permission in frontedn
if($page->createdUser != $user) {
    //this is not your post!

regards mr-fan

Link to comment
Share on other sites

First thanks of all the answer!

9 hours ago, tpr said:

Shooting in the dark: using $page->editable() wouldn't take care of what you need?

That is the solution i'm searching for! Without checking the creadetUser and session user ;-). Thank you!

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.

  • Create New...