Skip to content

Commit

Permalink
Merge branch 'develop' into imp/retention
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jun 21, 2024
2 parents 533f8bf + c0828b4 commit 02b5ddf
Show file tree
Hide file tree
Showing 71 changed files with 721 additions and 423 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-windows-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Moves the quotes to be on top of the message for better readability
5 changes: 5 additions & 0 deletions .changeset/rare-dancers-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Adds the missing `ignoreThreads` param fixing the issue not allowing ignoring threads when overriding retention policy
5 changes: 5 additions & 0 deletions .changeset/red-cheetahs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes a cosmetic issue where emoji picker object and symbols category icon are swapped
6 changes: 6 additions & 0 deletions .changeset/spotty-seals-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/uikit-playground': minor
'@rocket.chat/meteor': minor
---

Upgrades fuselage-toastbar version in order to add RTL support to the component
59 changes: 41 additions & 18 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SystemLogger } from '../../../../server/lib/logger/system';
import { getLogs } from '../../../../server/stream/stdout';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { passwordPolicy } from '../../../lib/server';
import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
import { getDefaultUserFields } from '../../../utils/server/functions/getDefaultUserFields';
import { isSMTPConfigured } from '../../../utils/server/functions/isSMTPConfigured';
Expand Down Expand Up @@ -687,27 +688,49 @@ API.v1.addRoute(
setDeploymentAs: String,
});

const settingsIds: string[] = [];

if (this.bodyParams.setDeploymentAs === 'new-workspace') {
await Promise.all([
Settings.resetValueById('uniqueID', process.env.DEPLOYMENT_ID || uuidv4()),
// Settings.resetValueById('Cloud_Url'),
Settings.resetValueById('Cloud_Service_Agree_PrivacyTerms'),
Settings.resetValueById('Cloud_Workspace_Id'),
Settings.resetValueById('Cloud_Workspace_Name'),
Settings.resetValueById('Cloud_Workspace_Client_Id'),
Settings.resetValueById('Cloud_Workspace_Client_Secret'),
Settings.resetValueById('Cloud_Workspace_Client_Secret_Expires_At'),
Settings.resetValueById('Cloud_Workspace_Registration_Client_Uri'),
Settings.resetValueById('Cloud_Workspace_PublicKey'),
Settings.resetValueById('Cloud_Workspace_License'),
Settings.resetValueById('Cloud_Workspace_Had_Trial'),
Settings.resetValueById('Cloud_Workspace_Access_Token'),
Settings.resetValueById('Cloud_Workspace_Access_Token_Expires_At', new Date(0)),
Settings.resetValueById('Cloud_Workspace_Registration_State'),
]);
settingsIds.push(
'Cloud_Service_Agree_PrivacyTerms',
'Cloud_Workspace_Id',
'Cloud_Workspace_Name',
'Cloud_Workspace_Client_Id',
'Cloud_Workspace_Client_Secret',
'Cloud_Workspace_Client_Secret_Expires_At',
'Cloud_Workspace_Registration_Client_Uri',
'Cloud_Workspace_PublicKey',
'Cloud_Workspace_License',
'Cloud_Workspace_Had_Trial',
'Cloud_Workspace_Access_Token',
'uniqueID',
'Cloud_Workspace_Access_Token_Expires_At',
);
}

await Settings.updateValueById('Deployment_FingerPrint_Verified', true);
settingsIds.push('Deployment_FingerPrint_Verified');

const promises = settingsIds.map((settingId) => {
if (settingId === 'uniqueID') {
return Settings.resetValueById('uniqueID', process.env.DEPLOYMENT_ID || uuidv4());
}

if (settingId === 'Cloud_Workspace_Access_Token_Expires_At') {
return Settings.resetValueById('Cloud_Workspace_Access_Token_Expires_At', new Date(0));
}

if (settingId === 'Deployment_FingerPrint_Verified') {
return Settings.updateValueById('Deployment_FingerPrint_Verified', true);
}

return Settings.resetValueById(settingId);
});

(await Promise.all(promises)).forEach((value, index) => {
if (value?.modifiedCount) {
void notifyOnSettingChangedById(settingsIds[index]);
}
});

return API.v1.success({});
},
Expand Down
28 changes: 20 additions & 8 deletions apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { FindOptions } from 'mongodb';
import _ from 'underscore';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { SettingsEvents, settings } from '../../../settings/server';
import { setValue } from '../../../settings/server/raw';
import { API } from '../api';
Expand Down Expand Up @@ -186,23 +187,34 @@ API.v1.addRoute(
}

