PermissionManager icon indicating copy to clipboard operation
PermissionManager copied to clipboard

Add support for Teams to PermissionManager

Open AkikiCharbel opened this issue 3 years ago • 12 comments

Can't find teams part to work with it

What I did:

created a team crud but forgot that team id will be user in model has permissions and model has roles

I expected when using setPermissionsTeamId(teamId) (spatie function) in my api to get all the permission of the user inside this team but as i can't access model has permission and set my team id so what's happening is that the logged in user have no permission in the team even that he was assigned to the team

i tried to create a crud for users that belongs to a team but it will be a long process to assign a permission to a user inside a team, any idea that can help or any team section in permissionManager that I don't know about it?

I'm using laravel 8 and 9, with backpack 4 and 5

AkikiCharbel avatar Sep 01 '22 09:09 AkikiCharbel

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication mediums:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

welcome[bot] avatar Sep 01 '22 09:09 welcome[bot]

Hmmm... I didn't even know Spatie added Teams to this package, thanks @AkikiCharbel .

https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions#breadcrumb

We'll should add teams support, I agree. For now though, please roll your own solution. You should be able to use your own models, which extend the ones in this package - that will give you full control.

tabacitu avatar Oct 03 '22 06:10 tabacitu

@tabacitu hello, I didn't use spatie permission as it is because spatie doesn't let a user have the same roles or permissions in different teams, so I made some changes in the spatie package, but I will check again to see if I can help with it. cheers :raised_hands:

AkikiCharbel avatar Oct 03 '22 06:10 AkikiCharbel

It would be nice to have that feature. I'm just implementing on existing backpack project a multi company feature and It's part of the roadmap to have permissions set for each company.

miquelangeld avatar Oct 23 '22 14:10 miquelangeld

Same here; planning to build a multi-tenant/team based app and using Backpack for most of the features. Having Spatie permissions support would be great!

@AkikiCharbel would be interested to see what changes you’ve implemented. I was’t aware of this limitation with the Spatie package…

malle-pietje avatar Oct 23 '22 17:10 malle-pietje

Totally agree we should do this. Thanks for the idea and feedback, guys! I've tagged so we do it in March 2023. Until then the team is super-busy working on Backpack v6 😱

tabacitu avatar Dec 13 '22 11:12 tabacitu

we do it in March 2023

Amazing

parallels999 avatar Mar 08 '23 20:03 parallels999

I just ran into the same issue, is there any update on this?

zachweix avatar Aug 17 '23 17:08 zachweix

I added this to my setup in UserCrudController and got it to work:

    $this->crud->setOperationSetting('strippedRequest', function($request) {
        $req = $request->only($this->crud->getAllFieldNames());

        if (\Spatie\Permission\PermissionRegistrar::$teams) {
            if ($req['roles'] && is_array($req['roles'])) {
                $roles = [];
                foreach ($req['roles'] as $role) {
                    $roles[] = [\Spatie\Permission\PermissionRegistrar::$teamsKey => getPermissionsTeamId(),'roles'=>$role];
                }
                $req['roles'] = $roles;
            }

            if ($req['permissions'] && is_array($req['permissions'])) {
                $permissions = [];
                foreach ($req['permissions'] as $permission) {
                    $permissions[] = [\Spatie\Permission\PermissionRegistrar::$teamsKey => getPermissionsTeamId(),'permissions'=>$permission];
                }
                $req['permissions'] = $permissions;
            }
        }

        return $req;
    });

zachweix avatar Aug 17 '23 17:08 zachweix

any news on this update?

alin09ro avatar Nov 16 '23 19:11 alin09ro

Has anyone successfully integrated team support into Laravel-Backpack PermissionManager, akin to the functionalities seen in Spatie's permissions package? If you have navigated this challenge, could you kindly share your approach or provide a guide on your implementation process? Furthermore, is there an anticipated update to the package that will incorporate native team support?

simke92 avatar Mar 11 '24 12:03 simke92

The message I sent back in August is what I did, and it works for me. Just put it directly into your setup() function in the UserCrudController

zachweix avatar Mar 11 '24 12:03 zachweix

Thank you for fast response. One thing i dont like about this approach is warning message "Expected parameter of type 'bool', '\Closure' provided ", but i found similar example in backpack documentation that gives same warning, but a good thing is that its actually works fine.

public function setupUpdateOperation()
{
    CRUD::setOperationSetting('strippedRequest', function ($request) {
        // keep the recommended Backpack stripping (remove anything that doesn't have a field)
        // but add 'updated_by' too
        $input = $request->only(CRUD::getAllFieldNames());
        $input['updated_by'] = backpack_user()->id;
        return $input;
    });
}

Thank you for this quick solution.

Still hopes that this amazing backpack team will find time and resources to provide us full implementation solution as a guide or package upgrade.

simke92 avatar Mar 11 '24 15:03 simke92