Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Teams to PermissionManager #310

Open
AkikiCharbel opened this issue Sep 1, 2022 · 13 comments
Open

Add support for Teams to PermissionManager #310

AkikiCharbel opened this issue Sep 1, 2022 · 13 comments

Comments

@AkikiCharbel
Copy link

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
Copy link

welcome bot commented Sep 1, 2022

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

@tabacitu
Copy link
Member

tabacitu commented Oct 3, 2022

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 tabacitu changed the title When using teams in spatie Add support for Teams to PermissionManager Oct 3, 2022
@tabacitu tabacitu removed this from This week Oct 3, 2022
@tabacitu tabacitu moved this to Todo in Backpack v5.4+ Oct 3, 2022
@AkikiCharbel
Copy link
Author

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

@miquelangeld
Copy link

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
Copy link

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
Copy link
Member

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
Copy link

we do it in March 2023

Amazing

@zachweix
Copy link

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

@zachweix
Copy link

zachweix commented Aug 17, 2023

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
Copy link

any news on this update?

@simke92
Copy link

simke92 commented Mar 11, 2024

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
Copy link

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
Copy link

simke92 commented Mar 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

8 participants