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

feat: Add session claims helper methods to check roles and permissions #200

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

mzhong9723
Copy link
Member

Add HasPermission() and HasRole() to session claims

@mzhong9723 mzhong9723 requested a review from a team as a code owner January 10, 2024 21:47
Copy link
Member

@chanioxaris chanioxaris left a comment

Choose a reason for hiding this comment

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

Great work 💯

(We can also use the new helpers in our Dashboard)

// user has permission
hasPermission := dummySessionClaims.HasPermission("org:billing:manage")
assert.True(t, hasPermission)

Copy link
Contributor

Choose a reason for hiding this comment

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

🔧 You could also assert that the helper finds both permissions defined in the claims:

ActiveOrganizationPermissions: []string{"org:billing:manage", "org:report:view"},

This case may provide an additional guarantee that we perform an exhaustive search.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add! Thanks for the suggestion

@mzhong9723 mzhong9723 merged commit 2f041fe into main Jan 11, 2024
1 check passed
@mzhong9723 mzhong9723 deleted the mz/core-1351 branch January 11, 2024 14:16
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.

4 participants