From 50127b8cc70043bfd61bd43d25a37c8db40015ad Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 3 Jun 2021 17:57:49 +0300 Subject: [PATCH 1/4] EdgeController: clear only license for customer users. Deleted ASSIGN_TO_EDGE, UNASSIGN_FROM_EDGE --- .../server/controller/AssetController.java | 4 ++-- .../server/controller/DashboardController.java | 4 ++-- .../server/controller/DeviceController.java | 4 ++-- .../server/controller/EdgeController.java | 18 +++++++----------- .../controller/EntityViewController.java | 4 ++-- .../server/controller/RuleChainController.java | 4 ++-- .../service/security/permission/Operation.java | 2 +- 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/AssetController.java b/application/src/main/java/org/thingsboard/server/controller/AssetController.java index 19280716b3..4854c96941 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AssetController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AssetController.java @@ -434,7 +434,7 @@ public class AssetController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); AssetId assetId = new AssetId(toUUID(strAssetId)); - checkAssetId(assetId, Operation.ASSIGN_TO_EDGE); + checkAssetId(assetId, Operation.READ); Asset savedAsset = checkNotNull(assetService.assignAssetToEdge(getTenantId(), assetId, edgeId)); @@ -467,7 +467,7 @@ public class AssetController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); AssetId assetId = new AssetId(toUUID(strAssetId)); - Asset asset = checkAssetId(assetId, Operation.UNASSIGN_FROM_EDGE); + Asset asset = checkAssetId(assetId, Operation.READ); Asset savedAsset = checkNotNull(assetService.unassignAssetFromEdge(getTenantId(), assetId, edgeId)); diff --git a/application/src/main/java/org/thingsboard/server/controller/DashboardController.java b/application/src/main/java/org/thingsboard/server/controller/DashboardController.java index 570f925c45..cb4f546556 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DashboardController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DashboardController.java @@ -657,7 +657,7 @@ public class DashboardController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); DashboardId dashboardId = new DashboardId(toUUID(strDashboardId)); - checkDashboardId(dashboardId, Operation.ASSIGN_TO_EDGE); + checkDashboardId(dashboardId, Operation.READ); Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId)); @@ -689,7 +689,7 @@ public class DashboardController extends BaseController { EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); Edge edge = checkEdgeId(edgeId, Operation.READ); DashboardId dashboardId = new DashboardId(toUUID(strDashboardId)); - Dashboard dashboard = checkDashboardId(dashboardId, Operation.UNASSIGN_FROM_EDGE); + Dashboard dashboard = checkDashboardId(dashboardId, Operation.READ); Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromEdge(getCurrentUser().getTenantId(), dashboardId, edgeId)); diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java index b13393515c..b315eb2294 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java @@ -682,7 +682,7 @@ public class DeviceController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); - checkDeviceId(deviceId, Operation.ASSIGN_TO_EDGE); + checkDeviceId(deviceId, Operation.READ); Device savedDevice = checkNotNull(deviceService.assignDeviceToEdge(getCurrentUser().getTenantId(), deviceId, edgeId)); @@ -716,7 +716,7 @@ public class DeviceController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); - Device device = checkDeviceId(deviceId, Operation.UNASSIGN_FROM_EDGE); + Device device = checkDeviceId(deviceId, Operation.READ); Device savedDevice = checkNotNull(deviceService.unassignDeviceFromEdge(getCurrentUser().getTenantId(), deviceId, edgeId)); diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index 9c196c6bd2..e5db18d09c 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -81,7 +81,7 @@ public class EdgeController extends BaseController { EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); Edge edge = checkEdgeId(edgeId, Operation.READ); if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) { - cleanUpSensitiveData(edge); + cleanUpLicenseKey(edge); } return edge; } catch (Exception e) { @@ -98,7 +98,7 @@ public class EdgeController extends BaseController { EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); EdgeInfo edgeInfo = checkEdgeInfoId(edgeId, Operation.READ); if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) { - cleanUpSensitiveData(edgeInfo); + cleanUpLicenseKey(edgeInfo); } return edgeInfo; } catch (Exception e) { @@ -405,7 +405,7 @@ public class EdgeController extends BaseController { } if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { for (Edge edge : result.getData()) { - cleanUpSensitiveData(edge); + cleanUpLicenseKey(edge); } } return checkNotNull(result); @@ -440,7 +440,7 @@ public class EdgeController extends BaseController { } if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { for (Edge edge : result.getData()) { - cleanUpSensitiveData(edge); + cleanUpLicenseKey(edge); } } return checkNotNull(result); @@ -472,7 +472,7 @@ public class EdgeController extends BaseController { List edges = edgesFuture.get(); if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { for (Edge edge : edges) { - cleanUpSensitiveData(edge); + cleanUpLicenseKey(edge); } } return checkNotNull(edges); @@ -503,7 +503,7 @@ public class EdgeController extends BaseController { }).collect(Collectors.toList()); if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { for (Edge edge : edges) { - cleanUpSensitiveData(edge); + cleanUpLicenseKey(edge); } } return edges; @@ -583,11 +583,7 @@ public class EdgeController extends BaseController { } } - private void cleanUpSensitiveData(Edge edge) { + private void cleanUpLicenseKey(Edge edge) { edge.setEdgeLicenseKey(null); - edge.setRoutingKey(null); - edge.setSecret(null); - edge.setCloudEndpoint(null); - edge.setRootRuleChainId(null); } } diff --git a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java index 5e9103a66a..63c151b24c 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java @@ -626,7 +626,7 @@ public class EntityViewController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId)); - checkEntityViewId(entityViewId, Operation.ASSIGN_TO_EDGE); + checkEntityViewId(entityViewId, Operation.READ); EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToEdge(getTenantId(), entityViewId, edgeId)); logEntityAction(entityViewId, savedEntityView, @@ -656,7 +656,7 @@ public class EntityViewController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId)); - EntityView entityView = checkEntityViewId(entityViewId, Operation.UNASSIGN_FROM_EDGE); + EntityView entityView = checkEntityViewId(entityViewId, Operation.READ); EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId)); logEntityAction(entityViewId, entityView, diff --git a/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java b/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java index d5fcc2706f..9adc99c305 100644 --- a/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java +++ b/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java @@ -500,7 +500,7 @@ public class RuleChainController extends BaseController { Edge edge = checkEdgeId(edgeId, Operation.READ); RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId)); - checkRuleChain(ruleChainId, Operation.ASSIGN_TO_EDGE); + checkRuleChain(ruleChainId, Operation.READ); RuleChain savedRuleChain = checkNotNull(ruleChainService.assignRuleChainToEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId)); @@ -532,7 +532,7 @@ public class RuleChainController extends BaseController { EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); Edge edge = checkEdgeId(edgeId, Operation.READ); RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId)); - RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.UNASSIGN_FROM_EDGE); + RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.READ); RuleChain savedRuleChain = checkNotNull(ruleChainService.unassignRuleChainFromEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId, false)); diff --git a/application/src/main/java/org/thingsboard/server/service/security/permission/Operation.java b/application/src/main/java/org/thingsboard/server/service/security/permission/Operation.java index 074943f1a6..1194c8a745 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/permission/Operation.java +++ b/application/src/main/java/org/thingsboard/server/service/security/permission/Operation.java @@ -19,6 +19,6 @@ public enum Operation { ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL, READ_CREDENTIALS, WRITE_CREDENTIALS, READ_ATTRIBUTES, WRITE_ATTRIBUTES, READ_TELEMETRY, WRITE_TELEMETRY, CLAIM_DEVICES, - ASSIGN_TO_TENANT, ASSIGN_TO_EDGE, UNASSIGN_FROM_EDGE + ASSIGN_TO_TENANT } From 633131574aba096fecaa871753bc8538876e0375 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 3 Jun 2021 17:59:12 +0300 Subject: [PATCH 2/4] Remove UI widgetBundles filter if Edge if disabled --- .../widget/widgets-bundles-table-config.resolver.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts index 735b56a783..5a50e4272f 100644 --- a/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/widget/widgets-bundles-table-config.resolver.ts @@ -121,14 +121,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); this.config.detailsReadonly = (widgetsBundle) => !this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); const authState = getCurrentAuthState(this.store); - this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink).pipe( - map((widgetBundles) => { - if (!authState.edgesSupportEnabled) { - widgetBundles.data = widgetBundles.data.filter(widgetBundle => widgetBundle.alias !== 'edge_widgets'); - } - return widgetBundles; - }) - ); + this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink); return this.config; } From dbadab6e9bb41a4e39daa8c37a7729348e1c9882 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 3 Jun 2021 17:59:52 +0300 Subject: [PATCH 3/4] Minor refactoring for merge with PE --- ui-ngx/src/app/core/http/entity.service.ts | 2 +- .../edge/edge-downlink-table-config.ts | 38 +++++++------------ ...add-entities-to-edge-dialog.component.html | 12 +++--- .../add-entities-to-edge-dialog.component.ts | 10 ++--- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index c58e5ac909..f6277b36b4 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -1342,7 +1342,7 @@ export class EntityService { return entitiesObservable; } - public getEdgeEventContentByEntityType(entity: any): Observable { + public getEdgeEventContent(entity: any): Observable { let entityObservable: Observable; const entityId: string = entity.entityId; const entityType: any = entity.type; diff --git a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts index 8f2f9a776d..4161527b9b 100644 --- a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts @@ -47,8 +47,8 @@ import { AttributeService } from '@core/http/attribute.service'; import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; import { EdgeService } from '@core/http/edge.service'; -import { map } from 'rxjs/operators'; -import { EntityService } from "@core/http/entity.service"; +import { map, mergeMap } from 'rxjs/operators'; +import { EntityService } from '@core/http/entity.service'; export class EdgeDownlinkTableConfig extends EntityTableConfig { @@ -85,26 +85,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig> { - this.loadEdgeInfo(); - return this.edgeService.getEdgeEvents(this.entityId, pageLink); - } - - loadEdgeInfo(): void { - this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']) - .subscribe( - attributes => this.onUpdate(attributes) - ); - } - - onUpdate(attributes) { - this.queueStartTs = 0; - let edge = attributes.reduce(function (map, attribute) { - map[attribute.key] = attribute; - return map; - }, {}); - if (edge.queueStartTs) { - this.queueStartTs = edge.queueStartTs.lastUpdateTs; - } + return this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']).pipe( + map((attributes) => { + const queueStartTs = attributes[0]; + this.queueStartTs = queueStartTs ? queueStartTs.lastUpdateTs : 0; + }), + mergeMap(() => this.edgeService.getEdgeEvents(this.entityId, pageLink)) + ); } updateColumns(updateTableColumns: boolean = false): void { @@ -129,7 +116,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.isEdgeEventHasData(entity.type), onAction: ($event, entity) => { - this.prepareEdgeEventContent(entity).subscribe((content) => { + this.prepareEdgeEventContent(entity).subscribe( + (content) => { this.showEdgeEventContent($event, content,'event.data'); }); } @@ -142,7 +130,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig { - return this.entityService.getEdgeEventContentByEntityType(entity).pipe( + return this.entityService.getEdgeEventContent(entity).pipe( map((result) => JSON.stringify(result)) ); } diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html index 82f166d71a..64aba5a711 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html @@ -40,12 +40,6 @@
- +
diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts index 1cd9ba87ba..ec4418403a 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts @@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends public dialogRef: MatDialogRef, public fb: FormBuilder) { super(store, router, dialogRef); - this.entityType = data.entityType; + this.entityType = this.data.entityType; } ngOnInit(): void { @@ -77,7 +77,7 @@ export class AddEntitiesToEdgeDialogComponent extends entityIds: [null, [Validators.required]] }); this.subType = ''; - switch (this.data.entityType) { + switch (this.entityType) { case EntityType.DEVICE: this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; this.assignToEdgeText = 'device.assign-device-to-edge-text'; @@ -118,7 +118,7 @@ export class AddEntitiesToEdgeDialogComponent extends const tasks: Observable[] = []; entityIds.forEach( (entityId) => { - tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId)); + tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId, this.entityType)); } ); forkJoin(tasks).subscribe( @@ -128,8 +128,8 @@ export class AddEntitiesToEdgeDialogComponent extends ); } - private getAssignToEdgeTask(edgeId: string, entityId: string): Observable { - switch (this.data.entityType) { + private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable { + switch (entityType) { case EntityType.DEVICE: return this.deviceService.assignDeviceToEdge(edgeId, entityId); case EntityType.ASSET: From cbe5a264974b7d482edaf31a98a9ccc17a289fe8 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Mon, 7 Jun 2021 07:44:32 +0300 Subject: [PATCH 4/4] Minor code cleanup --- .../home/components/edge/edge-downlink-table-config.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts index 4161527b9b..9ce8db0689 100644 --- a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts @@ -74,12 +74,10 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig; this.entitiesFetchFunction = pageLink => this.fetchEvents(pageLink); - this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC}; + this.defaultSortOrder = { property: 'createdTime', direction: Direction.DESC }; this.updateColumns(); }