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

Roles Nested Groups #202

Open
mybigman opened this issue Feb 14, 2017 · 3 comments
Open

Roles Nested Groups #202

mybigman opened this issue Feb 14, 2017 · 3 comments

Comments

@mybigman
Copy link

Hi,

Having an issue with route group protection on nested groups.

Route::group([
        'prefix' => 'application/fast',
        'middleware' => ['web', 'auth', 'acl'],
        'is' => 'god|fast.admin|fast.user',
        'namespace' => 'Modules\Fast\Http\Controllers',
        'as' => "fast."
    ],
    function () {

        ### ADMIN ###
        Route::group([
                'prefix' => 'admin',
                'middleware' => ['logger'],
                'is' => 'god|fast.admin', // <--- ISSUE HERE
                'namespace' => 'Admin',
                'as' => "admin."
            ],

If I remove "|fast.admin" from the ADMIN group I can access the admin page but with it there its permission denied. It doesn't matter what additional roles I add it's still permission denied.

Expected result is all three user roles can access the frontend but ONLY the two roles should access the backend.

Here's a dump of the router with "|fast.admin" removed.

Route {#264 ▼
  #uri: "application/fast/admin"
  #methods: array:2 [▶]
  #action: array:8 [▼
    "middleware" => array:4 [▼
      0 => "web"
      1 => "auth"
      2 => "acl"
      3 => "logger"
    ]
    "is" => array:2 [▼
      0 => "god|fast.admin|fast.user"
      1 => "god"
    ]
    "uses" => "Modules\Fast\Http\Controllers\Admin\HomeController@index"
    "controller" => "Modules\Fast\Http\Controllers\Admin\HomeController@index"
    "namespace" => "Modules\Fast\Http\Controllers\Admin"
    "prefix" => "application/fast/admin"
    "where" => []
    "as" => "fast.admin.index"
  ]

Bug or user error :)

Thanks.

@mybigman
Copy link
Author

mybigman commented Feb 14, 2017

After some digging appears to be a bug.

"is" appears it needs to be a string in which the second "is" group needs to overwrite the first since it returns both route groups.

Thanks

@mybigman
Copy link
Author

mybigman commented Feb 14, 2017

As a workaround I have done the following if anyone else needs until there's an official release.

Middleware\HasPermission.php - Line 172

from

    /**
     * Extract required action from requested route.
     *
     * @param string $key action name
     * @return string
     */
    protected function getAction($key)
    {
        $action = $this->request->route()->getAction();

        return isset($action[$key]) ? $action[$key] : false;
    }

to

    /**
     * Extract required action from requested route.
     *
     * @param string $key action name
     * @return string
     */
    protected function getAction($key)
    {
        $action = $this->request->route()->getAction();

        if (! isset($action[$key])) {
            return false;
        }

        $roles = (array) $action[$key];

        return end($roles);
    }

@kodeine
Copy link
Owner

kodeine commented Feb 28, 2017

@mybigman can you please post a PR for the fix? Thanks

also, wouldnt this work?

return isset($action[$key]) ? end($action[$key]) : false;

Also, i dont recall if $action[$key] is suppose to be an array. I have to go through the code again.

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

No branches or pull requests

2 participants