-
Notifications
You must be signed in to change notification settings - Fork 825
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
[2.x] Change current team of user when creating a new additional team #618
Conversation
Hmm, the tests are logically enough failing because its trying to assert that its the same team even though its been changed in the create function. Any suggestions on how to best solve this? Changing the test? The way i have done it works perfectly on the livewire stack, but have not tested yet on inertia. Imagine that could be a potential problem. Confirm/deny? |
Okay, I have gone ahead and manually tested both the Inertia stack and the Livewire stack that these changes do not break how the f.ex team switcher updates. I think that line 150 of the TeamBehaviorTest is unneeded and can be removed to allow for this change to proceed. |
@@ -147,8 +147,6 @@ public function test_user_does_not_need_to_refresh_after_switching_teams() | |||
|
|||
$anotherTeam = $action->create($user, ['name' => 'Test Team']); | |||
|
|||
$this->assertTrue($user->isCurrentTeam($personalTeam)); |
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.
Why not just move this line to before the previous line is executed?
@@ -147,8 +147,6 @@ public function test_user_does_not_need_to_refresh_after_switching_teams() | |||
|
|||
$anotherTeam = $action->create($user, ['name' => 'Test Team']); | |||
|
|||
$this->assertTrue($user->isCurrentTeam($personalTeam)); | |||
|
|||
$user->switchTeam($anotherTeam); |
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 line can be removed now.
$user->switchTeam($anotherTeam); |
'name' => $input['name'], | ||
'personal_team' => false, | ||
]); | ||
|
||
$user->forceFill([ |
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.
Rethinking this for the failed tests:
$user->forceFill([ | |
$user->switchTeam($team); |
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.
Trying now!
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.
@joelbutcher That seems to solve the failing tests! But lastly i cant wrap my head around why StyleCI is bugging us. That file looks perfectly fine to me. Do you see any thing? EDIT: Solved it!
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.
@OscarKolsrud it's the white space after
$personalTeam->forceFill(['personal_team' => true])->save();
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.
Fixed! All tests passing! I think this is now ready to merge :)
Maybe out of the scope of this PR, I was thinking about doing this + redirecting to the team edit screen in my project. Naturally would want to add members after creating a team. |
Cool idea! Maybe i will make a PR later that adds a config option of where to redirect after team creation, dont think its smart to make this PR very big! Could see tons of situations where that would be useful. For now maybe add the change yourself (On the livewire controller I imagine), or maybe you could possibly even make use of a middleware? |
Current behaviour is when a new team is created you are redirected back to the dashboard of the team that you were in before creating the new. In almost all cases a users next action would be directed against the new team.
This PR solves that problem by modifying the CreateTeam class and updating the current_team_id param on the user model of the user creating the team. This way when the user is redirected back they are acting in the context of the newly created team.