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

[Multi-Company] Fixes Users Being Moved With Items Still Assigned #15284

Merged
merged 13 commits into from
Aug 29, 2024

Conversation

spencerrlongg
Copy link
Collaborator

@spencerrlongg spencerrlongg commented Aug 13, 2024

Description

Adds a check to determine whether a user has any items assigned before being moved between companies. The logic happens in SaveUserRequest - so the logic works in both the UI and API. Route model binding is also now present for these routes - added to get the handy $this->user in the request, as well as remove some lines in the controllers.

One shortcoming - if the user has un-reassignable licenses, then it gets difficult to move the user, because you'd need to make the license reassignable before checking it in. We can talk about that next time we chat.

Fixes #15265

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tests written.

Test Configuration:

  • PHP version: 8.1
  • MySQL version 8.2

Copy link

what-the-diff bot commented Aug 13, 2024

PR Summary

  • Enhancement in User Asset Management
    In the UserController, the system will now fetch associated user assets including consumables, licenses, locations, and accessories when handling user requests. This increases the system's responsiveness and effectiveness in managing user assets.

  • Preventing Unintended Company Changes
    The update function in the UserController has been refined. Now, if a user has assigned items, changing their company is prohibited. This means a user cannot accidentally be moved to a different company if they still have resources tied to them in their current company. This makes resource management and tracking more effective.

  • Added New Translation Message
    Introduced a new translation message referred to as 'multi_company_items_assigned'. The exact purpose of this message isn't clear without further context, but it appears to handle scenarios involving assignment of items across multiple companies. This helps enhance the multilingual feature of the application and thus its accessibility to international users.

@spencerrlongg spencerrlongg marked this pull request as ready for review August 16, 2024 17:59
@spencerrlongg spencerrlongg requested a review from snipe as a code owner August 16, 2024 17:59
@@ -427,13 +427,10 @@ public function show($id) : JsonResponse | array
* @param \Illuminate\Http\Request $request
* @param int $id
*/
public function update(SaveUserRequest $request, $id) : JsonResponse
public function update(SaveUserRequest $request, User $user): JsonResponse
{
$this->authorize('update', User::class);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this can go away now, and was there to first check that a user could update users in general before doing the check to find the user? but wanted to double check.

@marcusmoore
Copy link
Collaborator

Hm....tests failed on MySQL and PHP 8.3...

1) Tests\Feature\Checkouts\Ui\AssetCheckoutTest::testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsUserTarget
ErrorException: require(/home/runner/work/snipe-it/snipe-it/bootstrap/cache/routes-v7.php): Failed to open stream: No such file or directory

Another PR failed on the same or similar error recently. Kinda odd. I just re-triggered it and it went green.

@snipe
Copy link
Owner

snipe commented Aug 20, 2024

Yeah, that seems to happen sometimes. 🤷‍♀️

Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Nice use of $fail to inline the validation errors 😄

@spencerrlongg
Copy link
Collaborator Author

This looks good to me. Nice use of $fail to inline the validation errors 😄

Thanks to the article you sent!

@snipe snipe merged commit c197644 into snipe:develop Aug 29, 2024
8 of 9 checks passed
@snipe
Copy link
Owner

snipe commented Aug 29, 2024

After merging this, I'm getting a gateway timeout when trying to create a new user. We're looking into it.

});
});

Route::match(['put', 'patch'], '{user}/update', [Api\UsersController::class, 'update'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a method not found error. #15435

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via #15440

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

Successfully merging this pull request may close these issues.

3 participants