mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-17 15:52:15 +00:00
it_accept_team_folder_invite
This commit is contained in:
32
database/factories/TeamFoldersInvitationFactory.php
Normal file
32
database/factories/TeamFoldersInvitationFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class TeamFoldersInvitationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = TeamFoldersInvitation::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'id' => $this->faker->uuid,
|
||||
'folder_id' => $this->faker->uuid,
|
||||
'email' => $this->faker->email,
|
||||
'permission' => $this->faker->randomElement(['can-edit', 'can-view', 'can-view-and-download']),
|
||||
'status' => $this->faker->randomElement(['pending', 'accepted', 'rejected']),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,11 @@ class CreateTeamFoldersInvitationsTable extends Migration
|
||||
$table->uuid('id')->primary();
|
||||
$table->uuid('folder_id');
|
||||
$table->text('email');
|
||||
$table->enum('permission', ['can-edit', 'can-view', 'can-view-and-download']);
|
||||
$table->enum('status', ['pending', 'accepted', 'rejected'])->default('pending');
|
||||
$table->timestamps();
|
||||
$table->charset = 'utf8mb4';
|
||||
$table->collation = 'utf8mb4_unicode_ci';
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTeamFolderMembersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('team_folder_members', function (Blueprint $table) {
|
||||
$table->uuid('folder_id');
|
||||
$table->uuid('member_id');
|
||||
$table->string('permission');
|
||||
$table->charset = 'utf8mb4';
|
||||
$table->collation = 'utf8mb4_unicode_ci';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('team_folder_members');
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Domain\Teams\Controllers\AcceptTeamFolderInvitationController;
|
||||
use Domain\Teams\Controllers\TeamFoldersController;
|
||||
|
||||
Route::apiResource('/team-folders', TeamFoldersController::class);
|
||||
|
||||
Route::post('/invitations/{invitation}', AcceptTeamFolderInvitationController::class);
|
||||
|
||||
@@ -32,7 +32,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
* @method static count()
|
||||
* @method static sortable(string[] $array)
|
||||
* @method static forceCreate(array $array)
|
||||
* @method static where(string $string, string $string1, string $toDateString)
|
||||
* @method static where(string $string, string $string1)
|
||||
* @method static create(array $array)
|
||||
* @method static find(mixed $email)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AcceptTeamFolderInvitationController extends Controller
|
||||
{
|
||||
public function __invoke(TeamFoldersInvitation $invitation): Response
|
||||
{
|
||||
|
||||
$user = User::where('email', $invitation->email)
|
||||
->firstOrFail();
|
||||
|
||||
$invitation->update([
|
||||
'status' => 'accepted',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
'folder_id' => $invitation->folder_id,
|
||||
'member_id' => $user->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
return response('Done', 201);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Domain\Teams\DTO\CreateTeamFolderData;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
@@ -23,16 +24,17 @@ class TeamFoldersController extends Controller
|
||||
]);
|
||||
|
||||
collect($data->members)
|
||||
->each(function ($email) use ($teamFolder) {
|
||||
->each(function ($member) use ($teamFolder) {
|
||||
|
||||
// Create invitation
|
||||
$invitation = TeamFoldersInvitation::create([
|
||||
'folder_id' => $teamFolder->id,
|
||||
'email' => $email,
|
||||
'permission' => $member['permission'],
|
||||
'email' => $member['email'],
|
||||
'folder_id' => $teamFolder->id,
|
||||
]);
|
||||
|
||||
// Invite user
|
||||
Notification::route('mail', $email)
|
||||
Notification::route('mail', $member['email'])
|
||||
->notify(new InvitationIntoTeamFolder($teamFolder, $invitation));
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace Domain\Teams\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Database\Factories\TeamFoldersInvitationFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,11 @@ class TeamFoldersInvitation extends Model
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected static function newFactory(): TeamFoldersInvitationFactory
|
||||
{
|
||||
return TeamFoldersInvitationFactory::new();
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Domain\Teams;
|
||||
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
use Notification;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
@@ -10,7 +13,6 @@ class TeamsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
*/
|
||||
public function it_create_team_folder()
|
||||
{
|
||||
@@ -27,8 +29,14 @@ class TeamsTest extends TestCase
|
||||
->post('/api/teams/team-folders', [
|
||||
'name' => 'Company Project',
|
||||
'members' => [
|
||||
'john@internal.com',
|
||||
'jane@external.com',
|
||||
[
|
||||
'email' => 'john@internal.com',
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'email' => 'jane@external.com',
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated()
|
||||
@@ -66,16 +74,47 @@ class TeamsTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function member_accept_team_folder_invite()
|
||||
public function it_accept_team_folder_invite()
|
||||
{
|
||||
$member = User::factory(User::class)
|
||||
->create([
|
||||
'email' => 'john@internal.com',
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create();
|
||||
|
||||
$invitation = TeamFoldersInvitation::factory()
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->postJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertCreated();
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_members', [
|
||||
'folder_id' => $folder->id,
|
||||
'member_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
])
|
||||
->assertDatabaseHas('team_folders_invitations', [
|
||||
'folder_id' => $folder->id,
|
||||
'status' => 'accepted',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function member_reject_team_folder_invite()
|
||||
public function it_reject_team_folder_invite()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user