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 573174558d..1abe594b2c 100644 --- a/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java +++ b/application/src/main/java/org/thingsboard/server/controller/ControllerConstants.java @@ -1435,7 +1435,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 bb8a43bcd4..ec6a30c1ba 100644 --- a/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/TelemetryControllerTest.java @@ -13,8 +13,10 @@ 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.AttributeScope; 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.audit.ActionType; import org.thingsboard.server.common.data.audit.AuditLog; @@ -32,6 +34,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.UUID; import java.util.concurrent.TimeUnit; @@ -361,6 +364,48 @@ public class TelemetryControllerTest extends AbstractControllerTest { .until(() -> attributesService.find(tenantId, deviceProfileId, AttributeScope.SERVER_SCOPE, "attr").get().isEmpty()); } + @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 6ac250c481..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,6 +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)) { 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.html b/ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.html index 57bec97572..90f6029043 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 @@ -6,6 +6,16 @@ --> @if (entity) { + @if (!isEdit && (resource.DEVICE_PROFILE | hasGenericPermission: operation.READ_ATTRIBUTES)) { + + + + + } @if (transportType.isActive) {
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 aab37fdb86..cc85313db3 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 @@ -51,7 +51,7 @@ export class DeviceProfileTabsComponent extends EntityTabsComponent