williamcruzme / vue-gates

🔒 A Vue.js & Nuxt.js plugin that allows you to use roles and permissions in your components or DOM elements, also compatible as middleware and methods.
https://williamcruzme.github.io/vue-gates/
MIT License
263 stars 31 forks source link

How about a super user? #9

Closed yamenarahman closed 4 years ago

yamenarahman commented 5 years ago

Like Laravel; we can grant access to all permissions for user by set Gate::before() method.

How can we implement it on the front end side? maybe setting a super role during registering the component like:

Vue.use(LaravelPermissions, { persistent: true, superRole: 'admin' });

so that meens if the auth user has role 'admin' he could pass all permissions.

I'm willing to implement this in a PR but give me a little guidance please. Thanks.

williamcruzme commented 5 years ago

Hi @yamenarahman! Thank you very much for your enthusiasm for improving the package 🎉. Have you tried the v-role-or-permission directive?

Check for role or permission:

<button v-role-or-permission="'super|add articles'">Add Article</button>

Tell me if this can solve the problem.

yamenarahman commented 5 years ago

Hi @williamcruzme First of all great work man! Yes, I've tried this directive but I think it's not applicable for multiple permissions, right? So I guess the following code doesn't work:

<button v-role-or-permission="'super|Edit article|Edit any article'">Edit Article</button>

How to get around these?

williamcruzme commented 5 years ago

You have an excellent point, I think if I convert multiple permissions/roles to comma separated, it could work.

<button v-role-or-permission="'super|add articles,edit articles'">Manage Articles</button>

What do you think @yamenarahman?

yamenarahman commented 4 years ago

I tried it:

<button v-role-or-permission="'super|Edit article,Edit any article'">Edit Article</button>

But this checks all permissions to be true not 'OR'.

williamcruzme commented 4 years ago

No no @yamenarahman, its a suggestion of a new feature.

yamenarahman commented 4 years ago

Sounds great! also how about renaming the directive to v-role:or-permissions:any and v-role:or-permissions:all.

I'm willing to submit a PR would you suggest me how to begin adding these features?

williamcruzme commented 4 years ago

If you like, create a PR and we will implement it 😎

marielsabornido commented 4 years ago

Hi @williamcruzme

The idea of a super-admin was to avoid for having to check access every time throughout the app, putting it in a v-role-or-permission is still counterproductive. I think @yamenarahman first idea is still applicable for enhancement so that we could set a super-admin globally.

Vue.use(LaravelPermissions, { persistent: true, superRole: 'admin' });

williamcruzme commented 4 years ago

@marielsabornido @yamenarahman Thank you very much for the feedback, I'll work on this issue and others. Something big is coming! 🎉, and it will be compatible with Vue 3 😎

williamcruzme commented 4 years ago

The feature has been successfully added. Thanks for the input! 🙌

e69f26a26dbbbb5e6b5a4434ac5e69c7ca8af489

marielsabornido commented 4 years ago

@williamcruzme Looks amazing man. Thanks for the plugin by the way, was having issues applying permissions in vue, this was a godsend.