Git Product home page Git Product logo

Comments (6)

filippotoso avatar filippotoso commented on May 27, 2024

Intercept the created event in the Permission model and attach the created permission to the superadmin role.

from laratrust.

Naamloos avatar Naamloos commented on May 27, 2024

I don't think this quite suffices as a proper solution to this problem. It sounds more like a workaround than a proper solution.

(Thank you for your response anyway, I appreciate the effort)

from laratrust.

filippotoso avatar filippotoso commented on May 27, 2024

Without modifing Laratrust behaviour there are only 2 ways to do what you need.

The first one is to keep the SuperAdmin role permissions in sync with all the available permissions (see above for the implementation)

The second one is to add a check for the SuperAdmin role everytime you check for permissions (ie. if the user has this permission OR he has the SuperAdmin role).

Otherwise, you have to change the Laratrust behaviour to check for the single permission OR check for the SuperAdmin role.

From my point of view, the first solution is the easiest and cleanest of all of them.

from laratrust.

Naamloos avatar Naamloos commented on May 27, 2024

I am not entirely sure if this would work, but after some digging, perhaps it'd be possible to override the hasPermission method on my User class that implements the LaratrustUserTrait?

Wouldn't that hide away the trait's method for my own implementation? Since class methods take precedence over trait methods.

Correct me if I'm wrong of course, but isn't that a possible solution?

from laratrust.

santigarcor avatar santigarcor commented on May 27, 2024

How I've made it in the past is by defining one permission that only super admins have and in side the policies i check if the user has that permission or the actually required permission. or by simply adding all the permissions to the admin.

from laratrust.

Naamloos avatar Naamloos commented on May 27, 2024

even though it's not exactly the solution I was looking for, it is a better solution than what was proposed before, in my honest opinion. Thank you both for your help. I'll propose this change internally.

from laratrust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.