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

check delete permission against model not DataType #4780

Merged
merged 6 commits into from Mar 9, 2020

Conversation

JackShev
Copy link
Contributor

For deleting models authorisation should get model as param, because in policies we use specific model attributes.
Example:
$model->deleted_at in BasePolicy
or $model->author_id in in PostPolicy

@fletch3555
Copy link
Collaborator

It is getting an instance of the model, but not the specific instance the row is rendering. This was done to reduce database queries, since we never used to cache permissions. I'd like to see evidence that this doesn't introduce the n+1 problem.

@MrCrayon
Copy link
Collaborator

@fletch3555 this change is in destroy method not index.
I didn't test it yet but it makes absolutely sense to check authorization for each instance otherwise it could be possible to delete even records that we are not allowed to delete based on policy.

@fletch3555
Copy link
Collaborator

You're correct. I hadn't noticed the method name.

I have no issues with this.

@JackShev
Copy link
Contributor Author

JackShev commented Mar 2, 2020

I have changed it because in example posts module delete button is displayed when I'm an author of the post. But when try to delete there is error 403. It happens because in view policy is chacked against specific model. So I think it is logic to check it the same way in controller.

@fletch3555 fletch3555 merged commit e41cbfc into thedevdojo:1.3 Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants