Domanda

I am using sentry for my application.

but, I am still confused to implements sentry permission to declare the owner of the object.

for example : any authors writing an articles.

my question : how to set permissions by the owner of the article ?

È stato utile?

Soluzione

I wouldn't see Sentry as being used for this, as it is a simple comparison of current user id to article author id. To use the default Sentry permissions for this you would need to add a new permission to the user permissions for every article that the user added, as far as I am aware - or otherwise extend the Sentry package with a custom function to handle this.

Another approach would be to use Sentry to check if the user is allowed to add an article in the first place, by adding author permissions to the user, or creating an authors group, and then check if they are the owner by just comparing the user and author id. You could also have an edit permission or group for users that can edit any article. Checks would then be something like:

//see if user can add article via sentry permissions
if ($current_user->hasAccess('author'))

//see if user can edit current article if they are author, or have edit permissions
if (($current_user->id == article->author_id) || $current_user->hasAccess('edit'))

with the hasAccess('edit') part using Sentry to check if user can edit the article even though they are not the author.

You would probably want to abstract out the owner check though if you are checking in multiple places in case you change the way you evaluate ownership at any point.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top