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

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

Merged
merged 2 commits into from Feb 28, 2019

Conversation

Projects
None yet
3 participants
@erikgaal
Copy link
Contributor

erikgaal commented Feb 28, 2019

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

This comment has been minimized.

Copy link
Contributor Author

erikgaal commented Feb 28, 2019

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@erikgaal erikgaal deleted the erikgaal:5.8-gate-for-user-policy-guesser branch Feb 28, 2019

@TBlindaruk

This comment has been minimized.

Copy link
Member

TBlindaruk commented Mar 3, 2019

@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
You can’t perform that action at this time.