Skip to content

Commit a23fe96

Browse files
authored
backport pr 15701 (#15704)
1 parent ed9fadb commit a23fe96

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

pkg/rancher-prime/config/navigation.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { IPlugin } from '@shell/core/types';
22
import { PRODUCT_SETTING_NAME, SETTING_PAGE_NAME } from './constants';
3+
import { IF_HAVE } from '@shell/store/type-map';
4+
import { SCC } from '@shell/store/features';
35

46
// Product configuration
57
export function init($plugin: IPlugin, store: any) {
@@ -9,9 +11,11 @@ export function init($plugin: IPlugin, store: any) {
911
} = $plugin.DSL(store, PRODUCT_SETTING_NAME);
1012

1113
virtualType({
12-
labelKey: 'registration.navigation.label',
13-
name: SETTING_PAGE_NAME,
14-
route: { name: SETTING_PAGE_NAME },
14+
ifHave: IF_HAVE.ADMIN,
15+
ifFeature: SCC,
16+
labelKey: 'registration.navigation.label',
17+
name: SETTING_PAGE_NAME,
18+
route: { name: SETTING_PAGE_NAME },
1519
});
1620

1721
basicType([SETTING_PAGE_NAME]);

pkg/rancher-prime/index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { SCC } from '@shell/store/features';
2+
const { IF_HAVE } = require('@shell/store/type-map');
3+
4+
jest.doMock('@rancher/auto-import', () => ({ importTypes: jest.fn() }), { virtual: true });
5+
6+
describe('extension: rancher-prime', () => {
7+
it('should enable routing for admin users with SCC feature', async() => {
8+
const plugin = await import('./index'); // initialized after the mock
9+
const virtualTypeSpy = jest.fn();
10+
const basicTypeSpy = jest.fn();
11+
const dslMock = jest.fn().mockReturnValue({
12+
virtualType: virtualTypeSpy,
13+
basicType: basicTypeSpy
14+
});
15+
16+
const pluginMock = {
17+
environment: { isPrime: true },
18+
addProduct: jest.fn(),
19+
addRoutes: jest.fn(),
20+
addPanel: jest.fn(),
21+
addNavHooks: jest.fn(),
22+
register: jest.fn(), // Used in installDocHandler
23+
metadata: {},
24+
DSL: dslMock
25+
} as any;
26+
27+
plugin.default(pluginMock); // basic extension import
28+
pluginMock.addProduct.mock.calls[0][0].init(pluginMock, {}); // force init to trigger as in @rancher/shell
29+
30+
expect(pluginMock.addProduct).toHaveBeenCalledWith(
31+
expect.objectContaining({ init: expect.any(Function) })
32+
);
33+
expect(virtualTypeSpy).toHaveBeenCalledWith(
34+
expect.objectContaining({
35+
ifHave: IF_HAVE.ADMIN,
36+
ifFeature: SCC
37+
})
38+
);
39+
});
40+
});

pkg/rancher-prime/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const poolRegistration = (store: Store<any>) => {
5353
if (store.state['managementReady']) {
5454
setNotification(store);
5555
clearInterval(id);
56+
attempts -= 1;
5657
}
57-
attempts -= 1;
5858
}, 1000);
5959
};
6060

shell/store/features.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const STEVE_CACHE = create('ui-sql-cache', false);
3737
export const UIEXTENSION = create('uiextension', true);
3838
export const PROVISIONING_PRE_BOOTSTRAP = create('provisioningprebootstrap', false);
3939
export const SCHEDULING_CUSTOMIZATION = create(SCHEDULING_CUSTOMIZATION_FEATURE, false);
40+
export const SCC = create('rancher-scc-registration-extension', true);
4041

4142
// Not currently used.. no point defining ones we don't use
4243
// export const EMBEDDED_CLUSTER_API = create('embedded-cluster-api', true);

0 commit comments

Comments
 (0)