@origen-ui/admin-cli 1.1.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -9
- package/package.json +26 -2
- package/templates/current/clean/.node-version +1 -0
- package/templates/current/clean/CHANGELOG.md +125 -0
- package/templates/current/clean/README.md +2 -1
- package/templates/current/clean/component-catalog.json +58 -17
- package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/clean/package.json +39 -25
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/pnpm-workspace.yaml +18 -0
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/scripts/demo-api.ts +88 -12
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/remove-examples.mjs +4 -4
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/clean/src/api/generated/http-client.ts +28 -26
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/clean/src/app/errorMessage.ts +53 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +39 -0
- package/templates/current/clean/src/app/menu.ts +48 -12
- package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
- package/templates/current/clean/src/demo-api.spec.ts +314 -3
- package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
- package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/clean/src/layouts/TopBar.vue +37 -6
- package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/clean/src/locales/en-US.json +30 -3
- package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/clean/src/locales/index.ts +39 -26
- package/templates/current/clean/src/locales/zh-CN.json +30 -3
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/clean/src/locales/zh-TW.json +30 -3
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +10 -16
- package/templates/current/clean/src/router/componentCache.ts +12 -0
- package/templates/current/clean/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/clean/src/router/paths.spec.ts +50 -0
- package/templates/current/clean/src/router/paths.ts +21 -0
- package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/clean/src/router/routeQuery.ts +4 -1
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/templates/og-table.ts +2 -4
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +55 -8
- package/templates/current/clean/vite.config.ts +30 -0
- package/templates/current/examples/.node-version +1 -0
- package/templates/current/examples/CHANGELOG.md +125 -0
- package/templates/current/examples/README.md +2 -1
- package/templates/current/examples/component-catalog.json +58 -17
- package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/examples/package.json +39 -25
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/pnpm-workspace.yaml +18 -0
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/examples/scripts/demo-api.ts +88 -12
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/remove-examples.mjs +4 -4
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/examples/src/api/generated/http-client.ts +28 -26
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/examples/src/app/errorMessage.ts +53 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +39 -0
- package/templates/current/examples/src/app/menu.ts +48 -12
- package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
- package/templates/current/examples/src/demo-api.spec.ts +314 -3
- package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/examples/src/layouts/TopBar.vue +37 -6
- package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/examples/src/locales/en-US.json +30 -3
- package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/examples/src/locales/index.ts +39 -26
- package/templates/current/examples/src/locales/zh-CN.json +30 -3
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/examples/src/locales/zh-TW.json +30 -3
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/examples/src/main.ts +24 -22
- package/templates/current/examples/src/router/bootstrap.ts +10 -16
- package/templates/current/examples/src/router/componentCache.ts +18 -0
- package/templates/current/examples/src/router/componentRegistry.ts +1 -18
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/examples/src/router/paths.spec.ts +50 -0
- package/templates/current/examples/src/router/paths.ts +21 -0
- package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/examples/src/router/routeQuery.ts +4 -1
- package/templates/current/examples/src/router/staticRoutes.ts +3 -3
- package/templates/current/examples/src/templates/og-table.ts +2 -4
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +55 -8
- package/templates/current/examples/vite.config.ts +30 -0
|
@@ -32,7 +32,7 @@ describe('admin demo API', () => {
|
|
|
32
32
|
api.handle({
|
|
33
33
|
method: 'POST',
|
|
34
34
|
path: '/api/auth/login',
|
|
35
|
-
body: { username: 'admin', password: 'wrong' },
|
|
35
|
+
body: { username: 'demo-admin', password: 'wrong' },
|
|
36
36
|
}).body,
|
|
37
37
|
).toMatchObject({ code: 40101, data: null })
|
|
38
38
|
const login = data<{
|
|
@@ -43,7 +43,7 @@ describe('admin demo API', () => {
|
|
|
43
43
|
api.handle({
|
|
44
44
|
method: 'POST',
|
|
45
45
|
path: '/auth/login',
|
|
46
|
-
body: { username: 'admin', password: '
|
|
46
|
+
body: { username: 'demo-admin', password: 'demo-password' },
|
|
47
47
|
}),
|
|
48
48
|
)
|
|
49
49
|
expect(login.accessToken).toBe('demo-admin-token')
|
|
@@ -52,7 +52,7 @@ describe('admin demo API', () => {
|
|
|
52
52
|
expect(api.handle({ method: 'GET', path: '/auth/profile' }).body.code).toBe(40101)
|
|
53
53
|
expect(
|
|
54
54
|
data<{ user: { username: string } }>(request(api, 'GET', '/auth/profile')).user.username,
|
|
55
|
-
).toBe('admin')
|
|
55
|
+
).toBe('demo-admin')
|
|
56
56
|
expect(
|
|
57
57
|
data<{ token: string }>(
|
|
58
58
|
api.handle({
|
|
@@ -165,3 +165,314 @@ describe('admin demo API', () => {
|
|
|
165
165
|
expect(data<{ total: number }>(request(restarted, 'GET', '/system/roles')).total).toBe(2)
|
|
166
166
|
})
|
|
167
167
|
})
|
|
168
|
+
|
|
169
|
+
describe('demo menu guardrails', () => {
|
|
170
|
+
it('rejects button menus whose parent is missing or not a page', () => {
|
|
171
|
+
const api = createDemoApi()
|
|
172
|
+
expect(
|
|
173
|
+
request(api, 'POST', '/system/menus', {
|
|
174
|
+
kind: 'button',
|
|
175
|
+
code: 'ghost-button',
|
|
176
|
+
title: 'Ghost',
|
|
177
|
+
permission: 'system:demo:ghost',
|
|
178
|
+
}).body.code,
|
|
179
|
+
).toBe(40001)
|
|
180
|
+
expect(
|
|
181
|
+
request(api, 'POST', '/system/menus', {
|
|
182
|
+
kind: 'button',
|
|
183
|
+
parentId: 'menu-system',
|
|
184
|
+
code: 'ghost-button',
|
|
185
|
+
title: 'Ghost',
|
|
186
|
+
permission: 'system:demo:ghost',
|
|
187
|
+
}).body.code,
|
|
188
|
+
).toBe(40001)
|
|
189
|
+
expect(
|
|
190
|
+
request(api, 'POST', '/system/menus', {
|
|
191
|
+
kind: 'button',
|
|
192
|
+
parentId: 'menu-nowhere',
|
|
193
|
+
code: 'ghost-button',
|
|
194
|
+
title: 'Ghost',
|
|
195
|
+
permission: 'system:demo:ghost',
|
|
196
|
+
}).body.code,
|
|
197
|
+
).toBe(40001)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('creates button menus under page parents, persists titleKey, and enforces version races', () => {
|
|
201
|
+
const api = createDemoApi()
|
|
202
|
+
const created = data<{ id: string, version: number, titleKey?: string }>(
|
|
203
|
+
request(api, 'POST', '/system/menus', {
|
|
204
|
+
kind: 'button',
|
|
205
|
+
parentId: 'menu-dashboard',
|
|
206
|
+
code: 'dashboard-export',
|
|
207
|
+
title: 'Export',
|
|
208
|
+
permission: 'workspace:dashboard:export',
|
|
209
|
+
titleKey: 'menus.export.title',
|
|
210
|
+
}),
|
|
211
|
+
)
|
|
212
|
+
expect(created.version).toBe(1)
|
|
213
|
+
expect(created.titleKey).toBe('menus.export.title')
|
|
214
|
+
const stale = request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
215
|
+
kind: 'button',
|
|
216
|
+
parentId: 'menu-dashboard',
|
|
217
|
+
code: 'dashboard-export',
|
|
218
|
+
title: 'Export v2',
|
|
219
|
+
permission: 'workspace:dashboard:export',
|
|
220
|
+
version: 0,
|
|
221
|
+
})
|
|
222
|
+
expect(stale.body.code).toBe(40901)
|
|
223
|
+
const fresh = data<{ version: number }>(
|
|
224
|
+
request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
225
|
+
kind: 'button',
|
|
226
|
+
parentId: 'menu-dashboard',
|
|
227
|
+
code: 'dashboard-export',
|
|
228
|
+
title: 'Export v2',
|
|
229
|
+
permission: 'workspace:dashboard:export',
|
|
230
|
+
version: 1,
|
|
231
|
+
}),
|
|
232
|
+
)
|
|
233
|
+
expect(fresh.version).toBe(2)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('rejects page and directory children under button menus on POST and PUT', () => {
|
|
237
|
+
const api = createDemoApi()
|
|
238
|
+
const button = data<{ id: string }>(
|
|
239
|
+
request(api, 'POST', '/system/menus', {
|
|
240
|
+
kind: 'button',
|
|
241
|
+
parentId: 'menu-dashboard',
|
|
242
|
+
code: 'dashboard-export-child-test',
|
|
243
|
+
title: 'Export',
|
|
244
|
+
permission: 'workspace:dashboard:export',
|
|
245
|
+
}),
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
for (const kind of ['page', 'directory'] as const) {
|
|
249
|
+
expect(
|
|
250
|
+
request(api, 'POST', '/system/menus', {
|
|
251
|
+
kind,
|
|
252
|
+
parentId: button.id,
|
|
253
|
+
code: `invalid-${kind}-post`,
|
|
254
|
+
title: `Invalid ${kind}`,
|
|
255
|
+
}).body.code,
|
|
256
|
+
).toBe(40001)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const page = data<{ id: string }>(
|
|
260
|
+
request(api, 'POST', '/system/menus', {
|
|
261
|
+
kind: 'page',
|
|
262
|
+
code: 'page-for-button-parent-test',
|
|
263
|
+
title: 'Page for button parent test',
|
|
264
|
+
path: '/page-for-button-parent-test',
|
|
265
|
+
componentKey: 'dashboard',
|
|
266
|
+
}),
|
|
267
|
+
)
|
|
268
|
+
const directory = data<{ id: string }>(
|
|
269
|
+
request(api, 'POST', '/system/menus', {
|
|
270
|
+
kind: 'directory',
|
|
271
|
+
code: 'directory-for-button-parent-test',
|
|
272
|
+
title: 'Directory for button parent test',
|
|
273
|
+
}),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
for (const menu of [page, directory]) {
|
|
277
|
+
expect(
|
|
278
|
+
request(api, 'PUT', `/system/menus/${menu.id}`, {
|
|
279
|
+
kind: menu === page ? 'page' : 'directory',
|
|
280
|
+
parentId: button.id,
|
|
281
|
+
}).body.code,
|
|
282
|
+
).toBe(40001)
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('rejects turning a menu with page or directory children into a button', () => {
|
|
287
|
+
const api = createDemoApi()
|
|
288
|
+
const page = data<{ id: string }>(
|
|
289
|
+
request(api, 'POST', '/system/menus', {
|
|
290
|
+
kind: 'page',
|
|
291
|
+
code: 'page-with-child-test',
|
|
292
|
+
title: 'Page with child',
|
|
293
|
+
path: '/page-with-child-test',
|
|
294
|
+
componentKey: 'dashboard',
|
|
295
|
+
}),
|
|
296
|
+
)
|
|
297
|
+
const directory = data<{ id: string }>(
|
|
298
|
+
request(api, 'POST', '/system/menus', {
|
|
299
|
+
kind: 'directory',
|
|
300
|
+
code: 'directory-with-child-test',
|
|
301
|
+
title: 'Directory with child',
|
|
302
|
+
}),
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
for (const [menu, childKind] of [
|
|
306
|
+
[page, 'page'],
|
|
307
|
+
[directory, 'directory'],
|
|
308
|
+
] as const) {
|
|
309
|
+
data(
|
|
310
|
+
request(api, 'POST', '/system/menus', {
|
|
311
|
+
kind: childKind,
|
|
312
|
+
parentId: menu.id,
|
|
313
|
+
code: `${childKind}-child-${menu.id}`,
|
|
314
|
+
title: `${childKind} child`,
|
|
315
|
+
...(childKind === 'page'
|
|
316
|
+
? { path: `/${childKind}-child-${menu.id}`, componentKey: 'dashboard' }
|
|
317
|
+
: {}),
|
|
318
|
+
}),
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
expect(
|
|
322
|
+
request(api, 'PUT', `/system/menus/${menu.id}`, {
|
|
323
|
+
kind: 'button',
|
|
324
|
+
parentId: 'menu-dashboard',
|
|
325
|
+
code: `${childKind}-with-child-button-${menu.id}`,
|
|
326
|
+
title: `${childKind} button`,
|
|
327
|
+
permission: 'workspace:dashboard:export',
|
|
328
|
+
}).body.code,
|
|
329
|
+
).toBe(40001)
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('keeps page titleKey through the runtime menu payload', () => {
|
|
334
|
+
const api = createDemoApi()
|
|
335
|
+
data(
|
|
336
|
+
request(api, 'POST', '/system/menus', {
|
|
337
|
+
kind: 'page',
|
|
338
|
+
code: 'coverage-page',
|
|
339
|
+
title: 'Coverage',
|
|
340
|
+
path: '/coverage',
|
|
341
|
+
componentKey: 'dashboard',
|
|
342
|
+
titleKey: 'menus.coverage.title',
|
|
343
|
+
}),
|
|
344
|
+
)
|
|
345
|
+
const runtime = data<{ list: Array<{ code: string, titleKey?: string }> }>(
|
|
346
|
+
request(api, 'GET', '/system/menus', undefined, 'page=1&pageSize=50'),
|
|
347
|
+
)
|
|
348
|
+
expect(
|
|
349
|
+
runtime.list.some(
|
|
350
|
+
(menu) => menu.code === 'coverage-page' && menu.titleKey === 'menus.coverage.title',
|
|
351
|
+
),
|
|
352
|
+
).toBe(true)
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('rejects structural menu writes: ghost parents, self or descendant parents, empty fields', () => {
|
|
356
|
+
const api = createDemoApi()
|
|
357
|
+
expect(
|
|
358
|
+
request(api, 'POST', '/system/menus', {
|
|
359
|
+
kind: 'page',
|
|
360
|
+
code: 'orphan',
|
|
361
|
+
title: 'Orphan',
|
|
362
|
+
path: '/orphan',
|
|
363
|
+
parentId: 'menu-nowhere',
|
|
364
|
+
}).body.code,
|
|
365
|
+
).toBe(40001)
|
|
366
|
+
expect(
|
|
367
|
+
request(api, 'POST', '/system/menus', { kind: 'page', code: '', title: 'NoCode' })
|
|
368
|
+
.body.code,
|
|
369
|
+
).toBe(40001)
|
|
370
|
+
const page = data<{ id: string }>(
|
|
371
|
+
request(api, 'POST', '/system/menus', {
|
|
372
|
+
kind: 'page',
|
|
373
|
+
code: 'self-test',
|
|
374
|
+
title: 'Self',
|
|
375
|
+
path: '/self-test',
|
|
376
|
+
componentKey: 'dashboard',
|
|
377
|
+
}),
|
|
378
|
+
)
|
|
379
|
+
expect(
|
|
380
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
381
|
+
kind: 'page',
|
|
382
|
+
parentId: page.id,
|
|
383
|
+
code: 'self-test',
|
|
384
|
+
title: 'Self',
|
|
385
|
+
path: '/self-test',
|
|
386
|
+
}).body.code,
|
|
387
|
+
).toBe(40001)
|
|
388
|
+
const child = data<{ id: string }>(
|
|
389
|
+
request(api, 'POST', '/system/menus', {
|
|
390
|
+
kind: 'page',
|
|
391
|
+
code: 'child-page',
|
|
392
|
+
title: 'Child',
|
|
393
|
+
path: 'child',
|
|
394
|
+
parentId: page.id,
|
|
395
|
+
componentKey: 'dashboard',
|
|
396
|
+
}),
|
|
397
|
+
)
|
|
398
|
+
expect(
|
|
399
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
400
|
+
kind: 'page',
|
|
401
|
+
parentId: child.id,
|
|
402
|
+
code: 'self-test',
|
|
403
|
+
title: 'Self',
|
|
404
|
+
path: '/self-test',
|
|
405
|
+
}).body.code,
|
|
406
|
+
).toBe(40001)
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
it('rejects kind conversions that orphan button children and tolerates legacy clients without version', () => {
|
|
410
|
+
const api = createDemoApi()
|
|
411
|
+
const page = data<{ id: string }>(
|
|
412
|
+
request(api, 'POST', '/system/menus', {
|
|
413
|
+
kind: 'page',
|
|
414
|
+
code: 'with-buttons',
|
|
415
|
+
title: 'Host',
|
|
416
|
+
path: '/with-buttons',
|
|
417
|
+
componentKey: 'dashboard',
|
|
418
|
+
}),
|
|
419
|
+
)
|
|
420
|
+
data(
|
|
421
|
+
request(api, 'POST', '/system/menus', {
|
|
422
|
+
kind: 'button',
|
|
423
|
+
parentId: page.id,
|
|
424
|
+
code: 'host-write',
|
|
425
|
+
title: 'Write',
|
|
426
|
+
permission: 'system:demo:write',
|
|
427
|
+
}),
|
|
428
|
+
)
|
|
429
|
+
expect(
|
|
430
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
431
|
+
kind: 'directory',
|
|
432
|
+
code: 'with-buttons',
|
|
433
|
+
title: 'Host',
|
|
434
|
+
}).body.code,
|
|
435
|
+
).toBe(40001)
|
|
436
|
+
const legacy = data<{ version: number }>(
|
|
437
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
438
|
+
kind: 'page',
|
|
439
|
+
code: 'with-buttons',
|
|
440
|
+
title: 'Host v2',
|
|
441
|
+
path: '/with-buttons',
|
|
442
|
+
}),
|
|
443
|
+
)
|
|
444
|
+
expect(legacy.version).toBeGreaterThan(1)
|
|
445
|
+
expect(
|
|
446
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
447
|
+
kind: 'page',
|
|
448
|
+
code: 'with-buttons',
|
|
449
|
+
title: 'Host v3',
|
|
450
|
+
path: '/with-buttons',
|
|
451
|
+
version: 'nope',
|
|
452
|
+
}).body.code,
|
|
453
|
+
).toBe(40901)
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('bumps version on status changes so open editors conflict instead of reverting', () => {
|
|
457
|
+
const api = createDemoApi()
|
|
458
|
+
const created = data<{ id: string, version: number }>(
|
|
459
|
+
request(api, 'POST', '/system/menus', {
|
|
460
|
+
kind: 'page',
|
|
461
|
+
code: 'status-bump',
|
|
462
|
+
title: 'Status',
|
|
463
|
+
path: '/status-bump',
|
|
464
|
+
componentKey: 'dashboard',
|
|
465
|
+
}),
|
|
466
|
+
)
|
|
467
|
+
data(request(api, 'PATCH', '/system/menus/status', { ids: [created.id], status: 'suspended' }))
|
|
468
|
+
expect(
|
|
469
|
+
request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
470
|
+
kind: 'page',
|
|
471
|
+
code: 'status-bump',
|
|
472
|
+
title: 'Status v2',
|
|
473
|
+
path: '/status-bump',
|
|
474
|
+
version: created.version,
|
|
475
|
+
}).body.code,
|
|
476
|
+
).toBe(40901)
|
|
477
|
+
})
|
|
478
|
+
})
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { getRouteQueryString } from '@origen-ui/router'
|
|
2
3
|
import { ElAlert, ElButton, ElCard, ElForm, ElFormItem, ElInput } from 'element-plus'
|
|
3
4
|
import { reactive, shallowRef } from 'vue'
|
|
4
5
|
import { useI18n } from 'vue-i18n'
|
|
5
6
|
import { useRoute, useRouter } from 'vue-router'
|
|
7
|
+
import { translateAdminError } from '../../../app/errorMessage'
|
|
8
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
6
9
|
import { useAuthStore } from '../store/auth'
|
|
7
10
|
|
|
8
11
|
defineOptions({ name: 'LoginPage' })
|
|
@@ -24,10 +27,14 @@ async function submit(): Promise<void> {
|
|
|
24
27
|
errorMessage.value = ''
|
|
25
28
|
try {
|
|
26
29
|
await auth.login(form)
|
|
27
|
-
const redirect =
|
|
30
|
+
const redirect = getRouteQueryString(route.query.redirect) ?? HOME_ROUTE
|
|
28
31
|
await router.push(redirect)
|
|
29
32
|
} catch (error: unknown) {
|
|
30
|
-
errorMessage.value = error
|
|
33
|
+
errorMessage.value = translateAdminError(error, {
|
|
34
|
+
domain: 'auth',
|
|
35
|
+
fallbackKey: 'auth.loginFailed',
|
|
36
|
+
fallback: t('auth.loginFailed'),
|
|
37
|
+
})
|
|
31
38
|
} finally {
|
|
32
39
|
loading.value = false
|
|
33
40
|
}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import type { ApiBusinessError } from '@origen-ui/http'
|
|
2
2
|
import type { Permission } from '@origen-ui/shared'
|
|
3
|
-
import type { AdminMessageKey } from '../../../locales'
|
|
4
|
-
import { ApiBusinessError as ApiBusinessErrorClass } from '@origen-ui/http'
|
|
5
3
|
import { hasCodePermission } from '@origen-ui/permission/codes'
|
|
6
4
|
import { defineStore } from 'pinia'
|
|
7
5
|
import { apiClient, tokenManager } from '../../../api/client'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
function translate(key: string): string {
|
|
11
|
-
const global = getAdminI18n()?.global as unknown as
|
|
12
|
-
| { te?: (key: string) => boolean, t: (key: string) => string } |
|
|
13
|
-
undefined
|
|
14
|
-
if (!global) return key
|
|
15
|
-
return global.te?.(key) ? global.t(key as AdminMessageKey) : key
|
|
16
|
-
}
|
|
6
|
+
import { adminErrorKey, createAdminError } from '../../../app/errorMessage'
|
|
17
7
|
|
|
18
8
|
export interface AdminUser {
|
|
19
9
|
id: string
|
|
@@ -111,7 +101,7 @@ function cacheProfile(session: AdminSession): void {
|
|
|
111
101
|
}
|
|
112
102
|
|
|
113
103
|
function parseLoginPayload(value: unknown): LoginPayload {
|
|
114
|
-
if (!isRecord(value)) throw
|
|
104
|
+
if (!isRecord(value)) throw createAdminError('auth.invalidResponse')
|
|
115
105
|
return {
|
|
116
106
|
token: readString(value.token),
|
|
117
107
|
accessToken: readString(value.accessToken),
|
|
@@ -137,11 +127,6 @@ function parseProfile(value: unknown, fallbackUsername: string): Omit<AdminSessi
|
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
129
|
|
|
140
|
-
function errorMessage(error: unknown): string {
|
|
141
|
-
if (error instanceof ApiBusinessErrorClass || error instanceof Error) return error.message
|
|
142
|
-
return translate('auth.requestFailed')
|
|
143
|
-
}
|
|
144
|
-
|
|
145
130
|
export const useAuthStore = defineStore('admin-auth', {
|
|
146
131
|
state: (): { session: AdminSession | null } => ({ session: null }),
|
|
147
132
|
getters: {
|
|
@@ -162,7 +147,7 @@ export const useAuthStore = defineStore('admin-auth', {
|
|
|
162
147
|
})
|
|
163
148
|
const payload = parseLoginPayload(response)
|
|
164
149
|
const token = payload.accessToken ?? payload.token
|
|
165
|
-
if (!token) throw
|
|
150
|
+
if (!token) throw createAdminError('auth.missingToken')
|
|
166
151
|
const session: AdminSession = {
|
|
167
152
|
token,
|
|
168
153
|
user: normalizeUser(payload.user, credentials.username),
|
|
@@ -176,7 +161,9 @@ export const useAuthStore = defineStore('admin-auth', {
|
|
|
176
161
|
cacheProfile(session)
|
|
177
162
|
return session
|
|
178
163
|
} catch (error: unknown) {
|
|
179
|
-
|
|
164
|
+
const key = adminErrorKey(error, { domain: 'auth', fallbackKey: 'auth.loginFailed' })
|
|
165
|
+
console.error('[admin] login failed', error)
|
|
166
|
+
throw createAdminError(key, error)
|
|
180
167
|
}
|
|
181
168
|
},
|
|
182
169
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ElButton, ElResult } from 'element-plus'
|
|
3
3
|
import { useI18n } from 'vue-i18n'
|
|
4
4
|
import { useRouter } from 'vue-router'
|
|
5
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
5
6
|
|
|
6
7
|
defineOptions({ name: 'ForbiddenPage' })
|
|
7
8
|
|
|
@@ -13,7 +14,7 @@ const { t } = useI18n()
|
|
|
13
14
|
<main class="error-page">
|
|
14
15
|
<ElResult icon="warning" :title="t('errors.forbidden.code')" :sub-title="t('errors.forbidden.message')">
|
|
15
16
|
<template #extra>
|
|
16
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
17
18
|
{{ t('errors.forbidden.backHome') }}
|
|
18
19
|
</ElButton>
|
|
19
20
|
</template>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ElButton, ElResult } from 'element-plus'
|
|
3
3
|
import { useI18n } from 'vue-i18n'
|
|
4
4
|
import { useRouter } from 'vue-router'
|
|
5
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
5
6
|
|
|
6
7
|
defineOptions({ name: 'NotFoundPage' })
|
|
7
8
|
|
|
@@ -13,7 +14,7 @@ const { t } = useI18n()
|
|
|
13
14
|
<main class="error-page">
|
|
14
15
|
<ElResult icon="warning" :title="t('errors.notFound.code')" :sub-title="t('errors.notFound.message')">
|
|
15
16
|
<template #extra>
|
|
16
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
17
18
|
{{ t('errors.notFound.backHome') }}
|
|
18
19
|
</ElButton>
|
|
19
20
|
</template>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ElButton, ElResult } from 'element-plus'
|
|
3
3
|
import { useI18n } from 'vue-i18n'
|
|
4
4
|
import { useRouter } from 'vue-router'
|
|
5
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
5
6
|
|
|
6
7
|
defineOptions({ name: 'ServerErrorPage' })
|
|
7
8
|
|
|
@@ -13,7 +14,7 @@ const { t } = useI18n()
|
|
|
13
14
|
<main class="error-page">
|
|
14
15
|
<ElResult icon="error" :title="t('errors.serverError.code')" :sub-title="t('errors.serverError.message')">
|
|
15
16
|
<template #extra>
|
|
16
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
17
18
|
{{ t('errors.serverError.backHome') }}
|
|
18
19
|
</ElButton>
|
|
19
20
|
</template>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageResult } from '@origen-ui/shared'
|
|
1
2
|
import type {
|
|
2
3
|
OgTableDataSource,
|
|
3
4
|
OgTableExportRequest,
|
|
@@ -149,11 +150,20 @@ function createExportRequest<TQuery extends object>(): OgTableExportRequest<TQue
|
|
|
149
150
|
mode: 'all',
|
|
150
151
|
source: 'display',
|
|
151
152
|
watermark: false,
|
|
153
|
+
fileName: 'export',
|
|
154
|
+
format: 'xlsx',
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
function createRequestContext(signal: AbortSignal): OgTableRequestContext {
|
|
156
|
-
return {
|
|
159
|
+
return {
|
|
160
|
+
signal,
|
|
161
|
+
requestId: 1,
|
|
162
|
+
pagination: {
|
|
163
|
+
buildRequest: (extra = {}) => ({ ...extra }),
|
|
164
|
+
parseResponse: <T extends OgTableRow>(raw: unknown): PageResult<T> => raw as PageResult<T>,
|
|
165
|
+
},
|
|
166
|
+
}
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
async function expectCancellableList<T extends OgTableRow, TQuery extends object>(
|
|
@@ -2,7 +2,7 @@ import type { PageResult } from '@origen-ui/shared'
|
|
|
2
2
|
import type { AdminMessageKey } from '../../../../locales'
|
|
3
3
|
import type { PageRequest, RbacRole, RbacStatus, RbacUser } from './rbac'
|
|
4
4
|
import { apiClient } from '../../../../api/client'
|
|
5
|
-
import {
|
|
5
|
+
import { translateAdminMessage } from '../../../../locales'
|
|
6
6
|
|
|
7
7
|
export type AdminRecordStatus = RbacStatus
|
|
8
8
|
|
|
@@ -248,11 +248,7 @@ export function createRoleDraft(row?: AdminRoleRecord): AdminRoleDraft {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
function rbacText(key: string, named?: Record<string, unknown>): string {
|
|
251
|
-
|
|
252
|
-
| { t: (key: string, named?: Record<string, unknown>) => string } |
|
|
253
|
-
undefined
|
|
254
|
-
if (!global) return key
|
|
255
|
-
return named ? global.t(key as AdminMessageKey, named) : global.t(key as AdminMessageKey)
|
|
251
|
+
return translateAdminMessage(key, { named })
|
|
256
252
|
}
|
|
257
253
|
|
|
258
254
|
function requiredString(value: unknown, labelKey: string): string {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PageResult, SelectOption } from '@origen-ui/shared'
|
|
2
|
-
import type { AdminMessageKey } from '../../../../locales'
|
|
3
2
|
import { apiClient } from '../../../../api/client'
|
|
4
|
-
import {
|
|
3
|
+
import { translateAdminMessage } from '../../../../locales'
|
|
5
4
|
|
|
6
5
|
export type RbacStatus = 'active' | 'suspended'
|
|
7
6
|
export type MenuKind = 'directory' | 'page' | 'button'
|
|
@@ -35,6 +34,8 @@ export interface RbacMenu {
|
|
|
35
34
|
kind: MenuKind
|
|
36
35
|
code: string
|
|
37
36
|
title: string
|
|
37
|
+
/** Optional i18n key resolved by the app title resolver; falls back to `title`. */
|
|
38
|
+
titleKey?: string
|
|
38
39
|
path?: string
|
|
39
40
|
componentKey?: string
|
|
40
41
|
icon?: string
|
|
@@ -45,12 +46,14 @@ export interface RbacMenu {
|
|
|
45
46
|
cache: boolean
|
|
46
47
|
tabHidden: boolean
|
|
47
48
|
redirect?: string
|
|
49
|
+
/** Optimistic-lock revision; assigned on create and incremented on every update. */
|
|
50
|
+
version: number
|
|
48
51
|
createdAt: string
|
|
49
52
|
updatedAt: string
|
|
50
53
|
children?: RbacMenu[]
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
export type RbacMenuDraft = Omit<RbacMenu, 'id' | 'createdAt' | 'updatedAt'>
|
|
56
|
+
export type RbacMenuDraft = Omit<RbacMenu, 'id' | 'createdAt' | 'updatedAt' | 'version'>
|
|
54
57
|
|
|
55
58
|
export interface RbacAuditEvent {
|
|
56
59
|
id: string
|
|
@@ -74,8 +77,7 @@ export interface RbacPageCapability {
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
export function rbacText(key: string): string {
|
|
77
|
-
|
|
78
|
-
return global?.t(key as AdminMessageKey) ?? key
|
|
80
|
+
return translateAdminMessage(key)
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export interface PageRequest<TQuery extends object> {
|
|
@@ -231,15 +233,23 @@ export async function createMenu(draft: RbacMenuDraft, signal: AbortSignal): Pro
|
|
|
231
233
|
return apiClient.post<RbacMenu>('/system/menus', draft, { signal, silent: true })
|
|
232
234
|
}
|
|
233
235
|
|
|
236
|
+
/** Business code returned by the server when a menu update loses a version race. */
|
|
237
|
+
export const MENU_VERSION_CONFLICT_CODE = 40901
|
|
238
|
+
|
|
234
239
|
export async function updateMenu(
|
|
235
240
|
menuId: string,
|
|
236
241
|
draft: RbacMenuDraft,
|
|
242
|
+
version: number,
|
|
237
243
|
signal: AbortSignal,
|
|
238
244
|
): Promise<RbacMenu> {
|
|
239
|
-
return apiClient.put<RbacMenu>(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
return apiClient.put<RbacMenu>(
|
|
246
|
+
`/system/menus/${encodeURIComponent(menuId)}`,
|
|
247
|
+
{ ...draft, version },
|
|
248
|
+
{
|
|
249
|
+
signal,
|
|
250
|
+
silent: true,
|
|
251
|
+
},
|
|
252
|
+
)
|
|
243
253
|
}
|
|
244
254
|
|
|
245
255
|
export async function setMenusStatus(
|