Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 8 commits intomainfromstevenmasley/users_sql_filter
Jul 17, 2023

Conversation

@Emyrk
Copy link
Member

@EmyrkEmyrk commentedJul 13, 2023
edited
Loading

Prereq to#8447

What this does

This pushes the GetUsers authorization filter into SQL. So all authz checks are done by the SQLWHERE 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.

RemovesGetAuthorizedUserCount andGetFilteredUserCount as it is no longer needed.

@EmyrkEmyrk marked this pull request as ready for reviewJuly 13, 2023 16:50
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:=rangeusers {
if!user.Deleted {
tmp=append(tmp,user)
}
}
users=tmp

ifparams.Search!="" {
tmp:=make([]database.User,0,len(users))
fori,user:=rangeusers {
ifstrings.Contains(strings.ToLower(user.Email),strings.ToLower(params.Search)) {
tmp=append(tmp,users[i])
}elseifstrings.Contains(strings.ToLower(user.Username),strings.ToLower(params.Search)) {
tmp=append(tmp,users[i])
}
}
users=tmp
}

iflen(params.Status)>0 {
usersFilteredByStatus:=make([]database.User,0,len(users))
fori,user:=rangeusers {
ifslice.ContainsCompare(params.Status,user.Status,func(a,b database.UserStatus)bool {
returnstrings.EqualFold(string(a),string(b))
}) {
usersFilteredByStatus=append(usersFilteredByStatus,users[i])
}
}
users=usersFilteredByStatus
}

iflen(params.RbacRole)>0&&!slice.Contains(params.RbacRole,rbac.RoleMember()) {
usersFilteredByRole:=make([]database.User,0,len(users))
fori,user:=rangeusers {
ifslice.OverlapCompare(params.RbacRole,user.RBACRoles,strings.EqualFold) {
usersFilteredByRole=append(usersFilteredByRole,users[i])
}
}

users=usersFilteredByRole
Copy link
MemberAuthor

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 theGetUsers call

@EmyrkEmyrk requested a review fromjohnstcnJuly 13, 2023 17:20
Copy link
Member

@johnstcnjohnstcn left a 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

Emyrk reacted with thumbs up emoji
@EmyrkEmyrk merged commit67494a3 intomainJul 17, 2023
@EmyrkEmyrk deleted the stevenmasley/users_sql_filter branchJuly 17, 2023 13:45
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 17, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@kylecarbskylecarbskylecarbs left review comments

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@Emyrk@johnstcn@kylecarbs

[8]ページ先頭

©2009-2025 Movatter.jp