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

[2.x] Change current team of user when creating a new additional team #618

Merged
merged 8 commits into from
Jan 11, 2021

Conversation

OscarKolsrud
Copy link
Contributor

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.

@OscarKolsrud OscarKolsrud marked this pull request as draft January 8, 2021 23:38
@OscarKolsrud
Copy link
Contributor Author

OscarKolsrud commented Jan 8, 2021

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?

@OscarKolsrud
Copy link
Contributor Author

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.

@OscarKolsrud OscarKolsrud marked this pull request as ready for review January 9, 2021 00:21
@@ -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));
Copy link
Contributor

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);
Copy link
Contributor

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.

Suggested change
$user->switchTeam($anotherTeam);

'name' => $input['name'],
'personal_team' => false,
]);

$user->forceFill([
Copy link
Contributor

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:

Suggested change
$user->forceFill([
$user->switchTeam($team);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying now!

Copy link
Contributor Author

@OscarKolsrud OscarKolsrud Jan 9, 2021

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!

Copy link
Contributor

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();

Copy link
Contributor Author

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 :)

@dillingham
Copy link
Contributor

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.

@OscarKolsrud
Copy link
Contributor Author

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?

@taylorotwell taylorotwell merged commit 00f9d74 into laravel:2.x Jan 11, 2021
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