mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Updates to permissions decoding
This commit is contained in:
parent
dce549cc5c
commit
97691726f0
|
@ -42,30 +42,33 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
// This is very coarse and should be changed
|
// This is very coarse and should be changed
|
||||||
public function hasAccess($section)
|
public function hasAccess($section)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->isSuperUser()) {
|
if ($this->isSuperUser()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
$permitted = false;
|
||||||
|
$user_groups = $this->groups;
|
||||||
|
|
||||||
if ($this->permissions=='') {
|
|
||||||
|
if (($this->permissions=='') && (count($user_groups) == 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$user_permissions = json_decode($this->permissions, true);
|
|
||||||
$user_groups = $this->groups();
|
|
||||||
|
|
||||||
if (((array_key_exists($section, $user_permissions)) && ($user_permissions[$section]=='1')) ||
|
$user_permissions = json_decode($this->permissions, true);
|
||||||
((array_key_exists('admin', $user_permissions)) && ($user_permissions['admin']=='1'))) {
|
|
||||||
return true;
|
if ((array_key_exists($section, $user_permissions)) && ($user_permissions[$section]=='1')) {
|
||||||
|
$permitted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($user_groups as $user_group) {
|
foreach ($user_groups as $user_group) {
|
||||||
$group_permissions = json_decode($user_group->permissions, true);
|
$group_permissions = json_decode($user_group->permissions, true);
|
||||||
if (((array_key_exists($section, $group_permissions)) && ($group_permissions[$section]=='1')) ||
|
if (((array_key_exists($section, $group_permissions)) && ($group_permissions[$section]=='1'))) {
|
||||||
((array_key_exists('admin', $group_permissions)) && ($group_permissions['admin']=='1'))) {
|
$permitted = true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
|
return $permitted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSuperUser() {
|
public function isSuperUser() {
|
||||||
|
@ -73,22 +76,19 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$group_array = array();
|
foreach ($this->groups as $user_group) {
|
||||||
foreach ($this->groups() as $user_group) {
|
|
||||||
$group_permissions = json_decode($user_group->permissions, true);
|
$group_permissions = json_decode($user_group->permissions, true);
|
||||||
$group_array[] = $group_permissions;
|
$group_array = $group_permissions;
|
||||||
}
|
if ((array_key_exists('superuser', $group_array)) && ($group_permissions['superuser']=='1')) {
|
||||||
|
|
||||||
if ((array_key_exists('superuser', $user_permissions)) && ($user_permissions['superuser']=='1')) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if ((array_key_exists('superuser', $group_array)) && ($group_array['superuser']=='1')) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
if ((array_key_exists('superuser', $user_permissions)) && ($user_permissions['superuser']=='1')) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,7 +212,13 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||||
*/
|
*/
|
||||||
public function groups()
|
public function groups()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('\App\Models\Group', 'users_groups');
|
static $static_cache = null;
|
||||||
|
|
||||||
|
if (!$static_cache) {
|
||||||
|
$static_cache = $this->belongsToMany('\App\Models\Group', 'users_groups');
|
||||||
|
}
|
||||||
|
return $static_cache;
|
||||||
|
//return $this->belongsToMany('\App\Models\Group', 'users_groups');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue