From afc53622d40534ee8162481447c4e06ab167c542 Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Thu, 2 Apr 2026 18:00:32 +0200 Subject: [PATCH 1/3] Add server-side attributes tab to Device Profile and Asset Profile (#9695) Adds an Attributes tab (SERVER_SCOPE only) to both Device Profile and Asset Profile detail pages, following the same pattern used by the Asset entity. Includes tests verifying save, read, and delete of server-scope attributes via the telemetry REST API for both entity types. --- .../controller/ControllerConstants.java | 2 +- .../controller/TelemetryControllerTest.java | 46 +++++++++++++++++++ .../asset-profile-tabs.component.html | 7 +++ .../device-profile-tabs.component.html | 9 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java b/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java index a285c45133..2bf6ddfe9d 100644 --- a/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java +++ b/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java @@ -1304,7 +1304,7 @@ public class ControllerConstants { "Platform creates an audit log event about entity time series updates with action type 'TIMESERIES_UPDATED' that includes an error stacktrace."; protected static final String ENTITY_ATTRIBUTE_SCOPES_TEMPLATE = " List of possible attribute scopes depends on the entity type: " + - "\n\n * SERVER_SCOPE - supported for all entity types;" + + "\n\n * SERVER_SCOPE - supported for all entity types, including device profiles and asset profiles;" + "\n * SHARED_SCOPE - supported for devices"; protected static final String ENTITY_SAVE_ATTRIBUTE_SCOPES = ENTITY_ATTRIBUTE_SCOPES_TEMPLATE + ".\n\n"; protected static final String ENTITY_GET_ATTRIBUTE_SCOPES = ENTITY_ATTRIBUTE_SCOPES_TEMPLATE + diff --git a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java index 3ae44db1b0..2d2e75b4a5 100644 --- a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 package org.thingsboard.server.controller; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.Assert; import org.junit.Test; @@ -10,7 +11,9 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.thingsboard.common.util.JacksonUtil; +import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.SaveDeviceWithCredentialsRequest; import org.thingsboard.server.common.data.kv.BasicTsKvEntry; import org.thingsboard.server.common.data.kv.LongDataEntry; @@ -22,6 +25,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.dao.service.DaoSqlTest; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; @@ -291,6 +295,48 @@ public class TelemetryControllerTest extends AbstractControllerTest { Assert.assertTrue(tsDataAfterDeletion.get("key3").get(0).get("value").isNull()); } + @Test + public void testDeviceProfileServerScopeAttributes() throws Exception { + loginTenantAdmin(); + DeviceProfile deviceProfile = createDeviceProfile("Test Device Profile"); + DeviceProfile savedProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); + verifyServerScopeAttributes("DEVICE_PROFILE", savedProfile.getId().getId().toString()); + } + + @Test + public void testAssetProfileServerScopeAttributes() throws Exception { + loginTenantAdmin(); + AssetProfile assetProfile = createAssetProfile("Test Asset Profile"); + AssetProfile savedProfile = doPost("/api/assetProfile", assetProfile, AssetProfile.class); + verifyServerScopeAttributes("ASSET_PROFILE", savedProfile.getId().getId().toString()); + } + + private void verifyServerScopeAttributes(String entityType, String entityId) throws Exception { + String body = "{\"testKey\": \"testValue\", \"testNumber\": 42}"; + doPostAsync("/api/plugins/telemetry/" + entityType + "/" + entityId + "/attributes/SERVER_SCOPE", body, String.class, status().isOk()); + + List> attributes = doGetAsyncTyped( + "/api/plugins/telemetry/" + entityType + "/" + entityId + "/values/attributes/SERVER_SCOPE?keys=testKey,testNumber", + new TypeReference<>() {}); + + assertThat(attributes).hasSize(2); + assertThat(attributes).anySatisfy(attr -> { + assertThat(attr.get("key")).isEqualTo("testKey"); + assertThat(attr.get("value")).isEqualTo("testValue"); + }); + assertThat(attributes).anySatisfy(attr -> { + assertThat(attr.get("key")).isEqualTo("testNumber"); + assertThat(attr.get("value")).isEqualTo(42); + }); + + doDeleteAsync("/api/plugins/telemetry/" + entityType + "/" + entityId + "/SERVER_SCOPE?keys=testKey,testNumber", String.class); + + List> afterDelete = doGetAsyncTyped( + "/api/plugins/telemetry/" + entityType + "/" + entityId + "/values/attributes/SERVER_SCOPE?keys=testKey,testNumber", + new TypeReference<>() {}); + assertThat(afterDelete).isEmpty(); + } + private Device createDevice() throws Exception { String testToken = "TEST_TOKEN"; diff --git a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html index fdaf05ba56..483736dda7 100644 --- a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html +++ b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html @@ -5,6 +5,13 @@ --> @if (entity && !isEdit) { + + + + @if (authUser.authority === authorities.TENANT_ADMIN) { diff --git a/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html b/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html index 8fbd4a4026..8b3816a103 100644 --- a/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html +++ b/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html @@ -5,6 +5,15 @@ --> @if (entity) { + @if (!isEdit) { + + + + + } @if (transportType.isActive) {
From 0f4181d7147780534627e63871312dd3e7c2cc09 Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Mon, 14 Sep 2026 11:03:31 +0200 Subject: [PATCH 2/3] Fix calculated fields tab index on device and asset profile pages --- .../home/pages/asset-profile/asset-profile-tabs.component.ts | 2 +- .../home/pages/device-profile/device-profile-tabs.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts index 5c81b869dd..852681cf24 100644 --- a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts +++ b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.ts @@ -24,7 +24,7 @@ export class AssetProfileTabsComponent extends EntityTabsComponent resolveTabIndex(tab: string): number { if (tab === 'cf') { - return 1; + return 2; } else { return super.resolveTabIndex(tab); } diff --git a/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts b/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts index 0029891d53..02a1a025c0 100644 --- a/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts +++ b/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts @@ -47,7 +47,7 @@ export class DeviceProfileTabsComponent extends EntityTabsComponent Date: Tue, 20 Oct 2026 14:25:32 +0200 Subject: [PATCH 3/3] Respect attribute permissions on device and asset profile attributes tab --- .../asset-profile-tabs.component.html | 17 ++++++++++------- .../device-profile-tabs.component.html | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html index 2169d92c29..e49a375aea 100644 --- a/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html +++ b/ui-ngx/src/app/modules/home/pages/asset-profile/asset-profile-tabs.component.html @@ -6,13 +6,16 @@ --> @if (entity && !isEdit) { - - - - + @if (resource.ASSET_PROFILE | hasGenericPermission: operation.READ_ATTRIBUTES) { + + + + + } @if (authUser.authority === authorities.TENANT_ADMIN && (resource.ASSET_PROFILE | hasGenericPermission: operation.READ_CALCULATED_FIELD)) { @if (entity) { - @if (!isEdit) { + @if (!isEdit && (resource.DEVICE_PROFILE | hasGenericPermission: operation.READ_ATTRIBUTES)) {