Files
CVAtron/app/Policies/ResumeComponentPlacementPolicy.php
Matthias Guillitte 55a52086c1
Some checks failed
linter / quality (push) Failing after 3m25s
tests / ci (push) Failing after 12m2s
Models refactor + Basic functionnalities
2025-08-26 12:12:02 +02:00

59 lines
1.6 KiB
PHP

<?php
namespace App\Policies;
use App\Models\Resume;
use App\Models\ResumeComponentPlacement;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ResumeComponentPlacementPolicy
{
private function isCreator(User $user, ResumeComponentPlacement $componentPlacement): Response
{
return $user->id === $componentPlacement->load('resume')->resume->creator_id
? Response::allow()
: Response::deny('You do not own the resume of the component placement.');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, ResumeComponentPlacement $componentPlacement): Response
{
return $this->isCreator($user, $componentPlacement);
}
/**
* 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, ResumeComponentPlacement $componentPlacement): Response
{
return $this->isCreator($user, $componentPlacement);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ResumeComponentPlacement $componentPlacement): Response
{
return $this->isCreator($user, $componentPlacement);
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, ResumeComponentPlacement $componentPlacement): Response
{
return $this->isCreator($user, $componentPlacement);
}
}