[5.8] Add a 'manage' default policy - #28654
Conversation
In our normal resource controller, we have `index`, `create`, `store`, `edit`, `show`, `update`, and `destroy`. Our default policy has methods that correspond to most of these methods. `view` --> `show` `create` --> `create` and `store` `update` --> `edit` and `update` `delete` --> `destroy` The one clear omission is we have no default policy that corresponds to the `index` method. The `index` method traditionally contains a list of all items of a particular Model. I'm proposing a new default policy called `manage` that can be used to determine if a `User` is allowed to access the `index` resource route.
|
Good idea. But I would call it |
|
Definitely not opposed to a name change. Thanks for the feedback. |
|
I think you should also modify the |
|
This was intentionally removed a while back. Taylor has commented why. Not where I can dig for it right now. |
|
I know (see link below), but what's the point of the |
|
The reason it was omitted is because it's not as commonly used. If you have a list of comments you would typically just filter the comments the user is allowed to see in the query you run against the database. However, there are sometimes places where this makes sense. I think I have done it once myself. I would not call it manage though... the suggestion of |
also fixed the comment to use the Plural version of the model name.
|
I'm good with 'list' as long as we don't have any conflicts with the PHP native I will say personally I use this everywhere, especially on an administrative backend. I would agree on the frontend you'd only want to list things that belong to a user. A user's comments, a user's payments, etc. But on the backend, as an administrator, you would want to see everything. All the Users, all the Comments, all the Payments. But you may selectively allow different administrative users to access different lists, based on their role. If this PR gets accepted, I can make the changes in |
|
Laravel Nova uses |
|
Ah yes, viewAny... probably worth keeping that to be consistent. |
|
Sorry if bumping this issue is not acceptable. It seems weird to stub out code for the user that is not used. I had the (dangerous) impression that Is it possible to denote in either the docstring or in the documentation that some of these policies are picked up by The documentation lists the policies that will be mapped but I was more inclined to believe the stubbed out code than the documentation. If you are finding this thread through google like I did, I needed to add the following in credit to laravel/ideas#772 (comment) |
|
For anyone stumbling on this issue, after Laravel 6.0 adding the viewAny method to a Policy now works automatically with the Index function on a resourceful controller. And Taylor is right that permission policies for the Index function is an unusual function in a consumer app, but it's great for admin apps and internal business apps. |
In our normal resource controller, we have
index,create,store,edit,show,update, anddestroy.Our default policy has methods that correspond to most of these methods.
view-->showcreate-->createandstoreupdate-->editandupdatedelete-->destroyThe one clear omission is we have no default policy that corresponds to the
indexmethod. Theindexmethod traditionally contains a list of all items of a particular Model.I'm proposing a new default policy called
managethat can be used to determine if aUseris allowed to access theindexresource route.