|
1
|
|
|
<?php namespace Arcanesoft\Blog\Policies; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Contracts\Auth\Models\User; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class PostsPolicy |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanesoft\Blog\Policies |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class PostsPolicy |
|
12
|
|
|
{ |
|
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
14
|
|
|
| Getters and Setters |
|
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* Get the policies. |
|
19
|
|
|
* |
|
20
|
|
|
* @return array |
|
21
|
|
|
*/ |
|
22
|
8 |
|
public static function getPolicies() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
8 |
|
'listPolicy' => 'blog.posts.list', |
|
26
|
6 |
|
'showPolicy' => 'blog.posts.show', |
|
27
|
6 |
|
'createPolicy' => 'blog.posts.create', |
|
28
|
6 |
|
'updatePolicy' => 'blog.posts.update', |
|
29
|
6 |
|
'deletePolicy' => 'blog.posts.delete', |
|
30
|
6 |
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
34
|
|
|
| Policies Functions |
|
35
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
36
|
|
|
*/ |
|
37
|
|
|
/** |
|
38
|
|
|
* Allow to list all the posts. |
|
39
|
|
|
* |
|
40
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\User $user |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
public function listPolicy(User $user) |
|
45
|
|
|
{ |
|
46
|
|
|
return $user->may('blog.posts.list'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Allow to show a post details. |
|
51
|
|
|
* |
|
52
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\User $user |
|
53
|
|
|
* |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function showPolicy(User $user) |
|
57
|
|
|
{ |
|
58
|
|
|
return $user->may('blog.posts.show'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Allow to create a post. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\User $user |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public function createPolicy(User $user) |
|
69
|
|
|
{ |
|
70
|
|
|
return $user->may('blog.posts.create'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Allow to update a post. |
|
75
|
|
|
* |
|
76
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\User $user |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
|
|
public function updatePolicy(User $user) |
|
81
|
|
|
{ |
|
82
|
|
|
return $user->may('blog.posts.update'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Allow to delete a post. |
|
87
|
|
|
* |
|
88
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\User $user |
|
89
|
|
|
* |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
public function deletePolicy(User $user) |
|
93
|
|
|
{ |
|
94
|
|
|
return $user->may('blog.posts.delete'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|