Add component-level permission tracking and visibility handling:

- Introduce `RequiresPermission` component for permission-based UI controls.
- Add missing permission reporting logic with throttling to `requestQueueState`.
- Update `DepartmentGoals.vue` to wrap actions with `RequiresPermission`.
- Extend unit and e2e tests to validate permission handling scenarios.
This commit is contained in:
Jeppe Bundgaard
2026-03-19 18:29:00 +01:00
parent 6ea51a70d8
commit f9bde54956
8 changed files with 377 additions and 23 deletions
+34
View File
@@ -205,6 +205,16 @@ test.describe('Admin Module - Goals', () => {
await card.locator('.dropdown-item', { hasText: actionLabel }).click({ force: true });
};
const removeSessionPermissions = async (page: Page, permissionKeys: string[]) => {
await page.evaluate(async ({ keys }) => {
const sessionModule = await import("/src/components/session/token/SessionUser.vue");
const current = Array.isArray(sessionModule.SessionUser.permissions.value)
? sessionModule.SessionUser.permissions.value
: [];
sessionModule.SessionUser.permissions.value = current.filter((permission) => !keys.includes(permission));
}, { keys: permissionKeys });
};
test.beforeEach(async ({ page }, testInfo) => {
test.skip(testInfo.project.name.toLowerCase().includes('mobile'), 'Goals admin suite is desktop-focused');
test.skip(testInfo.project.name !== 'chromium', 'Goals admin suite is stabilized for Chromium in this environment.');
@@ -313,5 +323,29 @@ test.describe('Admin Module - Goals', () => {
expect(deleteRequest.url()).toContain('id=');
await expect(page.locator('.swal2-popup')).toBeHidden({ timeout: 10000 });
});
test('hides create and test-alert controls when permission is missing and reports COMPONENT entries', async ({ page }) => {
await removeSessionPermissions(page, ['goals_department_create', 'goals_department_progress_alert_test']);
await page.reload();
await expect(page.locator('nav.level.box')).toBeVisible({ timeout: 15000 });
await expect(page.locator('button', { hasText: 'Opret mål' })).toHaveCount(0);
await expect(page.locator('button', { hasText: 'Opret dit første mål' })).toHaveCount(0);
const card = page.locator('.goal-card', { hasText: 'Mock Active Goal' }).first();
await expect(card).toBeVisible({ timeout: 15000 });
await card.locator('.dropdown.is-hoverable').first().hover();
await expect(card.locator('.dropdown-item', { hasText: 'Test alert' })).toHaveCount(0);
await page.keyboard.press('Shift');
await page.keyboard.press('Shift');
await page.keyboard.press('Shift');
const missingPermissionsBox = page.locator("[data-testid='request-queue-missing-permissions-box']");
await expect(missingPermissionsBox).toBeVisible({ timeout: 10000 });
await expect(missingPermissionsBox).toContainText('goals_department_create');
await expect(missingPermissionsBox).toContainText('goals_department_progress_alert_test');
await expect(missingPermissionsBox).toContainText('COMPONENT');
});
});