Skip to content

Commit f01c93e

Browse files
authored
Extend #6229 to include superuser permission check (#6772)
1 parent 26b97d2 commit f01c93e

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

app/Models/User.php

+20-26
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
114114

115115

116116
/**
117-
* Check user permissions
117+
* Internally check the user permission for the given section
118118
*
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]
124119
* @return boolean
125120
*/
126-
public function hasAccess($section)
121+
protected function checkPermissionSection($section)
127122
{
128-
if ($this->isSuperUser()) {
129-
return true;
130-
}
131123
$user_groups = $this->groups;
132124

133125

@@ -159,31 +151,33 @@ public function hasAccess($section)
159151
}
160152

161153
/**
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
163158
*
164159
* @author A. Gianotto <[email protected]>
165160
* @since [v1.0]
166161
* @return boolean
167162
*/
168-
public function isSuperUser()
163+
public function hasAccess($section)
169164
{
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()) {
183166
return true;
184167
}
168+
return $this->checkPermissionSection($section);
169+
}
185170

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');
187181
}
188182

189183

0 commit comments

Comments
 (0)