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

[BREAK] Always remove the field services from user data responses in REST API #10799

Merged
merged 5 commits into from
Jun 20, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions packages/rocketchat-api/server/helpers/parseJsonQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
const VIEW_FULL_USER_FIELDS_TO_EXCLUDE = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't define this every time the call happens, move it outside.

services: 0
};
let sort;
if (this.queryParams.sort) {
try {
Expand All @@ -22,8 +25,12 @@ RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
// Verify the user's selected fields only contains ones which their role allows
if (typeof fields === 'object') {
let nonSelectableFields = Object.keys(RocketChat.API.v1.defaultFieldsToExclude);
if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
nonSelectableFields = nonSelectableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
if (this.request.route.includes('/v1/users.')) {
if (RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info')) {
Copy link
Member

Choose a reason for hiding this comment

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

what do you think

	...
	const getFields = () => Object.keys(RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') ? RocketChat.API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser : RocketChat.API.v1.limitedUserFieldsToExclude);
	nonSelectableFields = nonSelectableFields.concat(getFields());
	...

nonSelectableFields = nonSelectableFields.concat(Object.keys(VIEW_FULL_USER_FIELDS_TO_EXCLUDE));
} else {
nonSelectableFields = nonSelectableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
}
}

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

// Limit the fields by default
fields = Object.assign({}, fields, RocketChat.API.v1.defaultFieldsToExclude);
if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
fields = Object.assign(fields, RocketChat.API.v1.limitedUserFieldsToExclude);
if (this.request.route.includes('/v1/users.')) {
if (RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info')) {
fields = Object.assign(fields, VIEW_FULL_USER_FIELDS_TO_EXCLUDE);
} else {
fields = Object.assign(fields, RocketChat.API.v1.limitedUserFieldsToExclude);
}
}

let query;
Expand All @@ -52,8 +63,12 @@ RocketChat.API.helperMethods.set('parseJsonQuery', function _parseJsonQuery() {
// Verify the user has permission to query the fields they are
if (typeof query === 'object') {
let nonQuerableFields = Object.keys(RocketChat.API.v1.defaultFieldsToExclude);
Copy link
Contributor

Choose a reason for hiding this comment

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

"nonQueryable"

if (!RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info') && this.request.route.includes('/v1/users.')) {
nonQuerableFields = nonQuerableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
if (this.request.route.includes('/v1/users.')) {
if (RocketChat.authz.hasPermission(this.userId, 'view-full-other-user-info')) {
nonQuerableFields = nonQuerableFields.concat(Object.keys(VIEW_FULL_USER_FIELDS_TO_EXCLUDE));
} else {
nonQuerableFields = nonQuerableFields.concat(Object.keys(RocketChat.API.v1.limitedUserFieldsToExclude));
}
}

Object.keys(query).forEach((k) => {
Expand Down