100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Feature: add user tag (#1967)
Wouter Voorberg3c5e78dce4c5
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 92cd57539..c4beb1bf0 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -376,6 +376,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im.clients().get(clientRepresentation.getId()).getServiceAccountUser();userRepresentation.setEnabled(user.getEnabled());+ userRepresentation.setAttributes(user.getAttributeMap());realmsResource.realm(realm).users().get(userRepresentation.getId()).update(userRepresentation);} else {diff --git a/ui/app/manager/src/pages/page-users.ts b/ui/app/manager/src/pages/page-users.tsindex 5f07260ad..e571a75e8 100644--- a/ui/app/manager/src/pages/page-users.ts+++ b/ui/app/manager/src/pages/page-users.ts@@ -476,11 +476,12 @@ export class PageUsers extends Page<AppStateKeyed> {{title: i18next.t('firstName')},{title: i18next.t('surname')},{title: i18next.t('email'), hideMobile: true},- {title: i18next.t('status')}+ {title: i18next.t('status')},+ {title: i18next.t('tag'), isSortable: true}];const userTableRows: TableRow[] = users.map((user) => {return {- content: [user.username, user.firstName, user.lastName, user.email, user.enabled ? i18next.t('enabled') : i18next.t('disabled')] as string[],+ content: [user.username, user.firstName, user.lastName, user.email, user.enabled ? i18next.t('enabled') : i18next.t('disabled'), user.attributes?.Tag?.[0]] as string[],clickable: true}});@@ -488,11 +489,12 @@ export class PageUsers extends Page<AppStateKeyed> {// Content of Service user Tableconst serviceUserTableColumns: TableColumn[] = [{title: i18next.t('username')},- {title: i18next.t('status')}+ {title: i18next.t('status')},+ {title: i18next.t('tag'), isSortable: true}];const serviceUserTableRows: TableRow[] = serviceUsers.map((user) => {return {- content: [user.username, user.enabled ? i18next.t('enabled') : i18next.t('disabled')] as string[],+ content: [user.username, user.enabled ? i18next.t('enabled') : i18next.t('disabled'), user.attributes?.Tag?.[0]] as string[],clickable: true}})@@ -628,7 +630,8 @@ export class PageUsers extends Page<AppStateKeyed> {(u.username as string)?.toLowerCase().includes(value) ||(u.firstName as string)?.toLowerCase().includes(value) ||(u.lastName as string)?.toLowerCase().includes(value) ||- (u.email as string)?.toLowerCase().includes(value)+ (u.email as string)?.toLowerCase().includes(value) ||+ (u.attributes?.Tag?.[0] as string)?.toLowerCase().includes(value));}}@@ -641,7 +644,8 @@ export class PageUsers extends Page<AppStateKeyed> {} else {this._serviceUserFilter = (users) => {return users.filter(u =>- (u.username as string)?.includes(value)+ (u.username as string)?.includes(value) ||+ (u.attributes?.Tag?.[0] as string)?.toLowerCase().includes(value));}}@@ -910,7 +914,22 @@ export class PageUsers extends Page<AppStateKeyed> {user.lastName = e.detail.value;this.onUserChanged(suffix)}}"></or-mwc-input>-+ <or-mwc-input id="new-tag" ?readonly="${readonly || isGatewayServiceUser}"+ class= "validate"+ .label="${i18next.t("tag")}"+ .type="${InputType.TEXT}" minLength="1"+ .value="${user.attributes?.Tag?.[0]}" autocomplete="false"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ // Ensure 'attributes' and 'Tag' exist before assigning+ if (!user.attributes) {+ user.attributes = {};+ }+ if (!Array.isArray(user.attributes.Tag)) {+ user.attributes.Tag = [];+ }+ user.attributes.Tag[0] = e.detail.value;+ this.onUserChanged(suffix)+ }}"></or-mwc-input><!-- password --><h5>${i18next.t("password")}</h5>${isServiceUser ? html`@@ -959,7 +978,7 @@ export class PageUsers extends Page<AppStateKeyed> {<div class="column"><h5>${i18next.t("settings")}</h5><!-- enabled -->- <or-mwc-input ?readonly="${readonly}"+ <or-mwc-input ?readonly="${readonly || isGatewayServiceUser}"class="validate".label="${i18next.t("active")}".type="${InputType.CHECKBOX}"diff --git a/ui/app/manager/test/fixtures/pages/users.ts b/ui/app/manager/test/fixtures/pages/users.tsindex cdea06ea2..4b400c2f8 100644--- a/ui/app/manager/test/fixtures/pages/users.ts+++ b/ui/app/manager/test/fixtures/pages/users.ts@@ -55,8 +55,9 @@ export class UsersPage implements BasePage {** @param username The users' username* @param password The users' password+ * @param tag Optional tag for the user*/- async addUser(username: string, password: string) {+ async addUser(username: string, password: string, tag?: string) {await this.page.locator("#content").filter({ hasText: "Regular users" })@@ -68,6 +69,33 @@ export class UsersPage implements BasePage {.filter({ hasText: /Password/ }).fill(password);await this.page.locator("label").filter({ hasText: "Repeat password" }).fill(password);+ if (tag) {+ await this.page.locator("label").filter({ hasText: "Tag" }).fill(tag);+ }+ await this.toggleUserRoles("Read", "Write");+ await this.toHavePermissions(...permissions);+ await this.shared.interceptResponse<UserModel>(`user/${this.manager.realm}/users`, (user) => {+ if (user) this.manager.user = user;+ });+ await this.page.getByRole("button", { name: "Create" }).click();+ }++ /**+ * Create a service user for the current realm.+ *+ * @param username The service user's username+ * @param tag Optional tag for the service user+ */+ async addServiceUser(username: string, tag?: string): Promise<void> {+ await this.page+ .locator("#content")+ .filter({ hasText: "Service users" })+ .getByRole("button", { name: "Add User" })+ .click();+ await this.page.locator("label").filter({ hasText: "Username" }).fill(username);+ if (tag) {+ await this.page.locator("label").filter({ hasText: "Tag" }).fill(tag);+ }await this.toggleUserRoles("Read", "Write");await this.toHavePermissions(...permissions);await this.shared.interceptResponse<UserModel>(`user/${this.manager.realm}/users`, (user) => {@@ -75,4 +103,24 @@ export class UsersPage implements BasePage {});await this.page.getByRole("button", { name: "Create" }).click();}++ /**+ * Search for users in the regular user table.+ * @param searchTerm The term to search for+ */+ async searchRegularUsers(searchTerm: string) {+ const panel = this.page.locator("#content").filter({ hasText: "Regular users" }).first();+ const input = panel.locator('or-mwc-input[placeholder="Search"] input');+ await input.fill(searchTerm);+ }++ /**+ * Search for users in the service user table.+ * @param searchTerm The term to search for+ */+ async searchServiceUsers(searchTerm: string) {+ const panel = this.page.locator("#content").filter({ hasText: "Service users" }).first();+ const input = panel.locator('or-mwc-input[placeholder="Search"] input');+ await input.fill(searchTerm);+ }}diff --git a/ui/app/manager/test/users.test.ts b/ui/app/manager/test/users.test.tsnew file mode 100644index 000000000..944612ad2--- /dev/null+++ b/ui/app/manager/test/users.test.ts@@ -0,0 +1,99 @@+import { expect } from "@openremote/test";+import { adminStatePath, test} from "./fixtures/manager";+++test.use({ storageState: adminStatePath });++/**+ * @given Logged into the "smartcity" realm as "admin"+ * @and Navigated to the "Users" page+ * @when Creating multiple regular users with different tags+ * @and Searching by tag in the regular user table+ * @then Only the user with the matching tag should be visible+ */+test(`Create regular users with tags and search by tag`, async ({ page, manager, usersPage }) => {await manager.goToRealmStartPage("master");+ await manager.switchToRealmByRealmPicker("smartcity");+ await manager.navigateToMenuItem("Users");+ await usersPage.addUser("user1", "password123", "Company1");+ await usersPage.addUser("user2", "password123", "Company2");+ await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();++ await usersPage.searchRegularUsers("Company1");+ await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "user2", exact: true })).not.toBeVisible();++ await usersPage.searchRegularUsers("Company2");+ await expect(page.getByRole("cell", { name: "user1", exact: true })).not.toBeVisible();+ await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();++ await usersPage.searchRegularUsers("");+ await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();+});++/**+ * @given Logged into the "smartcity" realm as "admin"+ * @and Navigated to the "Users" page+ * @when Creating multiple service users with different tags+ * @and Searching by tag in the service user table+ * @then Only the service user with the matching tag should be visible+ */+test(`Create service users with tags and search by tag`, async ({ page, manager, usersPage }) => {+ await manager.goToRealmStartPage("master");+ await manager.switchToRealmByRealmPicker("smartcity");+ await manager.navigateToMenuItem("Users");+ await usersPage.addServiceUser("serviceuser1", "api");+ await usersPage.addServiceUser("serviceuser2", "integration");+ await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();++ await usersPage.searchServiceUsers("api");+ await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).not.toBeVisible();++ await usersPage.searchServiceUsers("integration");+ await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).not.toBeVisible();+ await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();++ await usersPage.searchServiceUsers("");+ await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();+ await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();+});++/**+ * @given Logged into the "smartcity" realm as "admin"+ * @when Creating a gateway asset+ * @and Waiting for the clientId to be populated+ * @and Navigating to the gateway service user+ * @then All fields should be visible but read-only and no save button should be available+ */+test(`Verify gateway service user is read-only`, async ({ page, manager, usersPage, assetsPage }) => {+ await manager.goToRealmStartPage("master");+ await manager.switchToRealmByRealmPicker("smartcity");+ await manager.navigateToTab("Assets");+ await assetsPage.addAsset("GatewayAsset", "TestGateway");+ await page.waitForURL("**/assets/**");+ const clientIdInput = page.locator(`#field-clientId input`);+ await expect(clientIdInput).not.toHaveValue("", { timeout: 15000 });+ const clientId = await clientIdInput.inputValue();+ expect(clientId).toBeTruthy();+ expect(clientId).toContain("gateway-");+ await manager.navigateToMenuItem("Users");+ const gatewayUsername = `${clientId}`;+ await usersPage.searchServiceUsers(gatewayUsername);+ await expect(page.getByRole("cell", { name: gatewayUsername, exact: true })).toBeVisible();+ await page.getByRole("cell", { name: gatewayUsername, exact: true }).click();+ const usernameInput = page.locator('[id*="username"]');+ await expect(usernameInput).toHaveAttribute("readonly");+ const tagInput = page.locator('or-mwc-input#new-tag');+ await expect(tagInput).toHaveAttribute("readonly");+ const activeCheckbox = page.locator('or-mwc-input').filter({ hasText: 'Active' }).locator('input[type="checkbox"]');+ await expect(activeCheckbox).toBeDisabled();+ const realmRolesSelect = page.locator('or-mwc-input').filter({ hasText: 'Realm roles' });+ await expect(realmRolesSelect).toHaveAttribute("disabled");+ const managerRolesSelect = page.locator('or-mwc-input').filter({ hasText: 'Manager roles' });+ await expect(managerRolesSelect).toHaveAttribute("disabled");+ const saveButton = page.getByRole("button", { name: "Save" });+ await expect(saveButton).toBeDisabled();+});diff --git a/ui/app/shared/locales/en/or.json b/ui/app/shared/locales/en/or.jsonindex 9163f2dc6..4754cfb50 100644--- a/ui/app/shared/locales/en/or.json+++ b/ui/app/shared/locales/en/or.json@@ -693,6 +693,7 @@"invalidEmail": "Invalid email address","yes": "Yes","no": "No",+ "tag": "Tag","linked": "Linked","filter": {"close": "Close filter",