Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify handling of owning model (performance) #319

Closed
garygreen opened this issue Jul 10, 2018 · 3 comments
Closed

Simplify handling of owning model (performance) #319

garygreen opened this issue Jul 10, 2018 · 3 comments
Labels

Comments

@garygreen
Copy link

garygreen commented Jul 10, 2018

At the moment, when you do:

Bouncer::allow(User::find(1))->toOwn(Post::class)

This will allow that particular user to own a post. If you have millions of users and want them to own posts, it will add a million records into your permissions table just for them to be able to own their own posts.

It would be cool if you could grant permission to a general user class to own their own post models:

Bouncer::allow(User::class)->toOwn(Post::class)

Where this would create only 1 permission record in the database and still allow any users to own their own posts.

@JosephSilber
Copy link
Owner

This is actually on the roadmap. Not just for owning models, but for all abilities.

@JosephSilber
Copy link
Owner

I'm closing this for now. It's on my list of things to get done. I don't want it to clutter up the issues here.

I'll also post an update to this (closed) issue when this feature will be implemented.

@JosephSilber
Copy link
Owner

JosephSilber commented Feb 25, 2019

Just pushed this update to master:

Bouncer::allowEveryone()->to('view', Post::class);

or to own:

Bouncer::allowEveryone()->toOwn(Post::class)->to('view');

...or any other ability types.


To test this:

  1. Update your composer.json file's silber/bouncer dependency to dev-master.
  2. Run composer update.
  3. Make these two columns in the permissions table nullable: entity_id and entity_type

Now you're ready to play around with these new methods:

Bouncer::allowEveryone()->to(...);
Bouncer::disallowEveryone()->to(...);
Bouncer::forbidEveryone()->to(...);
Bouncer::unforbidEveryone()->to(...);

Please test it, and let me know your findings 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants