Skip to content

Commit

Permalink
Merge branch 'develop' into voip/wrap-up
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 authored Jun 9, 2022
2 parents 8c09db1 + 5a74a5c commit d5cce44
Show file tree
Hide file tree
Showing 326 changed files with 1,919 additions and 1,171 deletions.
1 change: 0 additions & 1 deletion apps/meteor/app/api/server/lib/getUploadFormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const getUploadFormData = async ({ request }) =>
bb.on('file', (fieldname, file, { filename, encoding, mimeType: mimetype }) => {
const fileData = [];

console.log(file);
file.on('data', (data) => fileData.push(data));

file.on('end', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ API.v1.addRoute(
'emoji-custom.list',
{ authRequired: true },
{
get() {
async get() {
const { query } = this.parseJsonQuery();
const { updatedSince } = this.queryParams;
let updatedSinceDate;
if (updatedSince) {
const updatedSinceDate = new Date(updatedSince);
if (isNaN(Date.parse(updatedSince))) {
throw new Meteor.Error('error-roomId-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
} else {
updatedSinceDate = new Date(updatedSince);
}
const [update, remove] = await Promise.all([
EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).toArray(),
EmojiCustom.trashFindDeletedAfter(updatedSinceDate).toArray(),
]);
return API.v1.success({
emojis: {
update: Promise.await(EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).toArray()),
remove: Promise.await(EmojiCustom.trashFindDeletedAfter(updatedSinceDate).toArray()),
update,
remove,
},
});
}

return API.v1.success({
emojis: {
update: Promise.await(EmojiCustom.find(query).toArray()),
update: await EmojiCustom.find(query).toArray(),
remove: [],
},
});
Expand All @@ -42,21 +44,19 @@ API.v1.addRoute(
'emoji-custom.all',
{ authRequired: true },
{
get() {
async get() {
const { offset, count } = this.getPaginationItems();
const { sort, query } = this.parseJsonQuery();

return API.v1.success(
Promise.await(
findEmojisCustom({
query,
pagination: {
offset,
count,
sort,
},
}),
),
await findEmojisCustom({
query,
pagination: {
offset,
count,
sort,
},
}),
);
},
},
Expand All @@ -66,18 +66,16 @@ API.v1.addRoute(
'emoji-custom.create',
{ authRequired: true },
{
post() {
const { emoji, ...fields } = Promise.await(
getUploadFormData({
request: this.request,
}),
);
async post() {
const { emoji, ...fields } = await getUploadFormData({
request: this.request,
});

if (!emoji) {
throw new Meteor.Error('invalid-field');
}

const isUploadable = Promise.await(Media.isImage(emoji.fileBuffer));
const isUploadable = await Media.isImage(emoji.fileBuffer);
if (!isUploadable) {
throw new Meteor.Error('emoji-is-not-image', "Emoji file provided cannot be uploaded since it's not an image");
}
Expand All @@ -88,10 +86,10 @@ API.v1.addRoute(
fields.newFile = true;
fields.aliases = fields.aliases || '';

Meteor.runAsUser(this.userId, () => {
Meteor.call('insertOrUpdateEmoji', fields);
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
});
Meteor.call('insertOrUpdateEmoji', fields);
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);

return API.v1.success();
},
},
);
Expand All @@ -100,12 +98,10 @@ API.v1.addRoute(
'emoji-custom.update',
{ authRequired: true },
{
post() {
const { emoji, ...fields } = Promise.await(
getUploadFormData({
request: this.request,
}),
);
async post() {
const { emoji, ...fields } = await getUploadFormData({
request: this.request,
});

if (!fields._id) {
throw new Meteor.Error('The required "_id" query param is missing.');
Expand Down Expand Up @@ -133,12 +129,11 @@ API.v1.addRoute(
fields.extension = emojiToUpdate.extension;
}

Meteor.runAsUser(this.userId, () => {
Meteor.call('insertOrUpdateEmoji', fields);
if (fields.newFile) {
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
}
});
Meteor.call('insertOrUpdateEmoji', fields);
if (fields.newFile) {
Meteor.call('uploadEmojiCustom', emoji.fileBuffer, emoji.mimetype, fields);
}
return API.v1.success();
},
},
);
Expand All @@ -153,7 +148,7 @@ API.v1.addRoute(
return API.v1.failure('The "emojiId" params is required!');
}

Meteor.runAsUser(this.userId, () => Meteor.call('deleteEmojiCustom', emojiId));
Meteor.call('deleteEmojiCustom', emojiId);

return API.v1.success();
},
Expand Down
28 changes: 18 additions & 10 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isMethodCallAnonProps,
isMeteorCall,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';

import { hasPermission } from '../../../authorization/server';
import { Users } from '../../../models/server';
Expand Down Expand Up @@ -166,17 +167,24 @@ API.v1.addRoute(
'me',
{ authRequired: true },
{
get() {
async get() {
const fields = getDefaultUserFields();
const user = Users.findOneById(this.userId, { fields });

// The password hash shouldn't be leaked but the client may need to know if it exists.
if (user?.services?.password?.bcrypt) {
user.services.password.exists = true;
delete user.services.password.bcrypt;
}

return API.v1.success(this.getUserInfo(user));
const { services, ...user } = Users.findOneById(this.userId, { fields }) as IUser;

return API.v1.success(
this.getUserInfo({
...user,
...(services && {
services: {
...services,
password: {
// The password hash shouldn't be leaked but the client may need to know if it exists.
exists: Boolean(services?.password?.bcrypt),
} as any,
},
}),
}),
);
},
},
);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ API.v1.addRoute(
},
post: {
twoFactorRequired: true,
async action(): Promise<ResultFor<'POST', 'settings/:_id'>> {
async action(): Promise<ResultFor<'POST', '/v1/settings/:_id'>> {
if (!hasPermission(this.userId, 'edit-privileged-setting')) {
return API.v1.unauthorized();
}
Expand Down
8 changes: 6 additions & 2 deletions apps/meteor/app/api/server/v1/voip/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ const parseAndValidate = (property: string, date?: string): DateParam => {

API.v1.addRoute(
'voip/room',
{ authRequired: false, rateLimiterOptions: { numRequestsAllowed: 5, intervalTimeInMS: 60000 } },
{
authRequired: true,
rateLimiterOptions: { numRequestsAllowed: 5, intervalTimeInMS: 60000 },
permissionsRequired: ['inbound-voip-calls'],
},
{
async get() {
const defaultCheckParams = {
Expand Down Expand Up @@ -213,7 +217,7 @@ API.v1.addRoute(
*/
API.v1.addRoute(
'voip/room.close',
{ authRequired: true, validateParams: isVoipRoomCloseProps },
{ authRequired: true, validateParams: isVoipRoomCloseProps, permissionsRequired: ['inbound-voip-calls'] },
{
async post() {
const { rid, token, options } = this.bodyParams;
Expand Down
19 changes: 4 additions & 15 deletions apps/meteor/app/apps/client/@types/IOrchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata/IAppInfo';
import { ISetting } from '@rocket.chat/apps-engine/definition/settings/ISetting';

export interface IDetailedDescription {
Expand Down Expand Up @@ -148,7 +147,6 @@ export interface IAppLanguage {

export interface IAppExternalURL {
url: string;
success: boolean;
}

export interface ICategory {
Expand All @@ -159,10 +157,10 @@ export interface ICategory {
title: string;
}

export interface IDeletedInstalledApp {
app: IAppInfo;
success: boolean;
}
// export interface IDeletedInstalledApp {
// app: IAppInfo;
// success: boolean;
// }

export interface IAppSynced {
app: IAppFromMarketplace;
Expand Down Expand Up @@ -193,12 +191,3 @@ export interface ISettingsReturn {
settings: ISettings;
success: boolean;
}

export interface ISettingsPayload {
settings: ISetting[];
}

export interface ISettingsSetReturn {
updated: ISettings;
success: boolean;
}
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/RealAppsEngineUIHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RealAppsEngineUIHost extends AppsEngineUIHost {

let cachedMembers = [];
try {
const { members } = await APIClient.get('v1/groups.members', { roomId: id });
const { members } = await APIClient.get('/v1/groups.members', { roomId: id });

cachedMembers = members.map(({ _id, username }) => ({
id: _id,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/communication/websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AppWebsocketReceiver extends Emitter {
}

onCommandAddedOrUpdated = (command) => {
APIClient.v1.get('commands.get', { command }).then((result) => {
APIClient.get('/v1/commands.get', { command }).then((result) => {
slashCommands.commands[command] = result.command;
});
};
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/client/gameCenter/gameCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { handleError } from '../../../../client/lib/utils/handleError';

const getExternalComponents = async (instance) => {
try {
const { externalComponents } = await APIClient.get('apps/externalComponents');
const { externalComponents } = await APIClient.get('/apps/externalComponents');
instance.games.set(externalComponents);
} catch (e) {
handleError(e);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/apps/client/gameCenter/gameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Template.GameContainer.events({
Template.GameContainer.onCreated(async () => {
const externalComponent = await getExternalComponent();

APIClient.post('apps/externalComponentEvent', {
APIClient.post('/apps/externalComponentEvent', {
event: 'IPostExternalComponentOpened',
externalComponent,
});
Expand All @@ -71,7 +71,7 @@ Template.GameContainer.onCreated(async () => {
Template.GameContainer.onDestroyed(async () => {
const externalComponent = await getExternalComponent();

APIClient.post('apps/externalComponentEvent', {
APIClient.post('/apps/externalComponentEvent', {
event: 'IPostExternalComponentClosed',
externalComponent,
});
Expand Down
Loading

0 comments on commit d5cce44

Please sign in to comment.