You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue where I'm calling has_permission(int) in my application in several places. If the user does not have the permission then the database gets called every time I call has_permission(int);
In Myth\Auth\Authorization\PermissionModel:doesUserHavePermission()
$this->getPermissionsForUser($userId) gets permissions for user - both group permissions and individual permissions. If the requested permission is found in all of the users permissions then return true.
It would seem logical that if the requested permission is not found in this manner then the user does not have the permission and then return false.
However for some reason the code continues and looks up group permissions for the user once again. This seems redundant unless I'm missing something. If the user doesn't have the permission requested then it will continually lookup in the database.
It seems to me that the entire method doesUserHavePermission() should look like this:
/** * Checks to see if a user, or one of their groups, * has a specific permission. * * @param int $userId * @param int $permissionId * * @return bool */publicfunctiondoesUserHavePermission(int$userId, int$permissionId): bool
{
// Check user permissions and take advantage of caching$userPerms = $this->getPermissionsForUser($userId);
if (count($userPerms) && array_key_exists($permissionId, $userPerms))
{
returntrue;
}
returnfalse;
}
Am I right or am I missing something?
The text was updated successfully, but these errors were encountered:
It's a little hard for me to look at all the code on mobile but if I understand what you are saying then: yes, you are correct that this is erroneously loading group permissions twice. Feel free to send over a PR with your change!
I have an issue where I'm calling has_permission(int) in my application in several places. If the user does not have the permission then the database gets called every time I call has_permission(int);
In Myth\Auth\Authorization\PermissionModel:doesUserHavePermission()
$this->getPermissionsForUser($userId) gets permissions for user - both group permissions and individual permissions. If the requested permission is found in all of the users permissions then return true.
For reference:
It would seem logical that if the requested permission is not found in this manner then the user does not have the permission and then return false.
However for some reason the code continues and looks up group permissions for the user once again. This seems redundant unless I'm missing something. If the user doesn't have the permission requested then it will continually lookup in the database.
It seems to me that the entire method doesUserHavePermission() should look like this:
Am I right or am I missing something?
The text was updated successfully, but these errors were encountered: