Updates to permissions decoding

This commit is contained in:
snipe 2016-06-02 02:49:32 -07:00
parent dce549cc5c
commit 97691726f0

View file

@ -42,30 +42,33 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
// This is very coarse and should be changed
public function hasAccess($section)
{
if ($this->isSuperUser()) {
return true;
}
$permitted = false;
$user_groups = $this->groups;
if ($this->permissions=='') {
if (($this->permissions=='') && (count($user_groups) == 0)) {
return false;
}
$user_permissions = json_decode($this->permissions, true);
$user_groups = $this->groups();
if (((array_key_exists($section, $user_permissions)) && ($user_permissions[$section]=='1')) ||
((array_key_exists('admin', $user_permissions)) && ($user_permissions['admin']=='1'))) {
return true;
$user_permissions = json_decode($this->permissions, true);
if ((array_key_exists($section, $user_permissions)) && ($user_permissions[$section]=='1')) {
$permitted = true;
}
foreach ($user_groups as $user_group) {
$group_permissions = json_decode($user_group->permissions, true);
if (((array_key_exists($section, $group_permissions)) && ($group_permissions[$section]=='1')) ||
((array_key_exists('admin', $group_permissions)) && ($group_permissions['admin']=='1'))) {
return true;
if (((array_key_exists($section, $group_permissions)) && ($group_permissions[$section]=='1'))) {
$permitted = true;
}
}
return false;
return $permitted;
}
public function isSuperUser() {
@ -73,25 +76,22 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
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_array[] = $group_permissions;
$group_array = $group_permissions;
if ((array_key_exists('superuser', $group_array)) && ($group_permissions['superuser']=='1')) {
return true;
}
}
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 false;
}
}
public function company()
{
return $this->belongsTo('\App\Models\Company', 'company_id');
@ -212,7 +212,13 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
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');
}