-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add Form Request and Tests for Update Asset API Method #14458
Conversation
…sion of SubstituteBindings
This pull request has been linked to Shortcut Story #24884: ErrorException: Object of class Illuminate\Database\Eloquent\Collection could not be converted to int.... |
PR Summary
|
@marcusmoore any idea what's going on with this SQLite test? |
WAT? |
@spencerrlongg long shot, but if you can retarget (again) to develop, since v7 is live, maybe that will help? |
Yeah, I'm pretty sure I had to mess with the SQLite tests after v7 got merged. Catching the branch up should help. |
# Conflicts: # routes/api.php
alright, this should be good to go now! |
@snipe conflicts resolved |
Can I get a test to check that a user from company A cannot edit/view/etc an asset from company B if FMCS is enabled? |
Test added, I just added it for edit since that's what this PR touches, if you want me to do other multi company support in a different PR I can do that |
Oh! Thanks :) |
Description
This does a couple things:
Adds a new Form Request for Asset Updates to continue our rollout of that feature.
Unfortunately, the only way it makes sense to do this on an update request was to duplicate the validation set. There were a couple reasons for this:
prepareForValidation()
method, but it got a little confusing because of:unique_undeleted
rule does not play nice in a form request because of the trait on the model that makes it work.I still believe that the form request itself is still worth it, it makes the application safer by making sure that our data is validated before we operate on it. And after all, an update request is still it's own request with it's own logic, so it stands to reason rules could be slightly different.
Adds the SubstituteBindings middleware to API routes to allow us to use Route Model Binding.
https://laravel.com/docs/8.x/routing#route-model-binding
Really just a starting step to allowing us to get rid of a lot of lines like
SubstituteBindings is default middleware in Laravel now, so I'm not sure why it wasn't there and I couldn't find any PRs or Issues about it being removed on purpose, I'm assuming it was a symptom of an upgrade and it didn't get added because we already had custom stuff going on in our Kernel - but that's a guess, please let me know if there's a reason it isn't there, and I can look into other options.
The model-not-found exception is already inline with what we had written manually, so the error bubbles up the same if a model isn't found.
This only effects areas in which we're using type-hinting with a method & model (like
public function update(Asset $asset)
), so we shouldn't see any adverse effects from this from what I can tell.Fixes # [sc-24884]
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Tests written
Test Configuration: