Skip to content

Commit

Permalink
Merge branch 'develop' into fix-jitsi-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal authored May 14, 2021
2 parents e0096b5 + 4713f3a commit 4ba4611
Show file tree
Hide file tree
Showing 318 changed files with 2,514 additions and 1,271 deletions.
13 changes: 11 additions & 2 deletions .storybook/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ export const rocketChatDecorator = (fn) => {
};

export const fullHeightDecorator = (storyFn) =>
<div style={{ display: 'flex', flexDirection: 'column', maxHeight: '100vh' }}>
<div style={{
display: 'flex',
flexDirection: 'column',
maxHeight: '100vh',
}}>
{storyFn()}
</div>;

export const centeredDecorator = (storyFn) =>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: '100vh' }}>
<div style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
minHeight: '100vh',
}}>
{storyFn()}
</div>;
9 changes: 6 additions & 3 deletions .storybook/mocks/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import i18next from 'i18next';
import React from 'react';

import { TranslationContext } from '../../client/contexts/TranslationContext';
import ServerProvider from '../../client/providers/ServerProvider';

let contextValue;

Expand Down Expand Up @@ -61,7 +62,9 @@ function TranslationProviderMock({ children }) {
}

export function MeteorProviderMock({ children }) {
return <TranslationProviderMock>
{children}
</TranslationProviderMock>;
return <ServerProvider>
<TranslationProviderMock>
{children}
</TranslationProviderMock>
</ServerProvider>;
}
4 changes: 2 additions & 2 deletions app/2fa/client/TOTPOAuth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { capitalize } from '@rocket.chat/string-helpers';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Facebook } from 'meteor/facebook-oauth';
Expand All @@ -6,7 +7,6 @@ import { Twitter } from 'meteor/twitter-oauth';
import { MeteorDeveloperAccounts } from 'meteor/meteor-developer-oauth';
import { Linkedin } from 'meteor/pauli:linkedin-oauth';
import { OAuth } from 'meteor/oauth';
import s from 'underscore.string';

import { Utils2fa } from './lib/2fa';
import { process2faReturn } from './callWithTwoFactorRequired';
Expand Down Expand Up @@ -126,7 +126,7 @@ Accounts.onPageLoadLogin((loginAttempt) => {

const oldConfigureLogin = CustomOAuth.prototype.configureLogin;
CustomOAuth.prototype.configureLogin = function(...args) {
const loginWithService = `loginWith${ s.capitalize(this.name) }`;
const loginWithService = `loginWith${ capitalize(String(this.name || '')) }`;

oldConfigureLogin.apply(this, args);

Expand Down
3 changes: 2 additions & 1 deletion app/api/server/lib/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { escapeRegExp } from '@rocket.chat/string-helpers';

import { Users } from '../../../models/server/raw';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { escapeRegExp } from '../../../../lib/escapeRegExp';

export async function findUsersToAutocomplete({ uid, selector }) {
if (!await hasPermissionAsync(uid, 'view-outside-room')) {
Expand Down
42 changes: 23 additions & 19 deletions app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import _ from 'underscore';

import { Rooms, Subscriptions, Messages, Uploads, Integrations, Users } from '../../../models';
import { Rooms, Subscriptions, Messages, Uploads, Integrations, Users } from '../../../models/server';
import { hasPermission, hasAtLeastOnePermission, hasAllPermission } from '../../../authorization/server';
import { mountIntegrationQueryBasedOnPermissions } from '../../../integrations/server/lib/mountQueriesBasedOnPermission';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { API } from '../api';
import { settings } from '../../../settings';
import { settings } from '../../../settings/server';
import { Team } from '../../../../server/sdk';
import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom';


// Returns the channel IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Expand Down Expand Up @@ -575,29 +577,31 @@ API.v1.addRoute('channels.members', { authRequired: true }, {
return API.v1.unauthorized();
}

const { offset, count } = this.getPaginationItems();
const { offset: skip, count: limit } = this.getPaginationItems();
const { sort = {} } = this.parseJsonQuery();

const subscriptions = Subscriptions.findByRoomId(findResult._id, {
fields: { 'u._id': 1 },
sort: { 'u.username': sort.username != null ? sort.username : 1 },
skip: offset,
limit: count,
});

const total = subscriptions.count();
check(this.queryParams, Match.ObjectIncluding({
status: Match.Maybe([String]),
filter: Match.Maybe(String),
}));
const { status, filter } = this.queryParams;

const members = subscriptions.fetch().map((s) => s.u && s.u._id);
const cursor = findUsersOfRoom({
rid: findResult._id,
...status && { status: { $in: status } },
skip,
limit,
filter,
...sort?.username && { sort: { username: sort.username } },
});

const users = Users.find({ _id: { $in: members } }, {
fields: { _id: 1, username: 1, name: 1, status: 1, statusText: 1, utcOffset: 1 },
sort: { username: sort.username != null ? sort.username : 1 },
}).fetch();
const total = cursor.count();
const members = cursor.fetch();

return API.v1.success({
members: users,
count: users.length,
offset,
members,
count: members.length,
offset: skip,
total,
});
},
Expand Down
49 changes: 28 additions & 21 deletions app/api/server/v1/groups.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { Match, check } from 'meteor/check';

import { mountIntegrationQueryBasedOnPermissions } from '../../../integrations/server/lib/mountQueriesBasedOnPermission';
import { Subscriptions, Rooms, Messages, Uploads, Integrations, Users } from '../../../models/server';
import { hasPermission, hasAtLeastOnePermission, canAccessRoom, hasAllPermission } from '../../../authorization/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { API } from '../api';
import { Team } from '../../../../server/sdk';
import { findUsersOfRoom } from '../../../../server/lib/findUsersOfRoom';

// Returns the private group subscription IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
export function findPrivateGroupByIdOrName({ params, userId, checkedArchived = true }) {
Expand All @@ -23,6 +24,7 @@ export function findPrivateGroupByIdOrName({ params, userId, checkedArchived = t
fname: 1,
prid: 1,
archived: 1,
broadcast: 1,
},
};
const room = params.roomId
Expand Down Expand Up @@ -54,6 +56,7 @@ export function findPrivateGroupByIdOrName({ params, userId, checkedArchived = t
ro: room.ro,
t: room.t,
name: roomName,
broadcast: room.broadcast,
};
}

Expand Down Expand Up @@ -491,36 +494,40 @@ API.v1.addRoute('groups.listAll', { authRequired: true }, {

API.v1.addRoute('groups.members', { authRequired: true }, {
get() {
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });
const room = Rooms.findOneById(findResult.rid, { fields: { broadcast: 1 } });
const findResult = findPrivateGroupByIdOrName({
params: this.requestParams(),
userId: this.userId,
});

if (room.broadcast && !hasPermission(this.userId, 'view-broadcast-member-list')) {
if (findResult.broadcast && !hasPermission(this.userId, 'view-broadcast-member-list')) {
return API.v1.unauthorized();
}

const { offset, count } = this.getPaginationItems();
const { offset: skip, count: limit } = this.getPaginationItems();
const { sort = {} } = this.parseJsonQuery();

const subscriptions = Subscriptions.findByRoomId(findResult.rid, {
fields: { 'u._id': 1 },
sort: { 'u.username': sort.username != null ? sort.username : 1 },
skip: offset,
limit: count,
});

const total = subscriptions.count();
check(this.queryParams, Match.ObjectIncluding({
status: Match.Maybe([String]),
filter: Match.Maybe(String),
}));
const { status, filter } = this.queryParams;

const members = subscriptions.fetch().map((s) => s.u && s.u._id);
const cursor = findUsersOfRoom({
rid: findResult.rid,
...status && { status: { $in: status } },
skip,
limit,
filter,
...sort?.username && { sort: { username: sort.username } },
});

const users = Users.find({ _id: { $in: members } }, {
fields: { _id: 1, username: 1, name: 1, status: 1, statusText: 1, utcOffset: 1 },
sort: { username: sort.username != null ? sort.username : 1 },
}).fetch();
const total = cursor.count();
const members = cursor.fetch();

return API.v1.success({
members: users,
count: users.length,
offset,
members,
count: members.length,
offset: skip,
total,
});
},
Expand Down
37 changes: 24 additions & 13 deletions app/api/server/v1/im.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';

import { Subscriptions, Uploads, Users, Messages, Rooms } from '../../../models';
import { hasPermission } from '../../../authorization';
import { Subscriptions, Uploads, Users, Messages, Rooms } from '../../../models/server';
import { hasPermission } from '../../../authorization/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { settings } from '../../../settings';
import { settings } from '../../../settings/server';
import { API } from '../api';
import { getDirectMessageByNameOrIdWithOptionToJoin } from '../../../lib/server/functions/getDirectMessageByNameOrIdWithOptionToJoin';

Expand Down Expand Up @@ -202,22 +203,32 @@ API.v1.addRoute(['dm.members', 'im.members'], { authRequired: true }, {

const { offset, count } = this.getPaginationItems();
const { sort } = this.parseJsonQuery();
const cursor = Subscriptions.findByRoomId(findResult.room._id, {
sort: { 'u.username': sort && sort.username ? sort.username : 1 },

check(this.queryParams, Match.ObjectIncluding({
status: Match.Maybe([String]),
filter: Match.Maybe(String),
}));
const { status, filter } = this.queryParams;

const extraQuery = {
_id: { $in: findResult.room.uids },
...status && { status: { $in: status } },
};

const options = {
sort: { username: sort && sort.username ? sort.username : 1 },
fields: { _id: 1, username: 1, name: 1, status: 1, statusText: 1, utcOffset: 1 },
skip: offset,
limit: count,
});
};

const total = cursor.count();
const members = cursor.fetch().map((s) => s.u && s.u.username);
const cursor = Users.findByActiveUsersExcept(filter, [], options, null, [extraQuery]);

const users = Users.find({ username: { $in: members } }, {
fields: { _id: 1, username: 1, name: 1, status: 1, statusText: 1, utcOffset: 1 },
sort: { username: sort && sort.username ? sort.username : 1 },
}).fetch();
const members = cursor.fetch();
const total = cursor.count();

return API.v1.success({
members: users,
members,
count: members.length,
offset,
total,
Expand Down
2 changes: 1 addition & 1 deletion app/api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { EJSON } from 'meteor/ejson';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { escapeHTML } from '@rocket.chat/string-helpers';

import { hasRole, hasPermission } from '../../../authorization/server';
import { Info } from '../../../utils/server';
Expand All @@ -14,7 +15,6 @@ import { API } from '../api';
import { getDefaultUserFields } from '../../../utils/server/functions/getDefaultUserFields';
import { getURL } from '../../../utils/lib/getURL';
import { StdOut } from '../../../logger/server/streamer';
import { escapeHTML } from '../../../../lib/escapeHTML';


// DEPRECATED
Expand Down
4 changes: 2 additions & 2 deletions app/api/server/v1/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, {

const inclusive = this.bodyParams.inclusive || false;

Meteor.runAsUser(this.userId, () => Meteor.call('cleanRoomHistory', {
const count = Meteor.runAsUser(this.userId, () => Meteor.call('cleanRoomHistory', {
roomId: findResult._id,
latest,
oldest,
Expand All @@ -207,7 +207,7 @@ API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, {
fromUsers: this.bodyParams.users,
}));

return API.v1.success();
return API.v1.success({ count });
},
});

Expand Down
7 changes: 2 additions & 5 deletions app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ API.v1.addRoute('teams.removeMember', { authRequired: true }, {
return API.v1.failure('invalid-user');
}

if (!Promise.await(Team.removeMembers(team._id, [{ userId }]))) {
if (!Promise.await(Team.removeMembers(this.userId, team._id, [{ userId }]))) {
return API.v1.failure();
}

Expand All @@ -279,7 +279,6 @@ API.v1.addRoute('teams.removeMember', { authRequired: true }, {
});
});
}

return API.v1.success();
},
});
Expand All @@ -290,7 +289,7 @@ API.v1.addRoute('teams.leave', { authRequired: true }, {

const team = teamId ? Promise.await(Team.getOneById(teamId)) : Promise.await(Team.getOneByName(teamName));

Promise.await(Team.removeMembers(team._id, [{
Promise.await(Team.removeMembers(this.userId, team._id, [{
userId: this.userId,
}]));

Expand All @@ -302,8 +301,6 @@ API.v1.addRoute('teams.leave', { authRequired: true }, {
});
}

removeUserFromRoom(team.roomId, this.user);

return API.v1.success();
},
});
Expand Down
14 changes: 12 additions & 2 deletions app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export class AppsRestApi {
},
post() {
let buff;
let permissionsGranted;

if (this.bodyParams.url) {
if (settings.get('Apps_Framework_Development_Mode') !== true) {
Expand Down Expand Up @@ -470,14 +471,23 @@ export class AppsRestApi {
return API.v1.failure({ error: 'Direct updating of an App is disabled.' });
}

buff = multipartFormDataHandler(this.request)?.app;
const formData = multipartFormDataHandler(this.request);
buff = formData?.app;
permissionsGranted = (() => {
try {
const permissions = JSON.parse(formData?.permissions || '');
return permissions.length ? permissions : undefined;
} catch {
return undefined;
}
})();
}

if (!buff) {
return API.v1.failure({ error: 'Failed to get a file to install for the App. ' });
}

const aff = Promise.await(manager.update(buff, this.bodyParams.permissionsGranted));
const aff = Promise.await(manager.update(buff, permissionsGranted));
const info = aff.getAppInfo();

if (aff.hasStorageError()) {
Expand Down
Loading

0 comments on commit 4ba4611

Please sign in to comment.