Laravel-Backpack / PermissionManager

Admin interface for managing users, roles, permissions, using Backpack CRUD
http://backpackforlaravel.com
Other
516 stars 166 forks source link

Add support for Teams to PermissionManager #310

Open AkikiCharbel opened 2 years ago

AkikiCharbel commented 2 years ago

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

welcome[bot] commented 2 years ago

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:

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

tabacitu commented 1 year ago

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.

AkikiCharbel commented 1 year ago

@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:

miquelangeld commented 1 year ago

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.

malle-pietje commented 1 year ago

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…

tabacitu commented 1 year ago

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 😱

parallels999 commented 1 year ago

we do it in March 2023

Amazing

zachweix commented 1 year ago

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

zachweix commented 1 year ago

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;
    });
alin09ro commented 10 months ago

any news on this update?

simke92 commented 6 months ago

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?

zachweix commented 6 months ago

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

simke92 commented 6 months ago

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.