2022-11-16 12:12:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Models\Template;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
|
|
|
class TemplatePolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can create models.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @return \Illuminate\Auth\Access\Response|bool
|
|
|
|
*/
|
|
|
|
public function create(User $user)
|
|
|
|
{
|
2023-10-13 10:11:03 +00:00
|
|
|
return $user !== null;
|
2023-09-08 11:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can update the model.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Template $template
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function update(User $user, Template $template)
|
|
|
|
{
|
2023-10-13 10:11:03 +00:00
|
|
|
return $user->admin || $user->template_editor || $template->creator_id === $user->id;
|
2023-09-08 11:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can delete the model.
|
|
|
|
*
|
|
|
|
* @param \App\Models\User $user
|
|
|
|
* @param \App\Models\Template $template
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function delete(User $user, Template $template)
|
|
|
|
{
|
2023-10-13 10:11:03 +00:00
|
|
|
return $user->admin || $user->template_editor || $template->creator_id === $user->id;
|
2022-11-16 12:12:48 +00:00
|
|
|
}
|
|
|
|
}
|