1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Zahir Hayrullah |
4
|
|
|
* create date : 10/04/2020 07:00 AM |
5
|
|
|
* Last Modified Date: 10/04/2020 07:00 AM. |
6
|
|
|
*/ |
7
|
|
|
if (!function_exists('available_permission_middleware')) { |
8
|
|
|
/** |
9
|
|
|
* @return array |
10
|
|
|
*/ |
11
|
|
|
function available_permission_middleware() |
12
|
|
|
{ |
13
|
|
|
return [ |
14
|
|
|
'web', |
15
|
|
|
'admin', |
16
|
|
|
'api', |
17
|
|
|
]; |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
21
|
|
|
|
22
|
|
|
if (!function_exists('check_user_authorize')) { |
23
|
|
|
/** |
24
|
|
|
* @param $permissionName |
25
|
|
|
* @param $trash |
26
|
|
|
* |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
function check_user_authorize($permissionName = null, $trash = null) |
30
|
|
|
{ |
31
|
|
|
if ($trash and !is_can_restore($permissionName) and !is_can_force_delete($permissionName)) { |
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
if (!is_can_show($permissionName) and !is_can_show_all($permissionName)) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
42
|
|
|
|
43
|
|
|
if (!function_exists('is_can_create')) { |
44
|
|
|
/** |
45
|
|
|
* @param $permissionName |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
function is_can_create($permissionName = null) |
50
|
|
|
{ |
51
|
|
|
return $permissionName ? is_can("create-{$permissionName}") : true; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
55
|
|
|
|
56
|
|
|
if (!function_exists('is_can_edit')) { |
57
|
|
|
/** |
58
|
|
|
* @param $permissionName |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
function is_can_edit($permissionName = null) |
63
|
|
|
{ |
64
|
|
|
return $permissionName ? is_can("edit-{$permissionName}") : true; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
68
|
|
|
|
69
|
|
|
if (!function_exists('is_can_delete')) { |
70
|
|
|
/** |
71
|
|
|
* @param $permissionName |
72
|
|
|
* |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
function is_can_delete($permissionName = null) |
76
|
|
|
{ |
77
|
|
|
return $permissionName ? is_can("delete-{$permissionName}") : true; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
81
|
|
|
|
82
|
|
|
if (!function_exists('is_can_restore')) { |
83
|
|
|
/** |
84
|
|
|
* @param $permissionName |
85
|
|
|
* |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
function is_can_restore($permissionName = null) |
89
|
|
|
{ |
90
|
|
|
return $permissionName ? is_can("restore-{$permissionName}") : true; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
94
|
|
|
|
95
|
|
|
if (!function_exists('is_can_force_delete')) { |
96
|
|
|
/** |
97
|
|
|
* @param $permissionName |
98
|
|
|
* |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
function is_can_force_delete($permissionName = null) |
102
|
|
|
{ |
103
|
|
|
return $permissionName ? is_can("force-delete-{$permissionName}") : true; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
107
|
|
|
|
108
|
|
|
if (!function_exists('is_can_show')) { |
109
|
|
|
/** |
110
|
|
|
* @param $permissionName |
111
|
|
|
* |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
function is_can_show($permissionName = null) |
115
|
|
|
{ |
116
|
|
|
return $permissionName ? is_can("show-{$permissionName}") : true; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
120
|
|
|
|
121
|
|
|
if (!function_exists('is_can_show_all')) { |
122
|
|
|
/** |
123
|
|
|
* @param $permissionName |
124
|
|
|
* |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
|
|
function is_can_show_all($permissionName = null) |
128
|
|
|
{ |
129
|
|
|
return $permissionName ? is_can("show-all-{$permissionName}") : true; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
133
|
|
|
|
134
|
|
|
if (!function_exists('is_can_activate')) { |
135
|
|
|
/** |
136
|
|
|
* @param $permissionName |
137
|
|
|
* |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
|
|
function is_can_activate($permissionName = null) |
141
|
|
|
{ |
142
|
|
|
return $permissionName ? is_can("activate-$permissionName") : true; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
146
|
|
|
|
147
|
|
|
if (!function_exists('is_can')) { |
148
|
|
|
/** |
149
|
|
|
* @param $permissionName |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
|
|
function is_can($permissionName = null) |
154
|
|
|
{ |
155
|
|
|
// $last = substr($permissionName, -1); |
156
|
|
|
// if ($last == '-') { |
157
|
|
|
// return true; |
158
|
|
|
// } |
159
|
|
|
$user = get_auth_user(); |
160
|
|
|
if ($user and $user->can($permissionName)) { |
161
|
|
|
return true; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return false; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
/*---------------------------------- </> ----------------------------------*/ |
168
|
|
|
|