team members and invitations

This commit is contained in:
Doar Mihai
2026-03-21 16:13:38 +02:00
parent 756747cd00
commit add7169de3
15 changed files with 666 additions and 31 deletions
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace App\Policies;
use App\Models\Project;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ProjectPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Project $project): bool
{
return $project->users()->where('users.id', $user->id)->exists();
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Project $project): bool
{
return $this->hasRole($user, $project, ['owner', 'admin']);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Project $project): bool
{
return $this->hasRole($user, $project, ['owner']);
}
/**
* Determine whether the user can manage members.
*/
public function manageMembers(User $user, Project $project): bool
{
return $this->hasRole($user, $project, ['owner', 'admin']);
}
/**
* Determine whether the user can manage settings.
*/
public function manageSettings(User $user, Project $project): bool
{
return $this->hasRole($user, $project, ['owner', 'admin']);
}
/**
* Check if user has one of the specified roles for the project
*/
private function hasRole(User $user, Project $project, array $roles): bool
{
$userRole = $project->users()
->where('users.id', $user->id)
->first()
?->pivot
?->role;
return $userRole && in_array($userRole, $roles);
}
}