snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
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

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
/**
* Picks a readable text color for a solid background fill.
*
* Computes each candidate's WCAG contrast ratio against the background (sRGB channels are
* gamma-decoded to linear light, then weighted by how strongly the eye perceives each: 21% red,
* 72% green, 7% blue) and keeps the higher-contrast one — so admins can pick any banner color
* and the label stays legible.
*/
export const readableTextColor = (hex: string): '#1F2329' | '#FFFFFF' => {
const luminanceOf = (color: string): number => {
const [r, g, b] = [0, 2, 4].map((offset) => parseInt(color.replace('#', '').slice(offset, offset + 2), 16) / 255);
const linearize = (channel: number): number => (channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4);
return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
};
const background = luminanceOf(hex);
const contrastWith = (ink: string): number => {
const text = luminanceOf(ink);
return (Math.max(background, text) + 0.05) / (Math.min(background, text) + 0.05);
};
return contrastWith('#1F2329') >= contrastWith('#FFFFFF') ? '#1F2329' : '#FFFFFF';
};

View File

@@ -0,0 +1,222 @@
import { readableTextColor } from './colors';
import { buildClassificationBanner, parseClassificationBannersConfig } from './engine';
import type { ClassificationBannersConfig } from './types';
const config: ClassificationBannersConfig = {
version: 1,
enabled: true,
banner: {
style: 'classic',
uppercase: true,
monospace: false,
delimiter: ' // ',
colorMode: 'highest',
fallbackText: 'NO CLASSIFICATION DATA',
fallbackColor: '#6C727A',
},
attributes: [
{
id: 'classification',
source: 'clearance.level',
label: 'Classification level',
showInBanner: true,
showLabel: false,
bannerLabel: '',
labelSeparator: '',
valueSeparator: '/',
sortAlpha: false,
groupThreshold: 0,
multipleLabel: '',
drivesColor: true,
values: [
{ source: 'TS-SCI', label: 'TOP SECRET//SCI', color: '#fce100' },
{ source: 'TS', label: 'TOP SECRET', color: '#ff8c00' },
{ source: 'S', label: 'SECRET', color: '#c8102e' },
{ source: 'C', label: 'CONFIDENTIAL', color: '#0033a0' },
{ source: 'CUI', label: 'CUI', color: '#502b85' },
{ source: 'U', label: 'UNCLASSIFIED', color: '#007a33' },
],
},
{
id: 'sar',
source: 'access.programs',
label: 'Special access programs',
showInBanner: true,
showLabel: true,
bannerLabel: 'SAR',
labelSeparator: '-',
valueSeparator: '/',
sortAlpha: true,
groupThreshold: 4,
multipleLabel: 'MULTIPLE PROGRAMS',
drivesColor: false,
values: [
{ source: 'SAP-1042', label: 'APPLES', color: '#c8102e' },
{ source: 'SAP-2271', label: 'BANANAS', color: '#ff8c00' },
{ source: 'SAP-3380', label: 'ORANGES', color: '#0033a0' },
{ source: 'SAP-4419', label: 'PEACHES', color: '#007a33' },
{ source: 'SAP-5567', label: 'GRAPES', color: '#502b85' },
],
},
{
id: 'relto',
source: 'dissem.relto',
label: 'Releasable to',
showInBanner: true,
showLabel: true,
bannerLabel: 'RELTO',
labelSeparator: ' ',
valueSeparator: '/',
sortAlpha: false,
groupThreshold: 0,
multipleLabel: '',
drivesColor: false,
values: [
{ source: 'USA', label: 'USA', color: '#0033a0' },
{ source: 'FVEY', label: 'FVEY', color: '#007a33' },
{ source: 'NATO', label: 'NATO', color: '#502b85' },
],
},
{
id: 'dissem',
source: 'dissem.controls',
label: 'Dissemination controls',
showInBanner: false,
showLabel: false,
bannerLabel: '',
labelSeparator: '',
valueSeparator: '/',
sortAlpha: true,
groupThreshold: 0,
multipleLabel: '',
drivesColor: false,
values: [
{ source: 'NF', label: 'NOFORN', color: '#c8102e' },
{ source: 'OC', label: 'ORCON', color: '#ff8c00' },
{ source: 'IM', label: 'IMCON', color: '#0033a0' },
],
},
],
};
describe('buildClassificationBanner', () => {
it('assembles the default prototype output', () => {
const banner = buildClassificationBanner(config, [
{ key: 'clearance.level', values: ['TS'] },
{ key: 'access.programs', values: ['SAP-1042', 'SAP-2271', 'SAP-3380'] },
{ key: 'dissem.relto', values: ['USA'] },
]);
expect(banner.text).toBe('TOP SECRET // SAR-APPLES/BANANAS/ORANGES // RELTO USA');
expect(banner.segments.map((s) => s.attrId)).toEqual(['classification', 'sar', 'relto']);
expect(banner.backgroundColor).toBe('#ff8c00');
expect(banner.color).toBe('#1F2329');
expect(banner).toMatchObject({ style: 'classic', uppercase: true, monospace: false });
});
it('collapses to multipleLabel when value count reaches groupThreshold', () => {
const banner = buildClassificationBanner(config, [
{ key: 'clearance.level', values: ['TS'] },
{ key: 'access.programs', values: ['SAP-1042', 'SAP-2271', 'SAP-3380', 'SAP-4419', 'SAP-5567'] },
]);
expect(banner.text).toBe('TOP SECRET // SAR-MULTIPLE PROGRAMS');
});
it('does not collapse below groupThreshold and sorts labels alphabetically when sortAlpha is set', () => {
const banner = buildClassificationBanner(config, [{ key: 'access.programs', values: ['SAP-3380', 'SAP-1042'] }]);
expect(banner.text).toBe('SAR-APPLES/ORANGES');
});
it('picks the most restrictive value color in highest mode (index 0 = highest ranking)', () => {
const banner = buildClassificationBanner(config, [{ key: 'clearance.level', values: ['U', 'TS'] }]);
expect(banner.backgroundColor).toBe('#ff8c00');
});
it('picks the color of the first room value that is mapped in attribute mode', () => {
const attributeModeConfig = { ...config, banner: { ...config.banner, colorMode: 'attribute' as const } };
expect(buildClassificationBanner(attributeModeConfig, [{ key: 'clearance.level', values: ['U', 'TS'] }]).backgroundColor).toBe(
'#007a33',
);
expect(buildClassificationBanner(attributeModeConfig, [{ key: 'clearance.level', values: ['TS', 'U'] }]).backgroundColor).toBe(
'#ff8c00',
);
});
it('excludes attributes with showInBanner disabled', () => {
const banner = buildClassificationBanner(config, [
{ key: 'clearance.level', values: ['S'] },
{ key: 'dissem.controls', values: ['NF'] },
]);
expect(banner.text).toBe('SECRET');
});
it('renders unmapped values of a configured attribute as raw text, after the mapped labels', () => {
const banner = buildClassificationBanner(config, [
{ key: 'clearance.level', values: ['TS'] },
{ key: 'dissem.relto', values: ['USA', 'ACGU'] },
]);
expect(banner.text).toBe('TOP SECRET // RELTO USA/ACGU');
});
it('sorts each group alphabetically when sortAlpha is set, keeping unmapped values last, and counts both toward groupThreshold', () => {
expect(buildClassificationBanner(config, [{ key: 'access.programs', values: ['aaa', 'SAP-3380', 'SAP-1042'] }]).text).toBe(
'SAR-APPLES/ORANGES/aaa',
);
expect(
buildClassificationBanner(config, [{ key: 'access.programs', values: ['SAP-1042', 'SAP-2271', 'SAP-3380', 'cherry'] }]).text,
).toBe('SAR-MULTIPLE PROGRAMS');
});
it('does not let unmapped values drive the color', () => {
const banner = buildClassificationBanner(config, [
{ key: 'clearance.level', values: ['X'] },
{ key: 'dissem.relto', values: ['USA'] },
]);
expect(banner.text).toBe('X // RELTO USA');
expect(banner.backgroundColor).toBe('#6C727A');
});
it('renders the fallback banner when the room only carries attributes not present in the config', () => {
const banner = buildClassificationBanner(config, [{ key: 'country', values: ['USA'] }]);
expect(banner).toMatchObject({
text: 'NO CLASSIFICATION DATA',
segments: [],
backgroundColor: '#6C727A',
color: '#FFFFFF',
});
});
});
describe('readableTextColor', () => {
it('uses dark text over light backgrounds and white text over dark backgrounds', () => {
expect(readableTextColor('#fce100')).toBe('#1F2329');
expect(readableTextColor('#FFFFFF')).toBe('#1F2329');
expect(readableTextColor('#c8102e')).toBe('#FFFFFF');
expect(readableTextColor('#0033a0')).toBe('#FFFFFF');
});
it('picks the higher-contrast ink on mid-range backgrounds', () => {
expect(readableTextColor('#999999')).toBe('#1F2329');
});
});
describe('parseClassificationBannersConfig', () => {
it('parses a valid config', () => {
expect(parseClassificationBannersConfig(JSON.stringify(config))).toEqual(config);
});
it.each([
['empty string (unset setting)', ''],
['invalid JSON', 'not json'],
])('returns null for %s', (_name, raw) => {
expect(parseClassificationBannersConfig(raw)).toBeNull();
});
});

View File

@@ -0,0 +1,94 @@
import type { IAbacAttributeDefinition } from '@rocket.chat/core-typings';
import { isTruthy } from '@rocket.chat/tools';
import { readableTextColor } from './colors';
import type {
ClassificationBannerAttribute,
ClassificationBannerPayload,
ClassificationBannerSegment,
ClassificationBannersConfig,
} from './types';
export const parseClassificationBannersConfig = (raw: string): ClassificationBannersConfig | null => {
try {
return JSON.parse(raw) as ClassificationBannersConfig;
} catch {
return null;
}
};
const buildSegment = (
attribute: ClassificationBannerAttribute,
roomAttributes: IAbacAttributeDefinition[],
): ClassificationBannerSegment | null => {
const roomValues = roomAttributes.find(({ key }) => key === attribute.source)?.values ?? [];
const mapped = attribute.values.filter(({ source }) => roomValues.includes(source));
const unmapped = roomValues.filter((value) => !attribute.values.some(({ source }) => source === value)).map((label) => ({ label }));
if (attribute.sortAlpha) {
const byLabel = (a: { label: string }, b: { label: string }) => a.label.localeCompare(b.label);
mapped.sort(byLabel);
unmapped.sort(byLabel);
}
const matched = [...mapped, ...unmapped];
if (!matched.length) {
return null;
}
const body =
attribute.groupThreshold > 0 && matched.length >= attribute.groupThreshold
? attribute.multipleLabel
: matched.map(({ label }) => label).join(attribute.valueSeparator);
return {
attrId: attribute.id,
text: attribute.showLabel ? `${attribute.bannerLabel}${attribute.labelSeparator}${body}` : body,
};
};
const resolveColor = ({ attributes, banner }: ClassificationBannersConfig, roomAttributes: IAbacAttributeDefinition[]): string => {
const driver = attributes.find(({ drivesColor }) => drivesColor) ?? attributes[0];
const roomValues = roomAttributes.find(({ key }) => key === driver.source)?.values ?? [];
// values are ranked most restrictive first, so in 'highest' mode the first match wins;
// in 'attribute' mode the room's own value order decides instead
const match =
banner.colorMode === 'highest'
? driver.values.find(({ source }) => roomValues.includes(source))
: roomValues.map((value) => driver.values.find(({ source }) => source === value)).find(isTruthy);
return match?.color ?? banner.fallbackColor;
};
export const buildClassificationBanner = (
config: ClassificationBannersConfig,
roomAttributes: IAbacAttributeDefinition[],
): ClassificationBannerPayload => {
const { banner } = config;
const base = {
style: banner.style,
uppercase: banner.uppercase,
monospace: banner.monospace,
} as const;
const segments = config.attributes
.filter(({ showInBanner }) => showInBanner)
.map((attribute) => buildSegment(attribute, roomAttributes))
.filter(isTruthy);
if (!segments.length) {
return {
...base,
text: banner.fallbackText,
segments: [],
backgroundColor: banner.fallbackColor,
color: readableTextColor(banner.fallbackColor),
};
}
const backgroundColor = resolveColor(config, roomAttributes);
return {
...base,
text: segments.map(({ text }) => text).join(banner.delimiter),
segments,
backgroundColor,
color: readableTextColor(backgroundColor),
};
};

View File

@@ -0,0 +1,79 @@
/**
* @jest-environment node
*/
import { ajv } from '@rocket.chat/rest-typings';
import type { ClassificationBannersConfig } from './types';
import schema from '../../../../../../../ee/packages/abac/docs/classification-banners.schema.json';
const validate = ajv.compile(schema);
const validConfig: ClassificationBannersConfig & { $schema: string } = {
$schema: 'https://rocket.chat/schemas/classification-banners/v1.json',
version: 1,
enabled: true,
banner: {
style: 'classic',
uppercase: true,
monospace: false,
delimiter: ' // ',
colorMode: 'highest',
fallbackText: 'NO CLASSIFICATION DATA',
fallbackColor: '#6C727A',
},
attributes: [
{
id: 'classification',
source: 'clearance.level',
label: 'Classification level',
showInBanner: true,
showLabel: false,
bannerLabel: '',
labelSeparator: '',
valueSeparator: '/',
sortAlpha: false,
groupThreshold: 0,
multipleLabel: '',
drivesColor: true,
values: [
{ source: 'TS', label: 'TOP SECRET', color: '#ff8c00' },
{ source: 'U', label: 'UNCLASSIFIED', color: '#007a33' },
],
},
],
};
const { banner } = validConfig;
const [attribute] = validConfig.attributes;
const [value] = attribute.values;
describe('classification banners JSON schema (v1 enforcement contract)', () => {
it('accepts a complete document typed as ClassificationBannersConfig', () => {
expect(validate(validConfig)).toBe(true);
});
it.each([
['wrong version', { ...validConfig, version: 2 }],
['missing banner option (colorMode)', { ...validConfig, banner: { ...banner, colorMode: undefined } }],
['empty delimiter', { ...validConfig, banner: { ...banner, delimiter: '' } }],
['oversized delimiter', { ...validConfig, banner: { ...banner, delimiter: 'x'.repeat(9) } }],
['empty fallbackText', { ...validConfig, banner: { ...banner, fallbackText: '' } }],
['malformed fallbackColor', { ...validConfig, banner: { ...banner, fallbackColor: 'red' } }],
['unknown banner option', { ...validConfig, banner: { ...banner, position: 'top' } }],
['unknown top-level property', { ...validConfig, source: 'idp' }],
['empty attributes', { ...validConfig, attributes: [] }],
['identical duplicate attributes', { ...validConfig, attributes: [attribute, attribute] }],
['missing attribute field (drivesColor)', { ...validConfig, attributes: [{ ...attribute, drivesColor: undefined }] }],
['uppercase attribute id', { ...validConfig, attributes: [{ ...attribute, id: 'Classification' }] }],
['invalid labelSeparator', { ...validConfig, attributes: [{ ...attribute, labelSeparator: '::' }] }],
['invalid valueSeparator', { ...validConfig, attributes: [{ ...attribute, valueSeparator: '|' }] }],
['groupThreshold of 1', { ...validConfig, attributes: [{ ...attribute, groupThreshold: 1 }] }],
['groupThreshold above 20', { ...validConfig, attributes: [{ ...attribute, groupThreshold: 21 }] }],
['empty values', { ...validConfig, attributes: [{ ...attribute, values: [] }] }],
['identical duplicate values', { ...validConfig, attributes: [{ ...attribute, values: [value, value] }] }],
['value with 3-digit color', { ...validConfig, attributes: [{ ...attribute, values: [{ ...value, color: '#fff' }] }] }],
['value missing label', { ...validConfig, attributes: [{ ...attribute, values: [{ ...value, label: undefined }] }] }],
])('rejects %s', (_name, config) => {
expect(validate(config)).toBe(false);
});
});

View File

@@ -0,0 +1,53 @@
export type ClassificationBannerValue = {
source: string;
label: string;
color: string;
};
export type ClassificationBannerAttribute = {
id: string;
source: string;
label: string;
showInBanner: boolean;
showLabel: boolean;
bannerLabel: string;
labelSeparator: string;
valueSeparator: string;
sortAlpha: boolean;
groupThreshold: number;
multipleLabel: string;
drivesColor: boolean;
values: ClassificationBannerValue[];
};
export type ClassificationBannerStyle = 'classic';
export type ClassificationBannersConfig = {
version: 1;
enabled: boolean;
banner: {
style: ClassificationBannerStyle;
uppercase: boolean;
monospace: boolean;
delimiter: string;
colorMode: 'highest' | 'attribute';
fallbackText: string;
fallbackColor: string;
};
attributes: ClassificationBannerAttribute[];
};
export type ClassificationBannerSegment = {
attrId: string;
text: string;
};
export type ClassificationBannerPayload = {
text: string;
segments: ClassificationBannerSegment[];
backgroundColor: string;
color: string;
style: ClassificationBannerStyle;
uppercase: boolean;
monospace: boolean;
};