Skip to content

Commit c53fa4d

Browse files
MarcosSpessattorodrigok
authored andcommitted
[BREAK] Always remove the field services from user data responses (#10799)
[BREAK] Always remove the field `services` from user data responses in REST API
1 parent 6cfc53f commit c53fa4d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/rocketchat-api/server/api.js

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class API extends Restivus {
3131
customFields: 0,
3232
settings: 0
3333
};
34+
this.limitedUserFieldsToExcludeIfIsPrivilegedUser = {
35+
services: 0
36+
};
3437

3538
this._config.defaultOptionsEndpoint = function _defaultOptionsEndpoint() {
3639
if (this.request.method === 'OPTIONS' && this.request.headers['access-control-request-method']) {

packages/rocketchat-api/server/helpers/parseJsonQuery.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
2222
// Verify the user's selected fields only contains ones which their role allows
2323
if (typeof fields === 'object') {
2424
let nonSelectableFields = Object.keys(RocketChat.API.v1.defaultFieldsToExclude);
25-
if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
26-
nonSelectableFields = nonSelectableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
25+
if (this.request.route.includes('/v1/users.')) {
26+
const getFields = () => Object.keys(RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') ? RocketChat.API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser : RocketChat.API.v1.limitedUserFieldsToExclude);
27+
nonSelectableFields = nonSelectableFields.concat(getFields());
2728
}
2829

2930
Object.keys(fields).forEach((k) => {
@@ -35,8 +36,12 @@ RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
3536

3637
// Limit the fields by default
3738
fields = Object.assign({}, fields, RocketChat.API.v1.defaultFieldsToExclude);
38-
if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
39-
fields = Object.assign(fields, RocketChat.API.v1.limitedUserFieldsToExclude);
39+
if (this.request.route.includes('/v1/users.')) {
40+
if (RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info')) {
41+
fields = Object.assign(fields, RocketChat.API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser);
42+
} else {
43+
fields = Object.assign(fields, RocketChat.API.v1.limitedUserFieldsToExclude);
44+
}
4045
}
4146

4247
let query;
@@ -51,13 +56,17 @@ RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
5156

5257
// Verify the user has permission to query the fields they are
5358
if (typeof query === 'object') {
54-
let nonQuerableFields = Object.keys(RocketChat.API.v1.defaultFieldsToExclude);
55-
if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
56-
nonQuerableFields = nonQuerableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
59+
let nonQueryableFields = Object.keys(RocketChat.API.v1.defaultFieldsToExclude);
60+
if (this.request.route.includes('/v1/users.')) {
61+
if (RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info')) {
62+
nonQueryableFields = nonQueryableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser));
63+
} else {
64+
nonQueryableFields = nonQueryableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
65+
}
5766
}
5867

5968
Object.keys(query).forEach((k) => {
60-
if (nonQuerableFields.includes(k) || nonQuerableFields.includes(k.split(RocketChat.API.v1.fieldSeparator)[0])) {
69+
if (nonQueryableFields.includes(k) || nonQueryableFields.includes(k.split(RocketChat.API.v1.fieldSeparator)[0])) {
6170
delete query[k];
6271
}
6372
});

0 commit comments

Comments
 (0)