if (isSettingColor(setting) && isSettingsUpdatePropsColor(this.bodyParams)) {
await Settings.updateOptionsById<ISettingColor>(this.urlParams._id, {
editor: this.bodyParams.editor,
});
await Settings.updateValueNotHiddenById(this.urlParams._id, this.bodyParams.value);
const updateOptionsPromise = Settings.updateOptionsById<ISettingColor>(this.urlParams._id, { editor: this.bodyParams.editor });
const updateValuePromise = Settings.updateValueNotHiddenById(this.urlParams._id, this.bodyParams.value);

const [updateOptionsResult, updateValueResult] = await Promise.all([updateOptionsPromise, updateValuePromise]);

if (updateOptionsResult.modifiedCount || updateValueResult.modifiedCount) {
await notifyOnSettingChangedById(this.urlParams._id);
}

return API.v1.success();
}

if (
isSettingsUpdatePropDefault(this.bodyParams) &&
(await Settings.updateValueNotHiddenById(this.urlParams._id, this.bodyParams.value))
) {
if (isSettingsUpdatePropDefault(this.bodyParams)) {
const { matchedCount } = await Settings.updateValueNotHiddenById(this.urlParams._id, this.bodyParams.value);
if (!matchedCount) {
return API.v1.failure();
}

const s = await Settings.findOneNotHiddenById(this.urlParams._id);
if (!s) {
return API.v1.failure();
}

settings.set(s);
setValue(this.urlParams._id, this.bodyParams.value);

await notifyOnSettingChanged(s);

return API.v1.success();
}

Expand Down
9 changes: 7 additions & 2 deletions apps/meteor/app/apps/server/bridges/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { ISetting } from '@rocket.chat/apps-engine/definition/settings';
import { ServerSettingBridge } from '@rocket.chat/apps-engine/server/bridges/ServerSettingBridge';
import { Settings } from '@rocket.chat/models';

import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';

export class AppSettingBridge extends ServerSettingBridge {
constructor(private readonly orch: IAppServerOrchestrator) {
super();
Expand Down Expand Up @@ -54,7 +56,7 @@ export class AppSettingBridge extends ServerSettingBridge {
throw new Error(`The setting "${setting.id}" is not readable.`);
}

await Settings.updateValueById(setting.id, setting.value);
(await Settings.updateValueById(setting.id, setting.value)).modifiedCount && void notifyOnSettingChangedById(setting.id);
}

protected async incrementValue(id: string, value: number, appId: string): Promise<void> {
Expand All @@ -64,6 +66,9 @@ export class AppSettingBridge extends ServerSettingBridge {
throw new Error(`The setting "${id}" is not readable.`);
}

await Settings.incrementValueById(id, value);
const { value: setting } = await Settings.incrementValueById(id, value, { returnDocument: 'after' });
if (setting) {
void notifyOnSettingChanged(setting);
}
}
}
20 changes: 17 additions & 3 deletions apps/meteor/app/assets/server/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import sharp from 'sharp';
import { hasPermissionAsync } from '../../authorization/server/functions/hasPermission';
import { RocketChatFile } from '../../file/server';
import { methodDeprecationLogger } from '../../lib/server/lib/deprecationWarningLogger';
import { notifyOnSettingChangedById } from '../../lib/server/lib/notifyListener';
import { settings, settingsRegistry } from '../../settings/server';
import { getExtension } from '../../utils/lib/mimeTypes';
import { getURL } from '../../utils/server/getURL';
Expand Down Expand Up @@ -261,7 +262,13 @@ class RocketChatAssetsClass {
defaultUrl: assetInstance.defaultUrl,
};

void Settings.updateValueById(key, value);
void (async () => {
const { modifiedCount } = await Settings.updateValueById(key, value);
if (modifiedCount) {
void notifyOnSettingChangedById(key);
}
})();

return RocketChatAssets.processAsset(key, value);
}, 200);
});
Expand All @@ -282,7 +289,13 @@ class RocketChatAssetsClass {
defaultUrl: getAssetByKey(asset).defaultUrl,
};

void Settings.updateValueById(key, value);
void (async () => {
const { modifiedCount } = await Settings.updateValueById(key, value);
if (modifiedCount) {
void notifyOnSettingChangedById(key);
}
})();

await RocketChatAssets.processAsset(key, value);
}

