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] Users without the view-other-user-info permission can't use the users.list endpoint #26050

Merged
merged 9 commits into from
Jul 18, 2022
7 changes: 6 additions & 1 deletion apps/meteor/app/api/server/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function getNonEmptyFields(fields: { [k: string]: 1 | 0 }): { [k: string]
active: 1,
avatarETag: 1,
lastLogin: 1,
type: 1,
} as const;

if (!fields || Object.keys(fields).length === 0) {
Expand All @@ -102,7 +103,7 @@ const _defaultQuery = {
*/

type Query = { [k: string]: unknown };
export function getNonEmptyQuery(query: Query): typeof _defaultQuery | (typeof _defaultQuery & Query) {
export function getNonEmptyQuery(query: Query, canSeeAllUserInfo?: boolean): typeof _defaultQuery | (typeof _defaultQuery & Query) {
const defaultQuery = {
$or: [
{ 'emails.address': { $regex: '', $options: 'i' } },
Expand All @@ -111,6 +112,10 @@ export function getNonEmptyQuery(query: Query): typeof _defaultQuery | (typeof _
],
};

if (!canSeeAllUserInfo) {
defaultQuery.$or = defaultQuery.$or.filter((or) => !or['emails.address']);
}

tassoevan marked this conversation as resolved.
Show resolved Hide resolved
if (!query || Object.keys(query).length === 0) {
return defaultQuery;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ API.v1.addRoute(
const { offset, count } = this.getPaginationItems();
const { sort, fields, query } = this.parseJsonQuery();

const nonEmptyQuery = getNonEmptyQuery(query);
const nonEmptyQuery = getNonEmptyQuery(query, hasPermission(this.userId, 'view-full-other-user-info'));
const nonEmptyFields = getNonEmptyFields(fields);

const inclusiveFields = getInclusiveFields(nonEmptyFields);
Expand All @@ -413,6 +413,7 @@ API.v1.addRoute(
inclusiveFieldsKeys.includes('emails') && 'emails.address.*',
inclusiveFieldsKeys.includes('username') && 'username.*',
inclusiveFieldsKeys.includes('name') && 'name.*',
inclusiveFieldsKeys.includes('type') && 'type.*',
].filter(Boolean) as string[],
this.queryOperations,
)
Expand Down