@@ -114,20 +114,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
114
114
115
115
116
116
/**
117
- * Check user permissions
117
+ * Internally check the user permission for the given section
118
118
*
119
- * Parses the user and group permission masks to see if the user
120
- * is authorized to do the thing
121
- *
122
- * @author A. Gianotto <[email protected] >
123
- * @since [v1.0]
124
119
* @return boolean
125
120
*/
126
- public function hasAccess ($ section )
121
+ protected function checkPermissionSection ($ section )
127
122
{
128
- if ($ this ->isSuperUser ()) {
129
- return true ;
130
- }
131
123
$ user_groups = $ this ->groups ;
132
124
133
125
@@ -159,31 +151,33 @@ public function hasAccess($section)
159
151
}
160
152
161
153
/**
162
- * Checks if the user is a SuperUser
154
+ * Check user permissions
155
+ *
156
+ * Parses the user and group permission masks to see if the user
157
+ * is authorized to do the thing
163
158
*
164
159
* @author A. Gianotto <[email protected] >
165
160
* @since [v1.0]
166
161
* @return boolean
167
162
*/
168
- public function isSuperUser ( )
163
+ public function hasAccess ( $ section )
169
164
{
170
- if (!$ user_permissions = json_decode ($ this ->permissions , true )) {
171
- return false ;
172
- }
173
-
174
- foreach ($ this ->groups as $ user_group ) {
175
- $ group_permissions = json_decode ($ user_group ->permissions , true );
176
- $ group_array = (array )$ group_permissions ;
177
- if ((array_key_exists ('superuser ' , $ group_array )) && ($ group_permissions ['superuser ' ]=='1 ' )) {
178
- return true ;
179
- }
180
- }
181
-
182
- if ((array_key_exists ('superuser ' , $ user_permissions )) && ($ user_permissions ['superuser ' ]=='1 ' )) {
165
+ if ($ this ->isSuperUser ()) {
183
166
return true ;
184
167
}
168
+ return $ this ->checkPermissionSection ($ section );
169
+ }
185
170
186
- return false ;
171
+ /**
172
+ * Checks if the user is a SuperUser
173
+ *
174
+ * @author A. Gianotto <[email protected] >
175
+ * @since [v1.0]
176
+ * @return boolean
177
+ */
178
+ public function isSuperUser ()
179
+ {
180
+ return $ this ->checkPermissionSection ('superuser ' );
187
181
}
188
182
189
183
0 commit comments