Expand Down Expand Up @@ -371,7 +384,8 @@ export async function addAssetToSetting(asset: string, value: IRocketChatAsset,

if (currentValue && typeof currentValue === 'object' && currentValue.defaultUrl !== getAssetByKey(asset).defaultUrl) {
currentValue.defaultUrl = getAssetByKey(asset).defaultUrl;
await Settings.updateValueById(key, currentValue);

(await Settings.updateValueById(key, currentValue)).modifiedCount && void notifyOnSettingChangedById(key);
}
}

Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getNewUserRoles } from '../../../../server/services/user/lib/getNewUser
import { getAvatarSuggestionForUser } from '../../../lib/server/functions/getAvatarSuggestionForUser';
import { joinDefaultChannels } from '../../../lib/server/functions/joinDefaultChannels';
import { setAvatarFromServiceWithValidation } from '../../../lib/server/functions/setUserAvatar';
import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import * as Mailer from '../../../mailer/server/api';
import { settings } from '../../../settings/server';
import { safeGetMeteorUser } from '../../../utils/server/functions/safeGetMeteorUser';
Expand Down Expand Up @@ -323,7 +324,8 @@ const insertUserDocAsync = async function (options, user) {
if (!roles.includes('admin') && !hasAdmin) {
roles.push('admin');
if (settings.get('Show_Setup_Wizard') === 'pending') {
await Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
(await Settings.updateValueById('Show_Setup_Wizard', 'in_progress')).modifiedCount &&
void notifyOnSettingChangedById('Show_Setup_Wizard');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Settings } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';

import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
import { userScopes } from '../oauthScopes';
import { getRedirectUri } from './getRedirectUri';
Expand All @@ -10,6 +11,8 @@ export async function getOAuthAuthorizationUrl() {

await Settings.updateValueById('Cloud_Workspace_Registration_State', state);

void notifyOnSettingChangedById('Cloud_Workspace_Registration_State');

const cloudUrl = settings.get('Cloud_Url');
const clientId = settings.get('Cloud_Workspace_Client_Id');
const redirectUri = getRedirectUri();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Settings } from '@rocket.chat/models';

import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
import { getWorkspaceAccessTokenWithScope } from './getWorkspaceAccessTokenWithScope';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';
Expand Down Expand Up @@ -32,11 +33,13 @@ export async function getWorkspaceAccessToken(forceNew = false, scope = '', save
const accessToken = await getWorkspaceAccessTokenWithScope(scope, throwOnError);

if (save) {
await Promise.all([
Settings.updateValueById('Cloud_Workspace_Access_Token', accessToken.token),
Settings.updateValueById('Cloud_Workspace_Access_Token_Expires_At', accessToken.expiresAt),
]);
(await Settings.updateValueById('Cloud_Workspace_Access_Token', accessToken.token)).modifiedCount &&
void notifyOnSettingChangedById('Cloud_Workspace_Access_Token');

(await Settings.updateValueById('Cloud_Workspace_Access_Token_Expires_At', accessToken.expiresAt)).modifiedCount &&
void notifyOnSettingChangedById('Cloud_Workspace_Access_Token_Expires_At');
}

return accessToken.token;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Settings } from '@rocket.chat/models';

import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';

export async function removeWorkspaceRegistrationInfo() {
Expand All @@ -8,16 +9,30 @@ export async function removeWorkspaceRegistrationInfo() {
return true;
}

await Promise.all([
Settings.resetValueById('Cloud_Workspace_Id', null),
Settings.resetValueById('Cloud_Workspace_Name', null),
Settings.resetValueById('Cloud_Workspace_Client_Id', null),
Settings.resetValueById('Cloud_Workspace_Client_Secret', null),
Settings.resetValueById('Cloud_Workspace_Client_Secret_Expires_At', null),
Settings.resetValueById('Cloud_Workspace_PublicKey', null),
Settings.resetValueById('Cloud_Workspace_Registration_Client_Uri', null),
]);
const settingsIds = [
'Cloud_Workspace_Id',
'Cloud_Workspace_Name',
'Cloud_Workspace_Client_Id',
'Cloud_Workspace_Client_Secret',
'Cloud_Workspace_Client_Secret_Expires_At',
'Cloud_Workspace_PublicKey',
'Cloud_Workspace_Registration_Client_Uri',
'Show_Setup_Wizard',
];

const promises = settingsIds.map((settingId) => {
if (settingId === 'Show_Setup_Wizard') {
return Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}

return Settings.resetValueById(settingId, null);
});

(await Promise.all(promises)).forEach((value, index) => {
if (value?.modifiedCount) {
void notifyOnSettingChangedById(settingsIds[index]);
}
});

await Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
return true;
}
Loading

0 comments on commit 02b5ddf

Please sign in to comment.