-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Better validation for relations on delete #14830
Better validation for relations on delete #14830
Conversation
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
PR Summary
|
Signed-off-by: snipe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and I love the DeleteUserRequest FormRequest thingee - it starts to shrink our controllers down to something more manageable, and I also love being able to re-use the same request between the API and GUI controllers. Very slick work! I did mention that, if you wanted, you could consider moving the ->authorize()
calls up into the FormRequest if you wanted to - but that's not a dealbreaker for me at all. Thanks for doing this!
{ | ||
$this->authorize('delete', User::class); | ||
$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed(); | ||
$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'); | ||
$user = Company::scopeCompanyables($user)->find($id); | ||
$this->authorize('delete', $user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to, you could move this logic to the DeleteUserRequest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did mention that, if you wanted, you could consider moving the ->authorize() calls up into the FormRequest if you wanted to - but that's not a dealbreaker for me at all. Thanks for doing this!
We don't do that anywhere else, and it seemed too big a leap for this PR. We'd need to extensively test anything that touches permissions.
I'm a little puzzled why the tests are failing here. When I test this directly in the browser, it behaves as expected, redirecting me back to the users page. I'm sure it's something dumb, but... |
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Still working through some failing tests on this, but wanted to put it up to see if we even like this approach.
The failure seems to be on the GUI redirect, where it seems to be redirecting back to the dashboard for some reason, even though I don't see where we'd be doing that.
On the API side, the response now looks like this: