laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

HasPermission middleware

Open IlyaSavich opened this issue 9 years ago • 3 comments

Can you help me? I'm debugging around 2 hour your middleware, don't understanding why you provide an opportunity to override in config

'crud' => [
    'restful' => [
        //methods
    ],
    'resource' => [
        //methods
    ],
],

but don't provide to override

'crud' => [
    'resources' => [
        // controller actions
    ],
],

I have a situation, when sending ajax request and the package don't permits me do this, Says "You are not authorized to access this resource.". I'm trying to add to route group 'protect_methods' => ['view' => ['index', 'show', 'filter']] , where filter is method that I need, but the result still the same. Maybe I'm don't understanding can you help me ? I tried to override this middleware.

// my HasPermission middleware
protected function crudConfigOverride()
    {
        // Override crud restful from config.
        if (($restful = config('acl.crud.restful')) != null) {
            $this->crud['restful'] = $restful;
        }

        // Override crud resource from config.
        if (($resource = config('acl.crud.resource')) != null) {
            $this->crud['resource'] = $resource;
        }

        if (($resources = config('acl.crud.resources')) != null) {
            $this->crud['resources'] = $resources;
        }
    }

// in config
'crud' => [
        'resource' => [
            'create' => ['create', 'store'],
            'store' => ['create', 'store'],
            'read' => ['index', 'show'],
            'view' => ['index', 'show', 'filter'],
            'edit' => ['edit', 'update'],
            'update' => ['edit', 'update'],
            'delete' => ['destroy'],
        ],
        'resources' => [
            'index',
            'create',
            'store',
            'show',
            'edit',
            'update',
            'destroy',
            'filter',
        ],
    ],

All works right now. Maybe there any another solution ?

IlyaSavich avatar Nov 30 '16 13:11 IlyaSavich

@IlyaSavich please refer to this wiki page

kodeine avatar Dec 08 '16 00:12 kodeine

The main problem is that when the method that I defined was not found in crud => ['resources'] then HasPermission seeks through restful, but I don't need that. I tried all the options from the wiki, but the result remained the same

IlyaSavich avatar Dec 09 '16 07:12 IlyaSavich

@kodeine, even using the protect_methods I still have 401. any updates?

amandiobm avatar Aug 09 '18 06:08 amandiobm