Models refactor + Basic functionnalities
This commit is contained in:
58
app/Policies/ResumeComponentPlacementPolicy.php
Normal file
58
app/Policies/ResumeComponentPlacementPolicy.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user