-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes the team invite to be simplified. Now the invite link will…
… log in the user after clicking
- Loading branch information
Showing
9 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Actions\Jetstream; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\URL; | ||
use Laravel\Jetstream\TeamInvitation as TeamInvitationModel; | ||
|
||
class TeamInvitation extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* The team invitation instance. | ||
* | ||
* @var \Laravel\Jetstream\TeamInvitation | ||
*/ | ||
public $invitation; | ||
|
||
/** | ||
* Create a new message instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(TeamInvitationModel $invitation) | ||
{ | ||
$this->invitation = $invitation; | ||
} | ||
|
||
/** | ||
* Build the message. | ||
* | ||
* @return $this | ||
*/ | ||
public function build() | ||
{ | ||
return $this->markdown('emails.team-invitation', | ||
['acceptUrl' => URL::signedRoute('team-invitations.accept', | ||
[ | ||
'user' => User::where('email', $this->invitation->email)->first()->id, | ||
'invitation' => $this->invitation, | ||
])])->subject(__('Team Invitation')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\TeamInvitation; | ||
use App\Models\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class TeamInviteAcceptController extends Controller | ||
{ | ||
public function accept(Request $request, TeamInvitation $invitation) | ||
{ | ||
$user = User::where('email', $invitation->email)->first(); | ||
$user->current_team_id = $invitation->team_id; | ||
$user->updateQuietly(); | ||
Auth::login($user); | ||
|
||
$invitation->delete(); | ||
|
||
return to_route('collections.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Team; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TeamInvitation> | ||
*/ | ||
class TeamInvitationFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'role' => 'admin', | ||
'email' => $this->faker->unique()->safeEmail(), | ||
'team_id' => Team::factory(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/Feature/Http/Controllers/TeamInviteAcceptControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Http\Controllers; | ||
|
||
use App\Models\TeamInvitation; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\URL; | ||
use Tests\TestCase; | ||
|
||
class TeamInviteAcceptControllerTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_accepts_team_invitation(): void | ||
{ | ||
$userInvited = User::factory()->create(); | ||
|
||
$invite = TeamInvitation::factory()->create([ | ||
'email' => $userInvited->email, | ||
]); | ||
|
||
$url = URL::signedRoute('team-invitations.accept', | ||
[ | ||
'invitation' => $invite, | ||
]); | ||
|
||
$this->get($url); | ||
|
||
$this->assertAuthenticatedAs($userInvited); | ||
|
||
$this->assertDatabaseCount('team_invitations', 0); | ||
|
||
//make the user since this is how the system works | ||
//add that email to the invite | ||
//then make the user and visit there | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters