64 lines
1.8 KiB
PHP
64 lines
1.8 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;
|
|
}
|
|
|
|
public function createForResume(User $user, ResumeComponentPlacement $componentPlacement): bool
|
|
{
|
|
return $user->can('update', $componentPlacement->load('resume')->resume);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|