Giter Club home page Giter Club logo

Comments (7)

landjea avatar landjea commented on May 26, 2024

Well I can't answer the first question, the second one makes more sense with $entity->created_by instead of $user->id. It gives the option to allow a user to create something on behalf of someone else. (for example an admin creating a missing "item" on behalf of a user, you want the user to own the item, not the admin)

$entity->created_by == $user->id would work fine when it belongs to the user.

from laravel-governor.

Evertt avatar Evertt commented on May 26, 2024

Thank you, that makes things clearer for me. :-)

from laravel-governor.

mikebronner avatar mikebronner commented on May 26, 2024

To you first question:

Normally when creating a new entity, in this case an Entity instance, you will pass in a new instance that has not yet been saved. This new instance may or may not already be populated. In the event that it is not populated, created_by will be null, but in the event it already was populated, it might have your current user. However, you don't want to hardcode your user->id in to the permission, it usually is better to rely on the method parameters. This makes for a less tightly coupled, and thus easier maintainable class.

I hope this helps explain things?

from laravel-governor.

mikebronner avatar mikebronner commented on May 26, 2024

If this question isn't fully answered for you, please feel free to re-open.

from laravel-governor.

Evertt avatar Evertt commented on May 26, 2024

from laravel-governor.

mikebronner avatar mikebronner commented on May 26, 2024

I will add a unit test to distinguish between the two. :) Will get back to you on this. While I think the current implementation is correct, it is possible I have not encountered the specific scenario in my own projects that would be sensitive to this.

from laravel-governor.

mikebronner avatar mikebronner commented on May 26, 2024

@Evertt I looked into this and have concluded that the functionality as it stands is correct. If a model is being evaluated in the policy, and created_by is null, it should be treated as not created by the user being evaluated, hence other is the correct assumption. If you do want it to be evaluated as own be sure to set the created_by to the respective user before evaluating.

If this doesn't answer your issue, please feel free to re-open. :)

from laravel-governor.

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.