-
Notifications
You must be signed in to change notification settings - Fork 887
feat: push GetUsers authorization filter to SQL #8497
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Emyrk
commented
Jul 13, 2023
Emyrk
commented
Jul 13, 2023
Comment on lines
-5392
to
-5436
users = append(users, user) | ||
} | ||
|
||
// Filter out deleted since they should never be returned.. | ||
tmp := make([]database.User, 0, len(users)) | ||
for _, user := range users { | ||
if !user.Deleted { | ||
tmp = append(tmp, user) | ||
} | ||
} | ||
users = tmp | ||
|
||
if params.Search != "" { | ||
tmp := make([]database.User, 0, len(users)) | ||
for i, user := range users { | ||
if strings.Contains(strings.ToLower(user.Email), strings.ToLower(params.Search)) { | ||
tmp = append(tmp, users[i]) | ||
} else if strings.Contains(strings.ToLower(user.Username), strings.ToLower(params.Search)) { | ||
tmp = append(tmp, users[i]) | ||
} | ||
} | ||
users = tmp | ||
} | ||
|
||
if len(params.Status) > 0 { | ||
usersFilteredByStatus := make([]database.User, 0, len(users)) | ||
for i, user := range users { | ||
if slice.ContainsCompare(params.Status, user.Status, func(a, b database.UserStatus) bool { | ||
return strings.EqualFold(string(a), string(b)) | ||
}) { | ||
usersFilteredByStatus = append(usersFilteredByStatus, users[i]) | ||
} | ||
} | ||
users = usersFilteredByStatus | ||
} | ||
|
||
if len(params.RbacRole) > 0 && !slice.Contains(params.RbacRole, rbac.RoleMember()) { | ||
usersFilteredByRole := make([]database.User, 0, len(users)) | ||
for i, user := range users { | ||
if slice.OverlapCompare(params.RbacRole, user.RBACRoles, strings.EqualFold) { | ||
usersFilteredByRole = append(usersFilteredByRole, users[i]) | ||
} | ||
} | ||
|
||
users = usersFilteredByRole |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this is done by the GetUsers
call
kylecarbs
reviewed
Jul 13, 2023
johnstcn
approved these changes
Jul 14, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can argue that this is a refactor
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Prereq to #8447
What this does
This pushes the GetUsers authorization filter into SQL. So all authz checks are done by the SQL
WHERE
clause.This is probably not a performance increase, but makes fetching users and the number of users correct if we change permissions.
In the current codebase we allow all users to read all other users. Because of this assumption,
GetUsers
was lazy in how it handled user counts. If permissions were changed, this value would be inaccurate and leak the total number of users to a caller who does not have permission to know this value.Removes
GetAuthorizedUserCount
andGetFilteredUserCount
as it is no longer needed.