Skip to content

[5.8] Fix guessed policy names when using Gate::forUser#27708

Merged
taylorotwell merged 2 commits intolaravel:5.8from
erikgaal:5.8-gate-for-user-policy-guesser
Feb 28, 2019
Merged

[5.8] Fix guessed policy names when using Gate::forUser#27708
taylorotwell merged 2 commits intolaravel:5.8from
erikgaal:5.8-gate-for-user-policy-guesser

Conversation

@erikgaal
Copy link
Copy Markdown
Contributor

Overview

When using the Gate facade to create a new instance for a specific user with forUser the guessPolicyNameUsingCallback is not passed on to the new instance. This results in the policies no policies being loaded when using just the policy name guesser.

Reproduction

Gate::guessPolicyNamesUsing(function ($class) {
    return 'foo';
});

dump(app(Gate::class));
// #guessPolicyNamesUsingCallback: Closure($class) {#371

dump(app(Gate::class)->forUser($user));
// #guessPolicyNamesUsingCallback: null

Proposed Solution

Add the guessPolicyNameUsingCallback nullable argument to the constructor and pass it in the forUser method.

@erikgaal
Copy link
Copy Markdown
Contributor Author

This probably needs a test so it won't break again.

@erikgaal erikgaal changed the title [5.8] Make Gate::forUser pass the policy guesser to the constructor [5.8] Fix guessed policy names when using Gate::forUser Feb 28, 2019
@taylorotwell taylorotwell merged commit c56c597 into laravel:5.8 Feb 28, 2019
@erikgaal erikgaal deleted the 5.8-gate-for-user-policy-guesser branch February 28, 2019 13:53
@TBlindaruk
Copy link
Copy Markdown
Contributor

@erikgaal #27757 I have created issue for the test

taylorotwell added a commit that referenced this pull request Mar 4, 2019
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

Successfully merging this pull request may close these issues.

3 participants