[4.x] Fix: GateWatcher shows allowed when it is denied via Response class #1010
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Error that happens
While returning and using the
Illuminate\Auth\Access\Response
class deny and allow methods from policies, I noticed that telescope is recording the Gate results as always allowedI determined that the
$result
argument that theGateWatcher
class is looking at it as only a bool, but this value also has the possibility of being an instance ofIlluminate\Auth\Access\Response
in the case of a policy that is returning a response, so when the policy has$this->denied('Reason for denial')
the request entry reflects a status code of 403, but it is confusing to see the gate value is allowed.As the intention of Telescope is to assist in debugging and seeing whats happening, this actually causes confusion in the long run.
Fix
The changes I made was to look if the
$result
argument is an instance of theIlluminate\Auth\Access\Response
class, if not it defaults to the original behaviour.Tests
The tests all passed locally, but will only know once the repo's ones run if they are correct.
The tests have a few changes for the Gate Watcher, but these are the line numbers and the additions I made. I am not sure if I was supposed to change the line numbers, but they shifted because of my additions I believe.