Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Use ClientRole enum from model throughout the UI (#3282)

Koenf786fb01e4dc
diff --git a/ui/AGENTS.md b/ui/AGENTS.md
index 2b30055e3..c31f7be2f 100644
--- a/ui/AGENTS.md
+++ b/ui/AGENTS.md
@@ -12,9 +12,11 @@ Anything a package references relative to its own emitted files must survive the
Three outputs stay outside `build/` on purpose. `ui/app/shared/fonts` is packaged by a `generateSources` task that copies the project dir minus `build/**`. `ui/app/shared/cache` is a checksum-keyed download that `clean` would force to re-download. The generated `model.ts` and `restclient.ts` are sources rather than artifacts, so they stay under `rootDir`.
-## Generated model types
+## Generated model
-`ui/component/model/src/model.ts` is generated from the Java backend by typescript-generator. Do not edit it by hand. When a TypeScript type mirrors a backend class, import it from `@openremote/model` instead of redeclaring a local interface. Regenerate it from the backend rather than patching the output.
+`ui/component/model/src/model.ts` is generated from the Java backend by typescript-generator and holds enums and constants as well as types. Do not edit it by hand. Anything mirroring a backend class or enum comes from `@openremote/model`, so import it rather than redeclaring an interface or hardcoding a member's value, e.g. `manager.hasRole(ClientRole.READ_ASSETS)` over the `"read:assets"` string.
+
+A member you expect being absent means the file is stale, not that the value has to be written by hand. Regenerate with `./gradlew :ui:component:model:generateTypeScript`. The file is gitignored and the build regenerates it, so this never shows up in a diff.
## Base element
diff --git a/ui/app/manager/src/components/notifications/or-notification-form.ts b/ui/app/manager/src/components/notifications/or-notification-form.ts
index 28c3fb477..89b90c3c5 100644
--- a/ui/app/manager/src/components/notifications/or-notification-form.ts
+++ b/ui/app/manager/src/components/notifications/or-notification-form.ts
@@ -24,6 +24,7 @@ import { i18next } from "@openremote/or-translate";
import manager, { Util } from "@openremote/core";
import {
type Asset,
+ ClientRole,
type EmailNotificationMessage,
type Notification,
NotificationTargetType,
@@ -227,16 +228,16 @@ export class OrNotificationForm extends OrElement {
return;
}
- const canReadAssets = manager.hasRole("read:assets") || manager.hasRole("read:admin");
+ const canReadAssets = manager.hasRole(ClientRole.READ_ASSETS) || manager.hasRole(ClientRole.READ_ADMIN);
const promises = [];
if (canReadAssets) {
promises.push(this._loadAssets());
}
- if (manager.hasRole("read:users") || manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN)) {
promises.push(this._loadUsers());
}
- if (manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_ADMIN)) {
promises.push(this._loadRealms());
}
await Promise.all(promises);
@@ -274,7 +275,7 @@ export class OrNotificationForm extends OrElement {
/** Users are the default recipient type; falls back to assets for callers not allowed to pick users. */
protected _defaultTargetType(): NotificationTargetType {
const canSelectUsers =
- !manager.isRestrictedUser() && (manager.hasRole("read:users") || manager.hasRole("read:admin"));
+ !manager.isRestrictedUser() && (manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN));
return canSelectUsers ? NotificationTargetType.USER : NotificationTargetType.ASSET;
}
@@ -289,7 +290,7 @@ export class OrNotificationForm extends OrElement {
}
protected async _loadUsers(): Promise<User[]> {
- if (!manager.hasRole("read:users") && !manager.hasRole("read:admin")) {
+ if (!manager.hasRole(ClientRole.READ_USERS) && !manager.hasRole(ClientRole.READ_ADMIN)) {
return [];
}
try {
@@ -307,7 +308,7 @@ export class OrNotificationForm extends OrElement {
}
protected async _loadAssets(): Promise<Asset[]> {
- if (!manager.hasRole("read:assets") && !manager.hasRole("read:admin")) {
+ if (!manager.hasRole(ClientRole.READ_ASSETS) && !manager.hasRole(ClientRole.READ_ADMIN)) {
return [];
}
try {
@@ -475,7 +476,7 @@ export class OrNotificationForm extends OrElement {
protected _renderPropertiesContainer() {
if (!this.notification) return "";
- const canReadUsers = manager.hasRole("read:users") || manager.hasRole("read:admin");
+ const canReadUsers = manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN);
const source =
canReadUsers && this.notification.sourceId
? `${this._normalizeValue(this.notification.source)}, ${this.notification.sourceId}`
@@ -501,9 +502,9 @@ export class OrNotificationForm extends OrElement {
protected _renderTargetContainer(inputDisabled: boolean) {
if (inputDisabled) {
const canSeeTargetId =
- manager.hasRole("read:admin") ||
- (this._targetType === NotificationTargetType.USER && manager.hasRole("read:users")) ||
- (this._targetType === NotificationTargetType.ASSET && manager.hasRole("read:assets"));
+ manager.hasRole(ClientRole.READ_ADMIN) ||
+ (this._targetType === NotificationTargetType.USER && manager.hasRole(ClientRole.READ_USERS)) ||
+ (this._targetType === NotificationTargetType.ASSET && manager.hasRole(ClientRole.READ_ASSETS));
const targetDisplay = canSeeTargetId ? this._normalizeValue(this._targets[0]) : "-";
return html`
<div class="targetContainer">
@@ -515,13 +516,16 @@ export class OrNotificationForm extends OrElement {
}
const allowedTargetTypes: SelectItem[] = [];
- if (manager.hasRole("read:assets") || manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_ASSETS) || manager.hasRole(ClientRole.READ_ADMIN)) {
allowedTargetTypes.push({
label: i18next.t("notifications.targetTypes.ASSET"),
value: NotificationTargetType.ASSET,
});
}
- if (!manager.isRestrictedUser() && (manager.hasRole("read:users") || manager.hasRole("read:admin"))) {
+ if (
+ !manager.isRestrictedUser() &&
+ (manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN))
+ ) {
allowedTargetTypes.unshift({
label: i18next.t("notifications.targetTypes.USER"),
value: NotificationTargetType.USER,
diff --git a/ui/app/manager/src/headers.ts b/ui/app/manager/src/headers.ts
index 72131f423..43ffe731e 100644
--- a/ui/app/manager/src/headers.ts
+++ b/ui/app/manager/src/headers.ts
@@ -17,6 +17,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { manager } from "@openremote/core";
+import { ClientRole } from "@openremote/model";
import type { AppStateKeyed, HeaderItem, OrApp } from "@openremote/or-app";
import type { AnyAction } from "@reduxjs/toolkit";
import { getMapRoute, getNotificationsRoute } from "./routes";
@@ -45,7 +46,7 @@ export function headerItemServices<S extends AppStateKeyed, A extends AnyAction>
value: "services",
href: "services",
text: "services",
- roles: ["read:services"],
+ roles: [ClientRole.READ_SERVICES],
};
}
@@ -75,7 +76,7 @@ export function headerItemGatewayConnection<S extends AppStateKeyed, A extends A
value: "gateway",
href: "gateway",
text: "gatewayConnection",
- roles: ["write:admin", "read:admin"],
+ roles: [ClientRole.WRITE_ADMIN, ClientRole.READ_ADMIN],
};
}
@@ -85,7 +86,7 @@ export function headerItemGatewayTunnel<S extends AppStateKeyed, A extends AnyAc
value: "gateway-tunnel",
href: "gateway-tunnel",
text: "gatewayTunnel",
- roles: ["write:admin", "read:admin"],
+ roles: [ClientRole.WRITE_ADMIN, ClientRole.READ_ADMIN],
};
}
@@ -118,7 +119,7 @@ export function headerItemLogs<S extends AppStateKeyed, A extends AnyAction>(orA
href: "logs",
text: "logs",
hideMobile: true,
- roles: ["write:logs", "read:logs"],
+ roles: [ClientRole.WRITE_LOGS, ClientRole.READ_LOGS],
};
}
@@ -128,7 +129,7 @@ export function headerItemNotifications<S extends AppStateKeyed, A extends AnyAc
value: "notifications",
href: getNotificationsRoute(),
text: "notification_other",
- roles: ["read:notifications"],
+ roles: [ClientRole.READ_NOTIFICATIONS],
};
}
@@ -138,7 +139,7 @@ export function headerItemAccount<S extends AppStateKeyed, A extends AnyAction>(
value: "account",
href: "account",
text: "account",
- roles: ["write:user"],
+ roles: [ClientRole.WRITE_USER],
};
}
export function headerItemUsers<S extends AppStateKeyed, A extends AnyAction>(orApp: OrApp<S>): HeaderItem {
@@ -147,7 +148,7 @@ export function headerItemUsers<S extends AppStateKeyed, A extends AnyAction>(or
value: "users",
href: "users",
text: "user_plural",
- roles: ["read:admin", "write:admin"],
+ roles: [ClientRole.READ_ADMIN, ClientRole.WRITE_ADMIN],
};
}
export function headerItemRoles<S extends AppStateKeyed, A extends AnyAction>(orApp: OrApp<S>): HeaderItem {
@@ -156,7 +157,7 @@ export function headerItemRoles<S extends AppStateKeyed, A extends AnyAction>(or
value: "roles",
href: "roles",
text: "role_plural",
- roles: ["read:admin", "write:admin"],
+ roles: [ClientRole.READ_ADMIN, ClientRole.WRITE_ADMIN],
};
}
export function headerItemRealms<S extends AppStateKeyed, A extends AnyAction>(orApp: OrApp<S>): HeaderItem {
@@ -175,7 +176,7 @@ export function headerItemExport<S extends AppStateKeyed, A extends AnyAction>(o
value: "export",
href: "data-export",
text: "dataExport",
- roles: ["read:assets"],
+ roles: [ClientRole.READ_ASSETS],
};
}
diff --git a/ui/app/manager/src/pages/page-alarms.ts b/ui/app/manager/src/pages/page-alarms.ts
index 2b5698696..2863b69fd 100644
--- a/ui/app/manager/src/pages/page-alarms.ts
+++ b/ui/app/manager/src/pages/page-alarms.ts
@@ -26,6 +26,7 @@ import {
AlarmSource,
AlarmStatus,
type Asset,
+ ClientRole,
type SentAlarm,
type User,
type UserQuery,
@@ -420,8 +421,8 @@ export class PageAlarms extends Page<AppStateKeyed> {
}
const disabled = false;
- const readAlarms = manager.hasRole("read:alarms");
- const writeAlarms = manager.hasRole("write:alarms");
+ const readAlarms = manager.hasRole(ClientRole.READ_ALARMS);
+ const writeAlarms = manager.hasRole(ClientRole.WRITE_ALARMS);
const readonly = readAlarms && !writeAlarms;
const assignOnly = !readAlarms && !writeAlarms;
@@ -548,7 +549,7 @@ export class PageAlarms extends Page<AppStateKeyed> {
return;
}
- if (manager.hasRole("read:users") || manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN)) {
const usersResponse = await manager.rest.api.UserResource.query({
realmPredicate: { name: manager.displayRealm },
} as UserQuery);
@@ -580,13 +581,13 @@ export class PageAlarms extends Page<AppStateKeyed> {
}
protected async _loadData() {
- if (this._loading || (!manager.hasRole("read:alarms") && !manager.hasRole("write:alarms"))) {
+ if (this._loading || (!manager.hasRole(ClientRole.READ_ALARMS) && !manager.hasRole(ClientRole.WRITE_ALARMS))) {
return;
}
this._loading = true;
const response = await manager.rest.api.AlarmResource.getAlarms({ realm: manager.displayRealm });
- if (manager.hasRole("read:users") || manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN)) {
const usersResponse = await manager.rest.api.UserResource.query({
realmPredicate: { name: manager.displayRealm },
} as UserQuery);
@@ -684,7 +685,7 @@ export class PageAlarms extends Page<AppStateKeyed> {
}
protected getSingleAlarmTemplate(alarm: AlarmModel, readonly: boolean = true): TemplateResult {
- const write = manager.hasRole("write:alarms");
+ const write = manager.hasRole(ClientRole.WRITE_ALARMS);
return html`
<!-- Breadcrumb on top of the page-->
<div style="margin: 0 auto auto auto;
@@ -766,7 +767,7 @@ export class PageAlarms extends Page<AppStateKeyed> {
</or-vaadin-select>
<or-vaadin-select class="alarm-input"
- ?readonly=${!manager.hasRole("read:users") && !manager.hasRole("read:admin")}
+ ?readonly=${!manager.hasRole(ClientRole.READ_USERS) && !manager.hasRole(ClientRole.READ_ADMIN)}
.items=${this._getUsers()} value=${alarm.assigneeId}
@change=${(ev: Event) => {
console.debug(this._getUsers());
@@ -777,7 +778,7 @@ export class PageAlarms extends Page<AppStateKeyed> {
</or-vaadin-select>
<div>
<span><or-translate value="linkedAssets"></or-translate>:</span>
- <or-vaadin-button ?disabled=${!manager.hasRole("write:alarms")} style="margin-left: 4px;"
+ <or-vaadin-button ?disabled=${!manager.hasRole(ClientRole.WRITE_ALARMS)} style="margin-left: 4px;"
@click=${(ev: Event) => this._openAssetSelector(ev, alarm, readonly)}>
<span>${i18next.t("selectRestrictedAssets", { number: alarm.alarmAssetLinks?.length })}</span>
</or-vaadin-button>
@@ -790,11 +791,11 @@ export class PageAlarms extends Page<AppStateKeyed> {
() => html`
<div class="row" style="justify-content: space-between; margin-top: 10px;">
${when(
- manager.hasRole("write:alarms"),
+ manager.hasRole(ClientRole.WRITE_ALARMS),
() => html`
<or-vaadin-button
class="alarm-input"
- ?disabled=${!manager.hasRole("write:alarms") || !alarm.id}
+ ?disabled=${!manager.hasRole(ClientRole.WRITE_ALARMS) || !alarm.id}
@click=${() => this._deleteAlarm(this.alarm)}
>
<or-translate value="delete"></or-translate>
diff --git a/ui/app/manager/src/pages/page-notifications.ts b/ui/app/manager/src/pages/page-notifications.ts
index 786f07567..08cf1252f 100644
--- a/ui/app/manager/src/pages/page-notifications.ts
+++ b/ui/app/manager/src/pages/page-notifications.ts
@@ -22,6 +22,7 @@ import { type AppStateKeyed, Page, type PageProvider } from "@openremote/or-app"
import type { Store } from "@reduxjs/toolkit";
import {
type Asset,
+ ClientRole,
type Notification,
NotificationSource,
NotificationTargetType,
@@ -154,11 +155,11 @@ export class NotificationService {
}
hasUserReadPermissions(): boolean {
- return manager.hasRole("read:users") || manager.hasRole("read:admin");
+ return manager.hasRole(ClientRole.READ_USERS) || manager.hasRole(ClientRole.READ_ADMIN);
}
hasAssetReadPermissions(): boolean {
- return manager.hasRole("read:assets") || manager.hasRole("read:admin");
+ return manager.hasRole(ClientRole.READ_ASSETS) || manager.hasRole(ClientRole.READ_ADMIN);
}
public getDefaultTimeRange(): { fromDate: number; toDate: number } {
@@ -485,9 +486,11 @@ export class PageNotifications extends Page<AppStateKeyed> {
}
protected render() {
- const writeNotifications = manager.hasRole("write:notifications");
+ const writeNotifications = manager.hasRole(ClientRole.WRITE_NOTIFICATIONS);
const hasRecipientType =
- manager.hasRole("read:admin") || manager.hasRole("read:assets") || manager.hasRole("read:users");
+ manager.hasRole(ClientRole.READ_ADMIN) ||
+ manager.hasRole(ClientRole.READ_ASSETS) ||
+ manager.hasRole(ClientRole.READ_USERS);
return html`
<div id="wrapper">
diff --git a/ui/app/manager/test/alarms.test.ts b/ui/app/manager/test/alarms.test.ts
index 8e8647193..1af1ad403 100644
--- a/ui/app/manager/test/alarms.test.ts
+++ b/ui/app/manager/test/alarms.test.ts
@@ -17,7 +17,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { expect } from "@openremote/test";
-import { type Alarm, AlarmSeverity, AlarmStatus } from "@openremote/model";
+import { type Alarm, AlarmSeverity, AlarmStatus, ClientRole } from "@openremote/model";
import { type Manager, adminStatePath, test } from "./fixtures/manager.js";
test.use({ storageState: adminStatePath });
@@ -158,7 +158,7 @@ test.describe("Filter alarms", () => {
async function loginAsAlarmUser(manager: Manager, username: string) {
await manager.provisionUserAndLogin("smartcity", {
username,
- roles: ["read:alarms", "write:alarms"],
+ roles: [ClientRole.READ_ALARMS, ClientRole.WRITE_ALARMS],
});
}
@@ -307,7 +307,7 @@ test.describe("Delete alarms", () => {
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-alarm-editor",
- roles: ["read:alarms", "write:alarms"],
+ roles: [ClientRole.READ_ALARMS, ClientRole.WRITE_ALARMS],
});
await alarmsPage.goto();
await expect(alarmsPage.getRows()).toHaveCount(alarms.length);
@@ -346,7 +346,7 @@ test.describe("Role-Based Access Control", () => {
const { title } = await seedAlarm(manager, { realm: "smartcity" });
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-alarm-viewer",
- roles: ["read:alarms"],
+ roles: [ClientRole.READ_ALARMS],
});
await alarmsPage.goto();
diff --git a/ui/app/manager/test/fixtures/data/permissions.ts b/ui/app/manager/test/fixtures/data/permissions.ts
deleted file mode 100644
index 0a1e0cdb2..000000000
--- a/ui/app/manager/test/fixtures/data/permissions.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2026, OpenRemote Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-export default [
- "write:assets",
- "write:alarms",
- "write:attributes",
- "read:assets",
- "write:logs",
- "write:user",
- "write:admin",
- "read:users",
- "read:insights",
- "write:rules",
- "read:map",
- "read:admin",
- "read:alarms",
- "read:rules",
- "read:logs",
- "write:insights",
-];
diff --git a/ui/app/manager/test/fixtures/data/roles.ts b/ui/app/manager/test/fixtures/data/roles.ts
index b905f4e47..c8d0ab551 100644
--- a/ui/app/manager/test/fixtures/data/roles.ts
+++ b/ui/app/manager/test/fixtures/data/roles.ts
@@ -16,10 +16,12 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+import { ClientRole } from "@openremote/model";
+
export const custom = {
composite: true,
name: "Custom",
// Find and replace with role IDs
- compositeRoleIds: ["read:assets", "write:assets"],
- description: "read:assets, write:assets",
+ compositeRoleIds: [ClientRole.READ_ASSETS, ClientRole.WRITE_ASSETS],
+ description: `${ClientRole.READ_ASSETS}, ${ClientRole.WRITE_ASSETS}`,
};
diff --git a/ui/app/manager/test/fixtures/pages/users.ts b/ui/app/manager/test/fixtures/pages/users.ts
index 9972f0ded..cd8c04f02 100644
--- a/ui/app/manager/test/fixtures/pages/users.ts
+++ b/ui/app/manager/test/fixtures/pages/users.ts
@@ -18,10 +18,11 @@
*/
import { type BasePage, type Locator, type Page, type Shared, expect } from "@openremote/test";
import type { Manager } from "../manager";
-import permissions from "../data/permissions";
import type { UserModel } from "../../../src/pages/page-users";
export class UsersPage implements BasePage {
+ private _allRoles?: string[];
+
constructor(
private readonly page: Page,
private readonly shared: Shared,
@@ -37,45 +38,65 @@ export class UsersPage implements BasePage {
}
/**
- * Get permission locator by name.
- * @param permission The permission name
+ * Get role checkbox locator by name.
+ * @param role The role name
*/
- getPermission(permission: string): Locator {
- return this.page.getByRole("checkbox", { name: permission });
+ getRole(role: string): Locator {
+ return this.page.getByRole("checkbox", { name: role });
}
/**
- * Toggle roles when configuring a user.
- * @param roles The roles to toggle
+ * Toggle composite roles when configuring a user. These select the roles asserted by
+ * {@link toHaveRoles}, they are not roles in their own right.
+ * @param composites The composite roles to toggle
*/
- async toggleUserRoles(...roles: string[]) {
+ async toggleCompositeRoles(...composites: string[]) {
const roleSelector = this.page.locator("or-vaadin-multi-select-combo-box", { hasText: "Manager roles" });
await roleSelector.click();
- for (const role of roles) {
- await this.page.getByRole("option", { name: role }).click();
+ for (const composite of composites) {
+ await this.page.getByRole("option", { name: composite }).click();
}
await roleSelector.locator("#toggleButton").click();
}
/**
- * Assert selected permissions.
- * @param perms The permissions expected to be checked
+ * Every role the current realm offers, read from the manager so that a role added to the backend
+ * is asserted without this fixture being updated. Composite roles are excluded; they select
+ * roles rather than being one.
+ */
+ private async getAllRoles(): Promise<string[]> {
+ if (!this._allRoles) {
+ const roles = await this.manager.getClientRoles();
+ this._allRoles = (roles ?? []).filter((role) => !role.composite).map((role) => role.name!);
+ }
+ return this._allRoles;
+ }
+
+ /**
+ * Assert selected roles, and that every other role is unselected.
+ * @param roles The roles expected to be checked
*/
- async toHavePermissions(...perms: string[]) {
- for (const permisison of perms) {
- await expect(this.getPermission(permisison)).toBeChecked();
- await expect(this.getPermission(permisison)).toBeDisabled();
+ async toHaveRoles(...roles: string[]) {
+ for (const role of roles) {
+ await expect(this.getRole(role)).toBeChecked();
+ await expect(this.getRole(role)).toBeDisabled();
}
- for (const permisison of permissions.filter((p) => !perms.includes(p))) {
- await expect(this.getPermission(permisison)).not.toBeChecked();
- await expect(this.getPermission(permisison)).not.toBeDisabled();
+ const all = await this.getAllRoles();
+ for (const role of all.filter((r) => !roles.includes(r))) {
+ await expect(this.getRole(role)).not.toBeChecked();
+ await expect(this.getRole(role)).not.toBeDisabled();
}
}
+ /** Assert that every role the realm offers is selected. */
+ async toHaveAllRoles() {
+ await this.toHaveRoles(...(await this.getAllRoles()));
+ }
+
/**
* Create a user with read and write access for the current realm.
*
- * Internally checks whether the permissions are correctly set and
+ * Internally checks whether the roles are correctly set and
* registers the user for cleanup.
*
* @param username The users' username
@@ -94,8 +115,8 @@ export class UsersPage implements BasePage {
if (tag) {
await this.page.getByLabel("Tag", { exact: true }).fill(tag);
}
- await this.toggleUserRoles("Read", "Write");
- await this.toHavePermissions(...permissions);
+ await this.toggleCompositeRoles("Read", "Write");
+ await this.toHaveAllRoles();
await this.shared.interceptResponse<UserModel>(`user/${this.manager.realm}/users`, (user) => {
if (user) this.manager.user = user;
});
@@ -118,8 +139,8 @@ export class UsersPage implements BasePage {
if (tag) {
await this.page.getByLabel("Tag").fill(tag);
}
- await this.toggleUserRoles("Read", "Write");
- await this.toHavePermissions(...permissions);
+ await this.toggleCompositeRoles("Read", "Write");
+ await this.toHaveAllRoles();
await this.shared.interceptResponse<UserModel>(`user/${this.manager.realm}/users`, (user) => {
if (user) this.manager.user = user;
});
diff --git a/ui/app/manager/test/notifications.test.ts b/ui/app/manager/test/notifications.test.ts
index 5e2122f2e..1b335391d 100644
--- a/ui/app/manager/test/notifications.test.ts
+++ b/ui/app/manager/test/notifications.test.ts
@@ -19,6 +19,7 @@
import { expect } from "@openremote/test";
import {
type Asset,
+ ClientRole,
type EmailNotificationMessage,
type Notification,
NotificationTargetType,
@@ -396,7 +397,7 @@ test.describe("Role-Based Access Control", () => {
test("should hide the send button for a user without write permission", async ({ manager, notificationsPage }) => {
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-readonly",
- roles: ["read:notifications"],
+ roles: [ClientRole.READ_NOTIFICATIONS],
});
await notificationsPage.goto();
@@ -413,7 +414,7 @@ test.describe("Role-Based Access Control", () => {
}) => {
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-sender",
- roles: ["read:notifications", "write:notifications"],
+ roles: [ClientRole.READ_NOTIFICATIONS, ClientRole.WRITE_NOTIFICATIONS],
});
await notificationsPage.goto();
@@ -433,7 +434,7 @@ test.describe("Role-Based Access Control", () => {
await ensureRecipient(manager, "smartcity", await manager.adminConfig());
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-user-sender",
- roles: ["read:notifications", "write:notifications", "read:users"],
+ roles: [ClientRole.READ_NOTIFICATIONS, ClientRole.WRITE_NOTIFICATIONS, ClientRole.READ_USERS],
});
await notificationsPage.goto();
@@ -455,7 +456,7 @@ test.describe("Role-Based Access Control", () => {
const subject = await seedNotification(manager, "smartcity");
await manager.provisionUserAndLogin("smartcity", {
username: "e2e-viewer",
- roles: ["read:notifications"],
+ roles: [ClientRole.READ_NOTIFICATIONS],
});
await notificationsPage.goto();
diff --git a/ui/app/manager/test/roles.test.ts b/ui/app/manager/test/roles.test.ts
index 4980c5313..e62e34bb9 100644
--- a/ui/app/manager/test/roles.test.ts
+++ b/ui/app/manager/test/roles.test.ts
@@ -19,8 +19,7 @@
import { expect } from "@openremote/test";
import { adminStatePath, test } from "./fixtures/manager.js";
import { custom } from "./fixtures/data/roles.js";
-import type { Role } from "@openremote/model";
-import permissions from "./fixtures/data/permissions.js";
+import { ClientRole, type Role } from "@openremote/model";
test.use({ storageState: adminStatePath });
@@ -29,13 +28,13 @@ test.use({ storageState: adminStatePath });
* @when Logging into OpenRemote "master" realm as "admin"
* @and Switching to the "smartcity" realm
* @and Navigating to the "Roles" page
- * @and Creating a new role named "Custom" with specific permissions
+ * @and Creating a new role named "Custom" with specific roles
* @and Navigating to the "Users" page and selecting a user
- * @and Assigning only the "Custom" role to the user and verifying permissions
- * @and Switching back to original permissions and verifying all permissions are selected
- * @then The new role is created and assigned correctly with expected permissions
+ * @and Assigning only the "Custom" role to the user and verifying its roles
+ * @and Switching back to the original roles and verifying all roles are selected
+ * @then The new role is created and assigned correctly with the expected roles
*/
-test("Create a new role, assign it to a user, and verify permissions", async ({ page, manager, shared, usersPage }) => {
+test("Create a new role, assign it to a user, and verify its roles", async ({ page, manager, shared, usersPage }) => {
await manager.setup("smartcity");
await manager.goToRealmStartPage("master");
await manager.switchToRealmByRealmPicker("smartcity");
@@ -43,8 +42,8 @@ test("Create a new role, assign it to a user, and verify permissions", async ({
await page.getByText("Add Role").click();
const lastRow = page.locator("#table-roles tbody tr").last();
- await lastRow.getByRole("textbox", { name: "Role" }).fill("Custom");
- await lastRow.getByRole("textbox", { name: "Description" }).fill("read:asset, write:asset");
+ await lastRow.getByRole("textbox", { name: "Role" }).fill(custom.name);
+ await lastRow.getByRole("textbox", { name: "Description" }).fill(custom.description);
await lastRow.getByRole("checkbox", { name: "assets: Read asset data" }).click();
await lastRow.getByRole("checkbox", { name: "assets: Write asset data" }).click();
@@ -58,11 +57,11 @@ test("Create a new role, assign it to a user, and verify permissions", async ({
await manager.navigateToMenuItem("Users");
await page.getByRole("cell", { name: "smartcity" }).click();
- await usersPage.toggleUserRoles("Read", "Write", "Custom");
- await usersPage.toHavePermissions("read:assets", "write:assets");
+ await usersPage.toggleCompositeRoles("Read", "Write", "Custom");
+ await usersPage.toHaveRoles(ClientRole.READ_ASSETS, ClientRole.WRITE_ASSETS);
- await usersPage.toggleUserRoles("Read", "Write", "Custom");
- await usersPage.toHavePermissions(...permissions);
+ await usersPage.toggleCompositeRoles("Read", "Write", "Custom");
+ await usersPage.toHaveAllRoles();
});
/**
diff --git a/ui/app/manager/test/test.setup.ts b/ui/app/manager/test/test.setup.ts
index ba9c9239e..74879b879 100644
--- a/ui/app/manager/test/test.setup.ts
+++ b/ui/app/manager/test/test.setup.ts
@@ -19,7 +19,6 @@
import { expect } from "@openremote/test";
import { adminStatePath, test as setup, userStatePath } from "./fixtures/manager";
import { users } from "./fixtures/data/users";
-import permissions from "./fixtures/data/permissions";
const { admin, smartcity } = users;
@@ -81,7 +80,7 @@ setup.describe(async () => {
* @and Navigated to the "Users" page
* @and Added a new user "smartcity"
* @then The user "smartcity" should be visible
- * @and All default permissions should be selected
+ * @and All default roles should be selected
*/
setup(`Add user called "smartcity"`, async ({ page, manager, usersPage }) => {
const { username, password } = smartcity;
@@ -92,7 +91,7 @@ setup.describe(async () => {
await usersPage.addUser(username, password);
await expect(page.getByRole("cell", { name: "smartcity" })).toHaveCount(1);
await page.getByRole("cell", { name: "smartcity" }).click();
- await usersPage.toHavePermissions(...permissions);
+ await usersPage.toHaveAllRoles();
});
});
diff --git a/ui/app/manager/test/users.test.ts b/ui/app/manager/test/users.test.ts
index 9b822943e..8b468c4ce 100644
--- a/ui/app/manager/test/users.test.ts
+++ b/ui/app/manager/test/users.test.ts
@@ -18,7 +18,6 @@
*/
import { expect } from "@openremote/test";
import { adminStatePath, test } from "./fixtures/manager";
-import permissions from "./fixtures/data/permissions";
test.use({ storageState: adminStatePath });
@@ -91,15 +90,15 @@ test(`Verify browser behavior while creating regular users`, async ({ page, user
await usersPage.gotoUserCreation("master", "regular");
await page.getByLabel("Username").fill("mycustomusername");
await page.getByLabel("Email").fill("[email protected]");
- await usersPage.toHavePermissions();
- await usersPage.toggleUserRoles("Read", "Write");
- await usersPage.toHavePermissions(...permissions);
+ await usersPage.toHaveRoles();
+ await usersPage.toggleCompositeRoles("Read", "Write");
+ await usersPage.toHaveAllRoles();
await page.evaluate(() => {
document.dispatchEvent(new Event("visibilitychange"));
});
await expect(await page.getByRole("textbox", { name: /username/i }).inputValue()).toBe("mycustomusername");
await expect(await page.getByRole("textbox", { name: /email/i }).inputValue()).toBe("[email protected]");
- await usersPage.toHavePermissions(...permissions);
+ await usersPage.toHaveAllRoles();
});
/**
diff --git a/ui/component/or-app/src/or-header.ts b/ui/component/or-app/src/or-header.ts
index e2cf321a7..fb3e7029d 100644
--- a/ui/component/or-app/src/or-header.ts
+++ b/ui/component/or-app/src/or-header.ts
@@ -33,7 +33,7 @@ import manager, {
import "@openremote/or-mwc-components/or-mwc-dialog";
import "@openremote/or-icon";
import type { OrVaadinSelect } from "@openremote/or-vaadin-components/or-vaadin-select";
-import type { AlarmEvent, Realm } from "@openremote/model";
+import { type AlarmEvent, ClientRole, type Realm } from "@openremote/model";
import { createMenuBarItem, type MenuBarItem } from "@openremote/or-vaadin-components/or-vaadin-menu-bar";
import { type AppStateKeyed, router, updateRealm } from "./index";
import type { AnyAction, Store } from "@reduxjs/toolkit";
@@ -467,7 +467,7 @@ export class OrHeader extends OrElement {
protected async _getAlarmButton() {
let newAlarms = false;
- if (manager.hasRole("read:alarms") || manager.hasRole("read:admin")) {
+ if (manager.hasRole(ClientRole.READ_ALARMS) || manager.hasRole(ClientRole.READ_ADMIN)) {
const response = await manager.rest.api.AlarmResource.getAlarms({
realm: manager.displayRealm,
status: Model.AlarmStatus.OPEN,