Team functionality (#459)
* add api enpoints for adding, removing, updating user to workspace and leaving workspace * feat: updates client site workspace settings * refactor and add domain setting ui in modal * move workspace user functionality to its own component * adds tests * fix linting * updates select input to FlatSelectInput * moves workspace user role edit to seperated component * move user adding to its own component * adds check to usure users exist before checking is admin * fix loading users * feat: invite user to team functionality * fix token coulmn * fix self host mode changes * tests for user invite * Refactor back-end * Rename variables * Improve some styling elements + refactor workspace settings * More styling * More UI polishing * More UI fixes * PHP linting * Implemented most of the logic for team-functionnality * Fix user avatar URL * WIP remove users on cancellation * Finished pricing for team functionality * Fix tests * Fix linting * Added pricing_enabled helper * Fix pricing_enabled shortcut * Debug CI * Disable pricing when testing --------- Co-authored-by: LL-Etiane <lukongleinyuyetiane@gmail.com> Co-authored-by: Lukong Etiane <83535251+LL-Etiane@users.noreply.github.com> Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -54,7 +54,6 @@ it('check formstat chart data', function () {
|
||||
return true;
|
||||
})
|
||||
->where('submissions', function ($values) use ($submissions) {
|
||||
ray($values, $submissions);
|
||||
foreach ($values as $date => $count) {
|
||||
if ((isset($submissions[$date]) && $submissions[$date] != $count) || (!isset($submissions[$date]) && $count != 0)) {
|
||||
return false;
|
||||
|
||||
150
tests/Feature/UserInviteTest.php
Normal file
150
tests/Feature/UserInviteTest.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
use App\Models\UserInvite;
|
||||
use Carbon\Carbon;
|
||||
|
||||
it('can register with invite token', function () {
|
||||
$this->withoutExceptionHandling();
|
||||
$user = $this->actingAsUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$email = 'invitee@gmail.com';
|
||||
$inviteData = ['email' => $email, 'role' => 'user'];
|
||||
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
|
||||
->assertSuccessful();
|
||||
|
||||
expect($workspace->invites()->count())->toBe(1);
|
||||
$userInvite = UserInvite::latest()->first();
|
||||
$token = $userInvite->token;
|
||||
|
||||
$this->postJson('/logout')
|
||||
->assertSuccessful();
|
||||
|
||||
// Register with token
|
||||
$response = $this->postJson('/register', [
|
||||
'name' => 'Invitee',
|
||||
'email' => $email,
|
||||
'hear_about_us' => 'google',
|
||||
'password' => 'secret',
|
||||
'password_confirmation' => 'secret',
|
||||
'agree_terms' => true,
|
||||
'invite_token' => $token,
|
||||
]);
|
||||
$response->assertSuccessful();
|
||||
expect($workspace->users()->count())->toBe(2);
|
||||
});
|
||||
|
||||
it('cannot register with expired invite token', function () {
|
||||
$user = $this->actingAsUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$email = 'invitee@gmail.com';
|
||||
$inviteData = ['email' => $email, 'role' => 'user'];
|
||||
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
|
||||
->assertSuccessful();
|
||||
|
||||
expect($workspace->invites()->count())->toBe(1);
|
||||
$userInvite = UserInvite::latest()->first();
|
||||
$token = $userInvite->token;
|
||||
|
||||
$this->postJson('/logout')
|
||||
->assertSuccessful();
|
||||
|
||||
Carbon::setTestNow(now()->addDays(8));
|
||||
// Register with token
|
||||
$response = $this->postJson('/register', [
|
||||
'name' => 'Invitee',
|
||||
'email' => $email,
|
||||
'hear_about_us' => 'google',
|
||||
'password' => 'secret',
|
||||
'password_confirmation' => 'secret',
|
||||
'agree_terms' => true,
|
||||
'invite_token' => $token,
|
||||
]);
|
||||
$response->assertStatus(400)->assertJson([
|
||||
'message' => 'Invite token has expired.',
|
||||
]);
|
||||
expect($workspace->users()->count())->toBe(1);
|
||||
});
|
||||
|
||||
it('cannot re-register with accepted invite token', function () {
|
||||
$user = $this->actingAsUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$email = 'invitee@gmail.com';
|
||||
$inviteData = ['email' => $email, 'role' => 'user'];
|
||||
$this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
|
||||
->assertSuccessful();
|
||||
|
||||
expect($workspace->invites()->count())->toBe(1);
|
||||
$userInvite = UserInvite::latest()->first();
|
||||
$token = $userInvite->token;
|
||||
|
||||
$this->postJson('/logout')
|
||||
->assertSuccessful();
|
||||
|
||||
// Register with token
|
||||
$response = $this->postJson('/register', [
|
||||
'name' => 'Invitee',
|
||||
'email' => $email,
|
||||
'hear_about_us' => 'google',
|
||||
'password' => 'secret',
|
||||
'password_confirmation' => 'secret',
|
||||
'agree_terms' => true,
|
||||
'invite_token' => $token,
|
||||
]);
|
||||
$response->assertSuccessful();
|
||||
expect($workspace->users()->count())->toBe(2);
|
||||
|
||||
$this->postJson('/logout')
|
||||
->assertSuccessful();
|
||||
|
||||
// Register again with same used token
|
||||
$response = $this->postJson('/register', [
|
||||
'name' => 'Invitee',
|
||||
'email' => $email,
|
||||
'hear_about_us' => 'google',
|
||||
'password' => 'secret',
|
||||
'password_confirmation' => 'secret',
|
||||
'agree_terms' => true,
|
||||
'invite_token' => $token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)->assertJson([
|
||||
'message' => 'The email has already been taken.',
|
||||
]);
|
||||
expect($workspace->users()->count())->toBe(2);
|
||||
});
|
||||
|
||||
it('can cancel user invite', function () {
|
||||
$user = $this->actingAsUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$email = 'invitee@gmail.com';
|
||||
$inviteData = ['email' => $email, 'role' => 'user'];
|
||||
$response = $this->postJson(route('open.workspaces.users.add', $workspace->id), $inviteData)
|
||||
->assertSuccessful();
|
||||
|
||||
expect($workspace->invites()->count())->toBe(1);
|
||||
$userInvite = UserInvite::latest()->first();
|
||||
$token = $userInvite->token;
|
||||
|
||||
// Cancel the invite
|
||||
$this->deleteJson(route('open.workspaces.invites.cancel', ['workspaceId' => $workspace->id, 'inviteId' => $userInvite->id]))
|
||||
->assertSuccessful();
|
||||
|
||||
$this->postJson('/logout')
|
||||
->assertSuccessful();
|
||||
|
||||
// Register with token
|
||||
$response = $this->postJson('/register', [
|
||||
'name' => 'Invitee',
|
||||
'email' => $email,
|
||||
'hear_about_us' => 'google',
|
||||
'password' => 'secret',
|
||||
'password_confirmation' => 'secret',
|
||||
'agree_terms' => true,
|
||||
'invite_token' => $token,
|
||||
]);
|
||||
$response->assertStatus(400)->assertJson([
|
||||
'message' => 'Invite token is invalid.',
|
||||
]);
|
||||
|
||||
expect($workspace->users()->count())->toBe(1);
|
||||
});
|
||||
90
tests/Feature/WorkspaceUserTest.php
Normal file
90
tests/Feature/WorkspaceUserTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Workspace;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\UserInvitationEmail;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = $this->actingAsProUser();
|
||||
$this->workspace = Workspace::factory()->create();
|
||||
$this->workspace->users()->attach($this->user, ['role' => 'admin']);
|
||||
});
|
||||
|
||||
it('can list users in a workspace', function () {
|
||||
|
||||
$this->getJson(route('open.workspaces.users.index', ['workspaceId' => $this->workspace->id]))
|
||||
->assertSuccessful()
|
||||
->assertJsonCount(1);
|
||||
});
|
||||
|
||||
it('can add a user to a workspace', function () {
|
||||
$newUser = User::factory()->create(['email' => 'newuser@example.com']);
|
||||
$this->postJson(route('open.workspaces.users.add', ['workspaceId' => $this->workspace->id]), [
|
||||
'email' => $newUser->email,
|
||||
'role' => 'user',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'message' => 'User has been successfully added to workspace.'
|
||||
]);
|
||||
|
||||
expect($this->workspace->users()->count())->toBe(2);
|
||||
});
|
||||
|
||||
it('can send an invitation email to a non-existing user', function () {
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson(route('open.workspaces.users.add', ['workspaceId' => $this->workspace->id]), [
|
||||
'email' => 'nonexisting@example.com',
|
||||
'role' => 'user',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'message' => 'Registration invitation email sent to user.'
|
||||
]);
|
||||
|
||||
Mail::assertQueued(UserInvitationEmail::class);
|
||||
});
|
||||
|
||||
it('can update user role in a workspace', function () {
|
||||
$existingUser = User::factory()->create();
|
||||
$this->workspace->users()->attach($existingUser, ['role' => 'user']);
|
||||
|
||||
$this->putJson(route('open.workspaces.users.update-role', [
|
||||
'workspaceId' => $this->workspace->id,
|
||||
'userId' => $existingUser->id
|
||||
]), [
|
||||
'role' => 'admin',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'message' => 'User role changed successfully.'
|
||||
]);
|
||||
});
|
||||
|
||||
it('can remove a user from a workspace', function () {
|
||||
$existingUser = User::factory()->create();
|
||||
$this->workspace->users()->attach($existingUser);
|
||||
|
||||
$this->deleteJson(route('open.workspaces.users.remove', [
|
||||
'workspaceId' => $this->workspace->id,
|
||||
'userId' => $existingUser->id
|
||||
]))
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'message' => 'User removed from workspace successfully.'
|
||||
]);
|
||||
|
||||
expect($this->workspace->users()->count())->toBe(1);
|
||||
});
|
||||
|
||||
it('can leave a workspace', function () {
|
||||
$this->postJson(route('open.workspaces.leave', ['workspaceId' => $this->workspace->id]))
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'message' => 'You have left the workspace successfully.'
|
||||
]);
|
||||
|
||||
expect($this->workspace->users()->count())->toBe(0);
|
||||
});
|
||||
Reference in New Issue
Block a user