spatie/laravel-permission

Unable to see roles of all system users as a global super admin on a team

sts-ryan-holton opened this issue ยท 8 comments

Describe the bug

I'm using the teams feature of this package. In my context it's a company so I'll refer to it as that throughout. I have a Company model and a User can only ever have one company, then, a Company can have as many roles as is needed.

I have a global Super admin that isn't assigned to any company.

As a super admin, when I log in and go to my user management page I need to be able to see the roles assigned to each user, not just the roles for me who I'm logged in as.

I believe this is related to the setPermissionsTeamId function which can only ever hold one company id, but as a super admin I need to be able to see everyone's.

Versions

  • spatie/laravel-permission package version: 5.7.0
  • illuminate/framework package 9.47.0

PHP version: 8.1.0

Database version: MySQL

Additional context

Here's how I'm getting a list of users:

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index(Request $request)
{
    $this->authorize('viewAny', User::class);

    $validator = Validator::make($request->all(), [
        'perPage' => [
            'numeric',
            new ValidPaginationPerPage
        ]
    ]);

    if ($validator->fails()) {
        return response()->json([
            'message' => 'One or more fields has been missed or is invalid.',
            'errors' => $validator->messages(),
        ], 400);
    }

    $users = User::with('roles')->paginate($request->input('perPage', 10));
    $users->onEachSide(1);

    if (!$users || count($users) <= 0) {
        return response()->json([
            'message' => 'No users found'
        ], 404);
    }

    return response()->json([
        'users' => $users
    ], 200);
}

Here's what my users view looks like whilst logged in as a super admin:

list-roles

And here's my table of roles:

table-roles

To summarise, a super admin should be able to see all roles of all users regardless of company.

It is not a bug or issue, it is a expected behaivor
Read other issues/discussions/pull requests about this
Also use discussions section stop opening new issues every time

I've seen you post several issues which are support questions. Please keep in mind the issue templates when submitting issues.

laravel/fortify#380 (comment)

I see you do the same everywhere and you don't understand it

@parallels999

It is not a bug or issue, it is a expected behaivor

This isn't an acceptable answer given the number of issues related to the Teams feature.

Having a Teams feature implies that I can have more than one team, and as such I should be able to see other teams/companies regardless of who I'm logged in as if my role is a global super admin.

Linking to Fortify isn't related at all to this package.

Please investigate further.

It is still expected behavior.

Having a Teams feature implies that I can have more than one team, and as such I should be able to see other teams/companies regardless of who I'm logged in as if my role is a global super admin.

if you read other issues/discussions/pull requests about this you would know how to do it, I will no longer perform the searches for you, never even a "thank you" you return

This isn't an acceptable answer given the number of issues related to the Teams feature.

Feel free to make a pull request to make it better

If my described issue has already been discussed, please link me to it - this would be helpful.

I will no longer perform the searches for you, never even a "thank you" you return

There you can search, or you can wait for someone else to do the searching for you, and don't forget to thank whoever does it, this is not a paid job, those who help use their personal time to do it,
https://github.com/spatie/laravel-permission/issues?q=
image
have a good day

Easy, already discussed

drbyte commented

Scoping as per the examples erikn69 linked to should resolve your situation.