97 lines
2.3 KiB
PHP
97 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Permission;
|
|
use App\Models\PermissionAssignment;
|
|
use App\Models\Project;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @extends Factory<PermissionAssignment>
|
|
*/
|
|
class PermissionAssignmentFactory extends Factory
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'permission' => Permission::ProjectRead->value,
|
|
'assignee_id' => User::factory(),
|
|
'assignee_type' => (new User)->getMorphClass(),
|
|
'scope_id' => Project::factory(),
|
|
'scope_type' => (new Project)->getMorphClass(),
|
|
];
|
|
}
|
|
|
|
public function forAssignee(Model $assignee): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'assignee_id' => $assignee->getKey(),
|
|
'assignee_type' => $assignee->getMorphClass(),
|
|
]);
|
|
}
|
|
|
|
public function forScope(Model $scope): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'scope_id' => $scope->getKey(),
|
|
'scope_type' => $scope->getMorphClass(),
|
|
]);
|
|
}
|
|
|
|
public function global(): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'scope_id' => null,
|
|
'scope_type' => null,
|
|
]);
|
|
}
|
|
|
|
public function permission(Permission $permission): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'permission' => $permission->value,
|
|
]);
|
|
}
|
|
|
|
public function globalAdmin(): static
|
|
{
|
|
return $this->global()->permission(Permission::GlobalAdmin);
|
|
}
|
|
|
|
public function projectAdmin(): static
|
|
{
|
|
return $this->permission(Permission::ProjectAdmin);
|
|
}
|
|
|
|
public function projectRead(): static
|
|
{
|
|
return $this->permission(Permission::ProjectRead);
|
|
}
|
|
|
|
public function projectWrite(): static
|
|
{
|
|
return $this->permission(Permission::ProjectWrite);
|
|
}
|
|
|
|
public function teamAdmin(): static
|
|
{
|
|
return $this->permission(Permission::TeamAdmin);
|
|
}
|
|
|
|
public function teamInvite(): static
|
|
{
|
|
return $this->permission(Permission::TeamInvite);
|
|
}
|
|
|
|
public function teamManage(): static
|
|
{
|
|
return $this->permission(Permission::TeamManage);
|
|
}
|
|
}
|