serenysoft / nova-permissions

Laravel Nova 4 Roles & Permissions
72 stars 27 forks source link

Replicating role does not replicate checked permissions #19

Open sanderbaas opened 1 year ago

sanderbaas commented 1 year ago

I am using version 1.3.1 on Nova 4.22.1.

When replicating a role, none of the permissions are checked.

Rokasl commented 8 months ago

@sanderbaas @leandrogehlen

You can try adding custom resolver to your permissions field:


            Checkboxes::make(__('Permissions'), 'permissions')
                ->options($this->loadPermissions()->map(function ($permission) {
                    return [
                        'group' => $this->translatePermissions(ucfirst($permission->group)),
                        'option' => $permission->name,
                        'label' => $this->translatePermissions($permission->name),
                    ];
                })
                    ->groupBy('group')
                    ->toArray()
                )
                ->resolveUsing(function ($value) use ($request) {
                    if ($request->get('fromResourceId')) {
                        return \Sereny\NovaPermissions\Models\Role::find($request->get('fromResourceId'))->permissions->pluck('name')->toArray();
                    }

                    return $value->pluck('name')->toArray();
                }),
leandrogehlen commented 8 months ago

Thanks for the suggestion.

Can you make a PR to solve this issue?

Please check if is there some more elegant way instead of $request->get('fromResourceId')