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

Fix issue using optional() on a RemoteUser in Laravel 5.6+. #129

Merged
merged 4 commits into from
Jul 20, 2020

Conversation

DFurnes
Copy link
Contributor

@DFurnes DFurnes commented Jul 20, 2020

What's this PR do?

This pull request fixes an issue where checking optional(auth()->user())->role would throw an error in Laravel 5.6.

This started happening because Laravel 5.6's optional helper now checks if the requested field is set using the null-coalescing operator (which, behind the scenes runs an isset() check on that field). Because these fields aren't really set on the RemoteUser class (which is just a convenience wrapper for accessing the token or Northstar user), it'd always be null!

How should this be reviewed?

I extracted a loadAttributes method in 30b6141 so I could use it in this new __isset method, added in f302997.

I also cleaned up a reference to $this->relations from HasAttributes in 97016a7. I think this was mistakenly copy-pasted when I extracted this logic from Laravel's HasAttributes to use here.

Checklist

DFurnes added 3 commits July 20, 2020 12:52
Because we wrap checks for the `role` attribute in an `optional()` in Rogue, we need to support this object's unique field behavior.
@DFurnes DFurnes requested a review from weerd July 20, 2020 17:02
Comment on lines +52 to +54
if (in_array($key, ['id', 'northstar_id', 'role'])) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Contributor

@weerd weerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Top-notch 🕵️‍♂️-ing work! 👍

@DFurnes DFurnes merged commit 0ae0f82 into master Jul 20, 2020
@DFurnes DFurnes deleted the remote-user-isset branch July 20, 2020 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants