Skip to content

Commit

Permalink
change split roles logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aslubsky committed Nov 25, 2013
1 parent 12b5236 commit 29a3038
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
7 changes: 4 additions & 3 deletions server/Bazalt/Auth/Model/Guest.php
Expand Up @@ -89,9 +89,10 @@ public function hasPermission()

public function toArray()
{
$ret['roles'] = [];
$ret['acl'] = [];
$arr = (array)$this;
$arr['roles'] = [];
$arr['acl'] = [];

return $this;
return $arr;
}
}
6 changes: 3 additions & 3 deletions server/Bazalt/Auth/Model/Role.php
Expand Up @@ -32,10 +32,10 @@ public static function getGuestRoles()
return $q->fetchAll();
}

public function getByName($name)
public static function getByName($name)
{
$q = ORM::select('Role r')
->where('name = ?', $name);
$q = ORM::select('Bazalt\\Auth\\Model\\Role r')
->where('title = ?', $name);

return $q->fetch();
}
Expand Down
31 changes: 13 additions & 18 deletions server/Bazalt/Auth/Model/User.php
Expand Up @@ -95,23 +95,12 @@ public function hasRole($roleId, $site = null)
public function getRoles($site = null)
{
$site = ($site) ? $site : \Bazalt\Site::get();
$splitRoles = \Bazalt\Site\Option::get(\Bazalt\Auth::SPLIT_ROLES_OPTION, true);

if($splitRoles) {
$q = ORM::select('Bazalt\\Auth\\Model\\Role r', 'r.*')
->innerJoin('Bazalt\\Auth\\Model\\RoleRefUser ru', ['role_id', 'r.id'])
->where('(r.site_id IS NULL OR r.site_id = ?)', $site->id)
->andWhere('ru.user_id = ?', $this->id)
->andWhere('ru.site_id = ?', $site->id);
return $q->fetchAll();
} else {
$roles = Role::getGuestRoles();
$currentRole = \Bazalt\Auth::getCurrentRole();
if($currentRole) {
$roles []= $currentRole;
}
return $roles;
}
$q = ORM::select('Bazalt\\Auth\\Model\\Role r', 'r.*')
->innerJoin('Bazalt\\Auth\\Model\\RoleRefUser ru', ['role_id', 'r.id'])
->where('(r.site_id IS NULL OR r.site_id = ?)', $site->id)
->andWhere('ru.user_id = ?', $this->id)
->andWhere('ru.site_id = ?', $site->id);
return $q->fetchAll();
}

/**
Expand Down Expand Up @@ -278,7 +267,13 @@ public function getPermissions($site = null)
$ret []= $perm->id;
}
} else {
$roles = $this->getRoles($site);
$roles = Role::getGuestRoles();
$currentRole = \Bazalt\Auth::getCurrentRole();
if($currentRole) {
$roles = [
$currentRole
];
}
foreach($roles as $role) {
$res = $role->getPermissions();
foreach ($res as $perm) {
Expand Down

0 comments on commit 29a3038

Please sign in to comment.