Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
125 lines
4.6 KiB
TypeScript
125 lines
4.6 KiB
TypeScript
import type { ILoginServiceConfiguration, OAuthConfiguration } from '@rocket.chat/core-typings';
|
|
import { Settings, LoginServiceConfiguration } from '@rocket.chat/models';
|
|
import { isTruthy } from '@rocket.chat/tools';
|
|
|
|
import { SystemLogger } from '../../lib/logger/system';
|
|
import { addMigration } from '../../lib/migrations';
|
|
|
|
const newDefaultButtonColor = '#e4e7ea';
|
|
const newDefaultButtonLabelColor = '#1f2329';
|
|
|
|
const settingsToUpdate = [
|
|
// button background colors
|
|
{ key: 'SAML_Custom_Default_button_color', defaultValue: '#1d74f5', newValue: newDefaultButtonColor },
|
|
{ key: 'CAS_button_color', defaultValue: '#1d74f5', newValue: newDefaultButtonColor },
|
|
{ key: 'Accounts_OAuth_Nextcloud_button_color', defaultValue: '#0082c9', newValue: newDefaultButtonColor },
|
|
{ key: 'Accounts_OAuth_Dolphin_button_color', defaultValue: '#1d74f5', newValue: newDefaultButtonColor },
|
|
// button label colors
|
|
{ key: 'SAML_Custom_Default_button_label_color', defaultValue: '#1d74f5', newValue: newDefaultButtonLabelColor },
|
|
{ key: 'CAS_button_label_color', defaultValue: '#1d74f5', newValue: newDefaultButtonLabelColor },
|
|
{ key: 'Accounts_OAuth_Nextcloud_button_label_color', defaultValue: '#1d74f5', newValue: newDefaultButtonLabelColor },
|
|
{ key: 'Accounts_OAuth_Dolphin_button_label_color', defaultValue: '#1d74f5', newValue: newDefaultButtonLabelColor },
|
|
];
|
|
|
|
const getSettingValue = async (key: string) => Settings.getValueById(key);
|
|
|
|
async function updateOAuthServices(): Promise<void> {
|
|
const services = await Settings.find({ _id: { $regex: /^(Accounts_OAuth_|Accounts_OAuth_Custom-)[a-z0-9_]+$/i } }).toArray();
|
|
const filteredServices = services.filter(({ value }) => typeof value === 'boolean');
|
|
for await (const { _id: key, value } of filteredServices) {
|
|
if (value !== true) {
|
|
continue;
|
|
}
|
|
|
|
let serviceName = key.replace('Accounts_OAuth_', '');
|
|
if (serviceName === 'Meteor') {
|
|
serviceName = 'meteor-developer';
|
|
}
|
|
if (/Accounts_OAuth_Custom-/.test(key)) {
|
|
serviceName = key.replace('Accounts_OAuth_Custom-', '');
|
|
}
|
|
|
|
const serviceKey = serviceName.toLowerCase();
|
|
|
|
const data: Partial<ILoginServiceConfiguration & Omit<OAuthConfiguration, '_id'>> = {};
|
|
|
|
if (/Accounts_OAuth_Custom-/.test(key)) {
|
|
data.buttonLabelColor = (await getSettingValue(`${key}-button_label_color`)) as string;
|
|
data.buttonColor = (await getSettingValue(`${key}-button_color`)) as string;
|
|
}
|
|
|
|
if (serviceName === 'Nextcloud') {
|
|
data.buttonLabelColor = (await getSettingValue('Accounts_OAuth_Nextcloud_button_label_color')) as string;
|
|
data.buttonColor = (await getSettingValue('Accounts_OAuth_Nextcloud_button_color')) as string;
|
|
}
|
|
|
|
await LoginServiceConfiguration.createOrUpdateService(serviceKey, data);
|
|
}
|
|
}
|
|
|
|
addMigration({
|
|
version: 317,
|
|
name: 'Change default color of OAuth login services buttons',
|
|
async up() {
|
|
// TODO: audit
|
|
const promises = settingsToUpdate
|
|
.map(async ({ key, defaultValue, newValue }) => {
|
|
const oldSettingValue = await getSettingValue(key);
|
|
|
|
if (!oldSettingValue || oldSettingValue !== defaultValue) {
|
|
return;
|
|
}
|
|
|
|
SystemLogger.warn({ msg: 'The default value of the setting has changed. Please review your settings.', key, newValue });
|
|
|
|
return Settings.updateOne({ _id: key }, { $set: { value: newValue } });
|
|
})
|
|
.filter(isTruthy);
|
|
|
|
await Promise.all(promises);
|
|
|
|
const customOAuthButtonColors = await Settings.find({
|
|
_id: { $regex: /^Accounts_OAuth_Custom-[a-zA-Z0-9_-]+-button_color$/ },
|
|
}).toArray();
|
|
const customOAuthButtonLabelColors = await Settings.find({
|
|
_id: { $regex: /^Accounts_OAuth_Custom-[a-zA-Z0-9_-]+-button_label_color$/ },
|
|
}).toArray();
|
|
|
|
const buttonColorPromises = customOAuthButtonColors
|
|
.map(({ _id, value, packageValue }) => {
|
|
if (packageValue !== value) {
|
|
return;
|
|
}
|
|
|
|
SystemLogger.warn({
|
|
msg: 'The default value of the custom setting has changed. Please review your settings.',
|
|
_id,
|
|
newValue: newDefaultButtonColor,
|
|
});
|
|
|
|
return Settings.updateOne({ _id }, { $set: { value: newDefaultButtonColor } });
|
|
})
|
|
.filter(isTruthy);
|
|
|
|
const buttonLabelColorPromises = customOAuthButtonLabelColors
|
|
.map(({ _id, value, packageValue }) => {
|
|
if (packageValue !== value) {
|
|
return;
|
|
}
|
|
|
|
SystemLogger.warn({
|
|
msg: 'The default value of the custom setting has changed. Please review your settings.',
|
|
_id,
|
|
newValue: newDefaultButtonLabelColor,
|
|
});
|
|
|
|
return Settings.updateOne({ _id }, { $set: { value: newDefaultButtonLabelColor } });
|
|
})
|
|
.filter(isTruthy);
|
|
|
|
await Promise.all([...buttonColorPromises, ...buttonLabelColorPromises]);
|
|
// update login service configurations
|
|
await updateOAuthServices();
|
|
},
|
|
});
|