kreativmonkey Posted July 4, 2016 Posted July 4, 2016 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!
tpr Posted July 4, 2016 Posted July 4, 2016 Shooting in the dark: using $page->editable() wouldn't take care of what you need?
Robin S Posted July 5, 2016 Posted July 5, 2016 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... } }
mr-fan Posted July 5, 2016 Posted July 5, 2016 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
kreativmonkey Posted July 5, 2016 Author Posted July 5, 2016 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!
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