-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotePolicy.php
39 lines (33 loc) · 1.05 KB
/
NotePolicy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
use Illuminate\Contracts\Auth\Authenticatable;
class NotePolicy
{
use HandlesAuthorization;
public function createNote(?Authenticatable $authenticatable): Response
{
return $this->allowAuthenticatedRotexUser($authenticatable);
}
private function allowAuthenticatedRotexUser(?Authenticatable $authenticatable): Response
{
if ($authenticatable == null) {
return Response::deny();
}
/** @var int $authIdentifier */
$authIdentifier = $authenticatable->getAuthIdentifier();
$id = $authIdentifier;
$user = User::find($id);
if ($user != null && $user->hasRole('rotex')) {
return Response::allow();
} else {
return Response::deny();
}
}
public function readNote(?Authenticatable $authenticatable): Response
{
return $this->allowAuthenticatedRotexUser($authenticatable);
}
}