From ea471451f8bc774f89e533fd66793d31f5b16557 Mon Sep 17 00:00:00 2001 From: Alexandre Alves Date: Thu, 23 Oct 2025 10:05:58 +0100 Subject: [PATCH] backport pr 15701 --- pkg/rancher-prime/config/navigation.ts | 10 +++++-- pkg/rancher-prime/index.test.ts | 40 ++++++++++++++++++++++++++ pkg/rancher-prime/index.ts | 2 +- shell/store/features.js | 1 + 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 pkg/rancher-prime/index.test.ts diff --git a/pkg/rancher-prime/config/navigation.ts b/pkg/rancher-prime/config/navigation.ts index f5e5e3494c..caa7729348 100644 --- a/pkg/rancher-prime/config/navigation.ts +++ b/pkg/rancher-prime/config/navigation.ts @@ -1,5 +1,7 @@ import { IPlugin } from '@shell/core/types'; import { PRODUCT_SETTING_NAME, SETTING_PAGE_NAME } from './constants'; +import { IF_HAVE } from '@shell/store/type-map'; +import { SCC } from '@shell/store/features'; // Product configuration export function init($plugin: IPlugin, store: any) { @@ -9,9 +11,11 @@ export function init($plugin: IPlugin, store: any) { } = $plugin.DSL(store, PRODUCT_SETTING_NAME); virtualType({ - labelKey: 'registration.navigation.label', - name: SETTING_PAGE_NAME, - route: { name: SETTING_PAGE_NAME }, + ifHave: IF_HAVE.ADMIN, + ifFeature: SCC, + labelKey: 'registration.navigation.label', + name: SETTING_PAGE_NAME, + route: { name: SETTING_PAGE_NAME }, }); basicType([SETTING_PAGE_NAME]); diff --git a/pkg/rancher-prime/index.test.ts b/pkg/rancher-prime/index.test.ts new file mode 100644 index 0000000000..4f1eeb3d9d --- /dev/null +++ b/pkg/rancher-prime/index.test.ts @@ -0,0 +1,40 @@ +import { SCC } from '@shell/store/features'; +const { IF_HAVE } = require('@shell/store/type-map'); + +jest.doMock('@rancher/auto-import', () => ({ importTypes: jest.fn() }), { virtual: true }); + +describe('extension: rancher-prime', () => { + it('should enable routing for admin users with SCC feature', async() => { + const plugin = await import('./index'); // initialized after the mock + const virtualTypeSpy = jest.fn(); + const basicTypeSpy = jest.fn(); + const dslMock = jest.fn().mockReturnValue({ + virtualType: virtualTypeSpy, + basicType: basicTypeSpy + }); + + const pluginMock = { + environment: { isPrime: true }, + addProduct: jest.fn(), + addRoutes: jest.fn(), + addPanel: jest.fn(), + addNavHooks: jest.fn(), + register: jest.fn(), // Used in installDocHandler + metadata: {}, + DSL: dslMock + } as any; + + plugin.default(pluginMock); // basic extension import + pluginMock.addProduct.mock.calls[0][0].init(pluginMock, {}); // force init to trigger as in @rancher/shell + + expect(pluginMock.addProduct).toHaveBeenCalledWith( + expect.objectContaining({ init: expect.any(Function) }) + ); + expect(virtualTypeSpy).toHaveBeenCalledWith( + expect.objectContaining({ + ifHave: IF_HAVE.ADMIN, + ifFeature: SCC + }) + ); + }); +}); diff --git a/pkg/rancher-prime/index.ts b/pkg/rancher-prime/index.ts index b1ac885273..eb3998be09 100644 --- a/pkg/rancher-prime/index.ts +++ b/pkg/rancher-prime/index.ts @@ -53,8 +53,8 @@ const poolRegistration = (store: Store) => { if (store.state['managementReady']) { setNotification(store); clearInterval(id); + attempts -= 1; } - attempts -= 1; }, 1000); }; diff --git a/shell/store/features.js b/shell/store/features.js index 884b6f452c..d2eb4dcbba 100644 --- a/shell/store/features.js +++ b/shell/store/features.js @@ -37,6 +37,7 @@ export const STEVE_CACHE = create('ui-sql-cache', false); export const UIEXTENSION = create('uiextension', true); export const PROVISIONING_PRE_BOOTSTRAP = create('provisioningprebootstrap', false); export const SCHEDULING_CUSTOMIZATION = create(SCHEDULING_CUSTOMIZATION_FEATURE, false); +export const SCC = create('rancher-scc-registration-extension', true); // Not currently used.. no point defining ones we don't use // export const EMBEDDED_CLUSTER_API = create('embedded-cluster-api', true);