framework icon indicating copy to clipboard operation
framework copied to clipboard

Merging of role and user permissions does not work without permission id

Open aduscher opened this issue 7 years ago • 0 comments

When using both role permissions & user permissions the following problem occurs:

The Eloquent statement in Litepie\Roles\Traits\HasRoleAndPermission::rolePermissions() does not include the permission id. So when the merge of the two permissions sets is done in function getPermissions(), the role permissions are ignored because no key attribute is available in the hydrated Permission object.

In class Litepie\Roles\Traits\HasRoleAndPermission the function rolePermissions() can be updated accordingly to fix the issue:

public function rolePermissions()
{
   ...
return $permissionModel::select(['permissions.id', 'permissions.slug', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
					->join('permission_role', 'permission_role.permission_id', '=', 'permissions.id')
					->join('roles', 'roles.id', '=', 'permission_role.role_id')
					->whereIn('roles.id', $this->getRoles()->pluck('id')->toArray())
					->orWhere('roles.level', '<', $this->level())
					->groupBy(['permissions.id', 'permissions.slug', 'pivot_created_at', 'pivot_updated_at']);
}

aduscher avatar Jun 20 '18 14:06 aduscher