Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/39646-security-topics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/plugin-security': patch
---

feat(plugin-security): the upgrade reports' notification topics carry their texts as catalog keys in eleven languages and list the variables a template can use

Clause-②: no
Metadata-protocol: none

Who sees it: an administrator writing a notification template, or a notification preference, for the two topics the upgrade reports raise (`security.access_upgrade`, `system.upgrade_impact`).

- **Before:** both topics were offered with an English name and description only, and with no variables, so the template form showed the generic ones.
- **Now:** the name and description of each topic, and the description of each variable, come from this package's own translation bundle in all eleven languages, with the English text as the fallback. Each topic lists the payload members its report sends as text: `title`, `body`, and each finding count under `counts` (for example `{{ counts.reEnablements }}`).
- The texts are shown in the administrator's language only once the preference-options door passes the caller's locale (#39969); until then that door serves the English fallback.
- Nothing changes in what the reports send or to whom.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* [#39641] The two upgrade reports' topics are described to the messaging
* service's topic registry at `kernel:ready`: a real `MessagingService`
* registry behind the `messaging` service, so its own checks judge them.
*
* [#39646] Each variable the access upgrade topic declares renders against
* the payload this report really emitted.
*/

import { afterEach, describe, expect, it, vi } from 'vitest';
Expand All @@ -34,15 +37,16 @@ import {
SysMetadataObject, SysMetadataHistoryObject, SysMetadataCommitObject, SysMetadataAuditObject,
} from '@objectstack/metadata-core';
import { resetPlatformAdminEmailMemo } from '@objectstack/core';
import { MessagingService } from '@objectstack/service-messaging';
import { interpolate, MessagingService } from '@objectstack/service-messaging';
import { SysMember, SysOrganization, SysUser } from '@objectstack/platform-objects/identity';
import { SysMetadataActivation } from '@objectstack/platform-objects/system';

import { SecurityPlugin } from './security-plugin.js';
import { SysUserPermissionSet } from './objects/sys-user-permission-set.object.js';
import { ACCESS_UPGRADE_TOPIC } from './access-upgrade-report.js';
import { UPGRADE_IMPACT_TOPIC } from './upgrade-impact-report.js';
import { UPGRADE_REPORT_NOTIFICATION_TOPICS } from './security-plugin-start-hooks.js';
import { UPGRADE_REPORT_NOTIFICATION_TOPICS } from './upgrade-report-notification-topics.js';
import { expectDeclaredVariablesRender } from './upgrade-report-topic-variables.testkit.js';

const SYS = { isSystem: true } as const;
const POSTURE_ENV = 'OS_TENANCY_POSTURE';
Expand Down Expand Up @@ -179,6 +183,13 @@ describe('[ADR-0126 §6 wall 3] the access upgrade report, wired at kernel:boots
expect(logger.error.mock.calls.some(([m]: any[]) => String(m).includes('no longer shipped under that name'))).toBe(true);
});

it('[#39646] every variable the topic declares renders against the payload this report sent', async () => {
const { emit } = await boot('single', true);
const input = (emit.mock.calls[0] as any[])[0];
expectDeclaredVariablesRender(UPGRADE_REPORT_NOTIFICATION_TOPICS.find((d) => d.topic === ACCESS_UPGRADE_TOPIC)!, input.payload, interpolate);
expect(input.payload.counts.reEnablements).toBe(1);
});

for (const posture of ['isolated', 'group'] as const) {
it(`${posture}: the same finding is raised to the operator alone, in the log — no emit, no organization told`, async () => {
const { emit, logger } = await boot(posture, true);
Expand Down Expand Up @@ -244,6 +255,7 @@ describe('the upgrade reports describe their topics to the messaging service at
for (const d of UPGRADE_REPORT_NOTIFICATION_TOPICS) {
expect(rendered.find((t) => t.topic === d.topic)).toEqual({
topic: d.topic, label: d.label.fallback, description: d.description.fallback,
variables: d.variables.map((v) => ({ name: v.name, description: v.description.fallback })),
});
}
expect(logger.warn.mock.calls.some(([m]: any[]) => String(m).includes('notification topics were NOT described'))).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ import { reportCatalogReferences } from './catalog-reference-report.js';
import { backfillStoredPermissionSetPackagesAtBoot } from './stored-permission-set-package-backfill.js';
import { createPositionRenameCarryRuns } from './position-renamed-holder-carry.js';
import {
ACCESS_UPGRADE_TOPIC,
reportAccessUpgrade,
SHARING_RULES_SERVICE,
type AccessUpgradeNotifier,
type DeclaredSharingRuleReader,
} from './access-upgrade-report.js';
import { reportUpgradeImpact, SETTINGS_SERVICE, UPGRADE_IMPACT_TOPIC, type SettingsManifestReader } from './upgrade-impact-report.js';
import { reportUpgradeImpact, SETTINGS_SERVICE, type SettingsManifestReader } from './upgrade-impact-report.js';
import { UPGRADE_REPORT_NOTIFICATION_TOPICS } from './upgrade-report-notification-topics.js';
import { applyManagedWriteDenies } from './managed-object-write-denies.js';
import { reportPackagedPermissionSetOverlays } from './packaged-permission-set-overlay-detection.js';
import { registerObjectPostureGate } from './object-posture-gate.js';
Expand Down Expand Up @@ -100,40 +100,6 @@ export interface StartHooksHost {
deploymentOrgScopingEntitlement: SecurityPlugin['deploymentOrgScopingEntitlement'];
}

/**
* The topics the two upgrade reports raise, as the messaging service's topic
* registry describes them to an administrator picking a topic (ruling
* 7409753977 on #39412: each sending feature registers its own topics). The
* part of `@objectstack/service-messaging`'s `NotificationTopicDescriptor`
* they fill, declared structurally: this package takes no dependency on
* service-messaging (as `AccessUpgradeNotifier`), and the registry checks
* each descriptor itself.
*/
export const UPGRADE_REPORT_NOTIFICATION_TOPICS: ReadonlyArray<{
readonly topic: string;
readonly label: { readonly fallback: string };
readonly description: { readonly fallback: string };
}> = [
{
topic: ACCESS_UPGRADE_TOPIC,
label: { fallback: 'Access choices an upgrade affected' },
description: {
fallback:
'At startup after an upgrade, a permission set, position or sharing rule the organization switched off, ' +
'cloned or wrote no longer matches what the installed packages ship; the administrators are told.',
},
},
{
topic: UPGRADE_IMPACT_TOPIC,
label: { fallback: 'Customizations an upgrade affected' },
description: {
fallback:
'At startup after an upgrade, a flow, action or webhook switch, a stored override, an object extension, a ' +
'navigation entry or a stored setting no longer matches what the installed packages ship; the administrators are told.',
},
},
];

/** The registrations `SecurityPlugin#start` makes after the authorization middleware, in that order; the comments inside are their contract. */
export function registerStartHooks(
this: Pick<StartHooksHost, 'bootstrapPermissionSets' | 'claimTargetAdminUserId' | 'declareEveryone' | 'deploymentAcceptance' | 'deploymentOrgScopingEntitlement' | 'metadata' | 'tenancyPosture'>,
Expand Down
29 changes: 27 additions & 2 deletions packages/plugins/plugin-security/src/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ import {
deBuiltinPositions,
koBuiltinPositions,
} from './builtin-positions.js';
import {
enUpgradeReportTopicMessages,
zhCNUpgradeReportTopicMessages,
jaJPUpgradeReportTopicMessages,
esESUpgradeReportTopicMessages,
zhHantUpgradeReportTopicMessages,
arUpgradeReportTopicMessages,
frUpgradeReportTopicMessages,
ptBRUpgradeReportTopicMessages,
ruUpgradeReportTopicMessages,
deUpgradeReportTopicMessages,
koUpgradeReportTopicMessages,
} from './upgrade-report-topics.js';

/**
* ## The provenance companions are READ here, not merely recorded
Expand Down Expand Up @@ -91,58 +104,70 @@ const enSource: TranslationData = { objects: enObjects };
* positions' (`positions`) are hand-authored beside the generated objects
* (`permission-sets.ts` says why). They sit outside `withSourceFallback`'s
* inputs: `enSource` carries neither group, so no leaf of theirs is judged
* stale.
* stale. The upgrade reports' topic texts (`messages`,
* `upgrade-report-topics.ts`) are hand-authored the same way, in every locale
* including `en`, whose entries are the descriptors' own fallbacks.
*/
export const SecurityTranslations: TranslationBundle = {
en: enSource,
en: { ...enSource, messages: enUpgradeReportTopicMessages },
'zh-CN': {
...withSourceFallback({ objects: zhCNObjects }, enSource, undefined, zhCNGeneratedSourceHashes),
permissions: zhCNPermissionSets,
positions: zhCNBuiltinPositions,
messages: zhCNUpgradeReportTopicMessages,
},
'ja-JP': {
...withSourceFallback({ objects: jaJPObjects }, enSource, undefined, jaJPGeneratedSourceHashes),
permissions: jaJPPermissionSets,
positions: jaJPBuiltinPositions,
messages: jaJPUpgradeReportTopicMessages,
},
'es-ES': {
...withSourceFallback({ objects: esESObjects }, enSource, undefined, esESGeneratedSourceHashes),
permissions: esESPermissionSets,
positions: esESBuiltinPositions,
messages: esESUpgradeReportTopicMessages,
},
'zh-Hant': {
...withSourceFallback({ objects: zhHantObjects }, enSource, undefined, zhHantGeneratedSourceHashes),
permissions: zhHantPermissionSets,
positions: zhHantBuiltinPositions,
messages: zhHantUpgradeReportTopicMessages,
},
'ar': {
...withSourceFallback({ objects: arObjects }, enSource, undefined, arGeneratedSourceHashes),
permissions: arPermissionSets,
positions: arBuiltinPositions,
messages: arUpgradeReportTopicMessages,
},
'fr': {
...withSourceFallback({ objects: frObjects }, enSource, undefined, frGeneratedSourceHashes),
permissions: frPermissionSets,
positions: frBuiltinPositions,
messages: frUpgradeReportTopicMessages,
},
'pt-BR': {
...withSourceFallback({ objects: ptBRObjects }, enSource, undefined, ptBRGeneratedSourceHashes),
permissions: ptBRPermissionSets,
positions: ptBRBuiltinPositions,
messages: ptBRUpgradeReportTopicMessages,
},
'ru': {
...withSourceFallback({ objects: ruObjects }, enSource, undefined, ruGeneratedSourceHashes),
permissions: ruPermissionSets,
positions: ruBuiltinPositions,
messages: ruUpgradeReportTopicMessages,
},
'de': {
...withSourceFallback({ objects: deObjects }, enSource, undefined, deGeneratedSourceHashes),
permissions: dePermissionSets,
positions: deBuiltinPositions,
messages: deUpgradeReportTopicMessages,
},
'ko': {
...withSourceFallback({ objects: koObjects }, enSource, undefined, koGeneratedSourceHashes),
permissions: koPermissionSets,
positions: koBuiltinPositions,
messages: koUpgradeReportTopicMessages,
},
};
Loading
Loading