Skip to content

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

Open
@aduscher

Description

@aduscher

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']);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions