Skip to content

Commit

Permalink
no has permission
Browse files Browse the repository at this point in the history
  • Loading branch information
regisoc committed Feb 15, 2024
1 parent 002be26 commit f4c5186
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
1 change: 0 additions & 1 deletion php/libraries/Role.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ class Role implements \LORIS\StudyEntities\AccessibleResource
*/
public function hasPermission(string $code): bool
{
$this->setPermissions();
if (!array_key_exists($code, $this->permissions)) {
return false;
}
Expand Down
86 changes: 43 additions & 43 deletions php/libraries/User.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -606,47 +606,47 @@ class User extends UserPermissions implements
return $this->userInfo['Pending_approval'] == 'Y';
}

/**
* Determines if the user has the permission to access a specific module
* or page. Override the hasPermission from UserPermission with Role access.
*
* @param string $code The permission code
*
* @return bool If the user has a permission.
*/
public function hasPermission(string $code): bool
{
if (parent::hasPermission($code) === true) {
return true;
}
// user does not have permission, check roles.
foreach ($this->getRoles() as $roleValues) {
$role = \Role::factory($roleValues['Code']);
if (!is_null($role) && $role->hasPermission($code) === true) {
return true;
}
}
return false;
}

/**
* Get the roles this user has access to.
*
* @return array an array with role values.
*/
public function getRoles(): array
{
$db = \NDB_Factory::singleton()->database();
return $db->pselect(
"SELECT
r.RoleID,
r.Code,
r.Name,
r.Description
FROM user_role_rel urr
JOIN roles r ON (urr.RoleID = r.RoleID)
WHERE urr.userID = :userid",
['userid' => $this->getId()]
);
}
// /**
// * Determines if the user has the permission to access a specific module
// * or page. Override the hasPermission from UserPermission with Role access.
// *
// * @param string $code The permission code
// *
// * @return bool If the user has a permission.
// */
// public function hasPermission(string $code): bool
// {
// if (parent::hasPermission($code) === true) {
// return true;
// }
// // user does not have permission, check roles.
// foreach ($this->getRoles() as $roleValues) {
// $role = \Role::factory($roleValues['Code']);
// if (!is_null($role) && $role->hasPermission($code) === true) {
// return true;
// }
// }
// return false;
// }

// /**
// * Get the roles this user has access to.
// *
// * @return array an array with role values.
// */
// public function getRoles(): array
// {
// $db = \NDB_Factory::singleton()->database();
// return $db->pselect(
// "SELECT
// r.RoleID,
// r.Code,
// r.Name,
// r.Description
// FROM user_role_rel urr
// JOIN roles r ON (urr.RoleID = r.RoleID)
// WHERE urr.userID = :userid",
// ['userid' => $this->getId()]
// );
// }
}

0 comments on commit f4c5186

Please sign in to comment.