Implement full CRUD operations for team members with TDD approach: Backend: - TeamMemberController with REST API endpoints - TeamMemberService for business logic extraction - TeamMemberPolicy for authorization (superuser/manager access) - 14 tests passing (8 API, 6 unit tests) Frontend: - Team member list with search and status filter - Create/Edit modal with form validation - Delete confirmation with constraint checking - Currency formatting for hourly rates - Real API integration with teamMemberService Tests: - E2E tests fixed with seed data helper - All 157 tests passing (backend + frontend + E2E) Closes #22
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\TeamMember;
|
|
use App\Models\User;
|
|
|
|
class TeamMemberPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
// All authenticated users can view team members
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*/
|
|
public function view(User $user, TeamMember $teamMember): bool
|
|
{
|
|
// All authenticated users can view individual team members
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
// Only superusers and managers can create team members
|
|
return in_array($user->role, ['superuser', 'manager']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*/
|
|
public function update(User $user, TeamMember $teamMember): bool
|
|
{
|
|
// Only superusers and managers can update team members
|
|
return in_array($user->role, ['superuser', 'manager']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*/
|
|
public function delete(User $user, TeamMember $teamMember): bool
|
|
{
|
|
// Only superusers and managers can delete team members
|
|
return in_array($user->role, ['superuser', 'manager']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can restore the model.
|
|
*/
|
|
public function restore(User $user, TeamMember $teamMember): bool
|
|
{
|
|
// Only superusers and managers can restore team members
|
|
return in_array($user->role, ['superuser', 'manager']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can permanently delete the model.
|
|
*/
|
|
public function forceDelete(User $user, TeamMember $teamMember): bool
|
|
{
|
|
// Only superusers can force delete team members
|
|
return $user->role === 'superuser';
|
|
}
|
|
}
|