Skip to content

Commit

Permalink
Merge branch 'develop' into chore/settings-small-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Jun 30, 2022
2 parents e5faff8 + cb7c9a9 commit 761e5db
Show file tree
Hide file tree
Showing 143 changed files with 1,420 additions and 995 deletions.
6 changes: 3 additions & 3 deletions .kodiak.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ block_on_neutral_required_check_runs = true
blocking_labels = ["stat: needs QA", "Invalid PR Title"]
prioritize_ready_to_merge = true


[merge.message]
title = "pull_request_title" # default: "github_default"
body = "pull_request_body" # default: "github_default"
title = "pull_request_title"
body = "empty"
include_coauthors=true

[merge.automerge_dependencies]
versions = ["minor", "patch"]
usernames = ["dependabot"]
Expand Down
62 changes: 8 additions & 54 deletions apps/meteor/app/api/server/v1/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '@rocket.chat/rest-typings';

import { API } from '../api';
import { hasPermission } from '../../../authorization/server';
import { Imports } from '../../../models/server';
import { Importers } from '../../../importer/server';
import { executeUploadImportFile } from '../../../importer/server/methods/uploadImportFile';
Expand Down Expand Up @@ -42,9 +41,7 @@ API.v1.addRoute(
post() {
const { fileUrl, importerKey } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('downloadPublicImportFile', fileUrl, importerKey));
});
Meteor.call('downloadPublicImportFile', fileUrl, importerKey);

return API.v1.success();
},
Expand All @@ -61,9 +58,7 @@ API.v1.addRoute(
post() {
const { input } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('startImport', input));
});
Meteor.call('startImport', input);

return API.v1.success();
},
Expand All @@ -78,11 +73,7 @@ API.v1.addRoute(
},
{
get() {
let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('getImportFileData');
});

const result = Meteor.call('getImportFileData');
return API.v1.success(result);
},
},
Expand All @@ -96,11 +87,7 @@ API.v1.addRoute(
},
{
get() {
let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('getImportProgress');
});

const result = Meteor.call('getImportProgress');
return API.v1.success(result);
},
},
Expand All @@ -114,11 +101,7 @@ API.v1.addRoute(
},
{
get() {
let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('getLatestImportOperations');
});

const result = Meteor.call('getLatestImportOperations');
return API.v1.success(result);
},
},
Expand All @@ -129,19 +112,10 @@ API.v1.addRoute(
{
authRequired: true,
validateParams: isDownloadPendingFilesParamsPOST,
permissionsRequired: ['run-import'],
},
{
post() {
if (!this.userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'downloadPendingFiles',
});
}

if (!hasPermission(this.userId, 'run-import')) {
throw new Meteor.Error('not_authorized');
}

const importer = Importers.get('pending-files');
if (!importer) {
throw new Meteor.Error('error-importer-not-defined', 'The Pending File Importer was not found.', {
Expand All @@ -153,7 +127,6 @@ API.v1.addRoute(
const count = importer.instance.prepareFileCount();

return API.v1.success({
success: true,
count,
});
},
Expand All @@ -165,19 +138,10 @@ API.v1.addRoute(
{
authRequired: true,
validateParams: isDownloadPendingAvatarsParamsPOST,
permissionsRequired: ['run-import'],
},
{
post() {
if (!this.userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'downloadPendingAvatars',
});
}

if (!hasPermission(this.userId, 'run-import')) {
throw new Meteor.Error('not_authorized');
}

const importer = Importers.get('pending-avatars');
if (!importer) {
throw new Meteor.Error('error-importer-not-defined', 'The Pending File Importer was not found.', {
Expand All @@ -189,7 +153,6 @@ API.v1.addRoute(
const count = importer.instance.prepareFileCount();

return API.v1.success({
success: true,
count,
});
},
Expand All @@ -201,19 +164,10 @@ API.v1.addRoute(
{
authRequired: true,
validateParams: isGetCurrentImportOperationParamsGET,
permissionsRequired: ['run-import'],
},
{
get() {
if (!this.userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'getCurrentImportOperation',
});
}

if (!hasPermission(this.userId, 'run-import')) {
throw new Meteor.Error('not_authorized');
}

const operation = Imports.findLastImport();
return API.v1.success({
success: true,
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/api/server/v1/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ API.v1.addRoute(
Meteor.call('raix:push-update', {
id: deviceId,
token: { [type]: value },
authToken: this.request.headers['x-auth-token'],
appName,
userId: this.userId,
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ API.v1.addRoute(
{
authRequired: false,
rateLimiterOptions: {
numRequestsAllowed: settings.get('Rate_Limiter_Limit_RegisterUser'),
numRequestsAllowed: settings.get('Rate_Limiter_Limit_RegisterUser') ?? 1,
intervalTimeInMS: settings.get('API_Enable_Rate_Limiter_Limit_Time_Default'),
},
validateParams: isUserRegisterParamsPOST,
Expand Down
12 changes: 11 additions & 1 deletion apps/meteor/app/apps/server/bridges/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ export class AppSettingBridge extends ServerSettingBridge {
throw new Error(`The setting "${setting.id}" is not readable.`);
}

throw new Error('Method not implemented.');
await Settings.updateValueById(setting.id, setting.value);
}

protected async incrementValue(id: string, value: number, appId: string): Promise<void> {
this.orch.debugLog(`The App ${appId} is incrementing the value of the setting ${id}.`);

if (!(await this.isReadableById(id, appId))) {
throw new Error(`The setting "${id}" is not readable.`);
}

await Settings.incrementValueById(id, value);
}
}
32 changes: 32 additions & 0 deletions apps/meteor/app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,38 @@ export class AppsRestApi {
},
);

this.api.addRoute(
':id/versions',
{ authRequired: true, permissionsRequired: ['manage-apps'] },
{
get() {
const baseUrl = orchestrator.getMarketplaceUrl();

const headers = {}; // DO NOT ATTACH THE FRAMEWORK/ENGINE VERSION HERE.
const token = getWorkspaceAccessToken();
if (token) {
headers.Authorization = `Bearer ${token}`;
}

let result;
try {
result = HTTP.get(`${baseUrl}/v1/apps/${this.urlParams.id}`, {
headers,
});
} catch (e) {
return handleError('Unable to access Marketplace. Does the server has access to the internet?', e);
}

if (!result || result.statusCode !== 200) {
orchestrator.getRocketChatLogger().error('Error getting the App versions from the Marketplace:', result.data);
return API.v1.failure();
}

return API.v1.success({ apps: result.data });
},
},
);

this.api.addRoute(
':id/sync',
{ authRequired: true, permissionsRequired: ['manage-apps'] },
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/loadMessageHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const loadMessageHistory = function loadMessageHistory({
if (ls != null) {
const firstMessage = messages[messages.length - 1];

if ((firstMessage != null ? firstMessage.ts : undefined) > ls) {
if (firstMessage && new Date(firstMessage.ts) > new Date(ls)) {
// delete options.limit;
const unreadMessages = Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(
rid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function getEmailData({ message, receiver, sender, subscription, room, em
// Reply-To header with format "username+messageId@domain"
email.headers['Reply-To'] = `${replyto.split('@')[0].split(settings.get('Direct_Reply_Separator'))[0]}${settings.get(
'Direct_Reply_Separator',
)}${message._id}@${replyto.split('@')[1]}`;
)}${message.tmid || message._id}@${replyto.split('@')[1]}`;
}

metrics.notificationsSent.inc({ notification_type: 'email' });
Expand Down
Loading

0 comments on commit 761e5db

Please sign in to comment.