Merge pull request #4906 from deaflynx/edge/cleanups-fixes

WIP [3.3.0] Fixed Edge RBAC, widget bundles, UI
This commit is contained in:
Igor Kulikov 2021-07-14 17:28:28 +03:00 committed by GitHub
commit fae3a9d9a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 30 additions and 41 deletions

View File

@ -434,7 +434,7 @@ public class AssetController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
AssetId assetId = new AssetId(toUUID(strAssetId)); AssetId assetId = new AssetId(toUUID(strAssetId));
checkAssetId(assetId, Operation.ASSIGN_TO_EDGE); checkAssetId(assetId, Operation.READ);
Asset savedAsset = checkNotNull(assetService.assignAssetToEdge(getTenantId(), assetId, edgeId)); Asset savedAsset = checkNotNull(assetService.assignAssetToEdge(getTenantId(), assetId, edgeId));
@ -467,7 +467,7 @@ public class AssetController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
AssetId assetId = new AssetId(toUUID(strAssetId)); 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)); Asset savedAsset = checkNotNull(assetService.unassignAssetFromEdge(getTenantId(), assetId, edgeId));

View File

@ -657,7 +657,7 @@ public class DashboardController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId)); 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)); Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));
@ -689,7 +689,7 @@ public class DashboardController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
DashboardId dashboardId = new DashboardId(toUUID(strDashboardId)); 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)); Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromEdge(getCurrentUser().getTenantId(), dashboardId, edgeId));

View File

@ -682,7 +682,7 @@ public class DeviceController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); 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)); Device savedDevice = checkNotNull(deviceService.assignDeviceToEdge(getCurrentUser().getTenantId(), deviceId, edgeId));
@ -716,7 +716,7 @@ public class DeviceController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
DeviceId deviceId = new DeviceId(toUUID(strDeviceId)); 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)); Device savedDevice = checkNotNull(deviceService.unassignDeviceFromEdge(getCurrentUser().getTenantId(), deviceId, edgeId));

View File

@ -80,7 +80,7 @@ public class EdgeController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) { if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) {
cleanUpSensitiveData(edge); cleanUpLicenseKey(edge);
} }
return edge; return edge;
} catch (Exception e) { } catch (Exception e) {
@ -97,7 +97,7 @@ public class EdgeController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
EdgeInfo edgeInfo = checkEdgeInfoId(edgeId, Operation.READ); EdgeInfo edgeInfo = checkEdgeInfoId(edgeId, Operation.READ);
if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) { if (Authority.CUSTOMER_USER.equals(getCurrentUser().getAuthority())) {
cleanUpSensitiveData(edgeInfo); cleanUpLicenseKey(edgeInfo);
} }
return edgeInfo; return edgeInfo;
} catch (Exception e) { } catch (Exception e) {
@ -404,7 +404,7 @@ public class EdgeController extends BaseController {
} }
if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
for (Edge edge : result.getData()) { for (Edge edge : result.getData()) {
cleanUpSensitiveData(edge); cleanUpLicenseKey(edge);
} }
} }
return checkNotNull(result); return checkNotNull(result);
@ -439,7 +439,7 @@ public class EdgeController extends BaseController {
} }
if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
for (Edge edge : result.getData()) { for (Edge edge : result.getData()) {
cleanUpSensitiveData(edge); cleanUpLicenseKey(edge);
} }
} }
return checkNotNull(result); return checkNotNull(result);
@ -471,7 +471,7 @@ public class EdgeController extends BaseController {
List<Edge> edges = edgesFuture.get(); List<Edge> edges = edgesFuture.get();
if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
for (Edge edge : edges) { for (Edge edge : edges) {
cleanUpSensitiveData(edge); cleanUpLicenseKey(edge);
} }
} }
return checkNotNull(edges); return checkNotNull(edges);
@ -502,7 +502,7 @@ public class EdgeController extends BaseController {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if (Authority.CUSTOMER_USER.equals(user.getAuthority())) { if (Authority.CUSTOMER_USER.equals(user.getAuthority())) {
for (Edge edge : edges) { for (Edge edge : edges) {
cleanUpSensitiveData(edge); cleanUpLicenseKey(edge);
} }
} }
return edges; return edges;
@ -580,11 +580,7 @@ public class EdgeController extends BaseController {
} }
} }
private void cleanUpSensitiveData(Edge edge) { private void cleanUpLicenseKey(Edge edge) {
edge.setEdgeLicenseKey(null); edge.setEdgeLicenseKey(null);
edge.setRoutingKey(null);
edge.setSecret(null);
edge.setCloudEndpoint(null);
edge.setRootRuleChainId(null);
} }
} }

View File

@ -626,7 +626,7 @@ public class EntityViewController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId)); EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
checkEntityViewId(entityViewId, Operation.ASSIGN_TO_EDGE); checkEntityViewId(entityViewId, Operation.READ);
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToEdge(getTenantId(), entityViewId, edgeId)); EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToEdge(getTenantId(), entityViewId, edgeId));
logEntityAction(entityViewId, savedEntityView, logEntityAction(entityViewId, savedEntityView,
@ -656,7 +656,7 @@ public class EntityViewController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId)); 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)); EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId));
logEntityAction(entityViewId, entityView, logEntityAction(entityViewId, entityView,

View File

@ -506,7 +506,7 @@ public class RuleChainController extends BaseController {
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId)); 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)); RuleChain savedRuleChain = checkNotNull(ruleChainService.assignRuleChainToEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId));
@ -538,7 +538,7 @@ public class RuleChainController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
Edge edge = checkEdgeId(edgeId, Operation.READ); Edge edge = checkEdgeId(edgeId, Operation.READ);
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId)); 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)); RuleChain savedRuleChain = checkNotNull(ruleChainService.unassignRuleChainFromEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId, false));

View File

@ -19,6 +19,6 @@ public enum Operation {
ALL, CREATE, READ, WRITE, DELETE, ASSIGN_TO_CUSTOMER, UNASSIGN_FROM_CUSTOMER, RPC_CALL, 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, 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
} }

View File

@ -40,12 +40,6 @@
</fieldset> </fieldset>
</div> </div>
<div mat-dialog-actions fxLayoutAlign="end center"> <div mat-dialog-actions fxLayoutAlign="end center">
<button mat-raised-button color="primary"
type="submit"
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid
|| !addEntitiesToEdgeFormGroup.dirty">
{{ 'action.assign' | translate }}
</button>
<button mat-button color="primary" <button mat-button color="primary"
style="margin-right: 20px;" style="margin-right: 20px;"
type="button" type="button"
@ -53,5 +47,11 @@
(click)="cancel()"> (click)="cancel()">
{{ 'action.cancel' | translate }} {{ 'action.cancel' | translate }}
</button> </button>
<button mat-raised-button color="primary"
type="submit"
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid
|| !addEntitiesToEdgeFormGroup.dirty">
{{ 'action.assign' | translate }}
</button>
</div> </div>
</form> </form>

View File

@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends
public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>, public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>,
public fb: FormBuilder) { public fb: FormBuilder) {
super(store, router, dialogRef); super(store, router, dialogRef);
this.entityType = data.entityType; this.entityType = this.data.entityType;
} }
ngOnInit(): void { ngOnInit(): void {
@ -77,7 +77,7 @@ export class AddEntitiesToEdgeDialogComponent extends
entityIds: [null, [Validators.required]] entityIds: [null, [Validators.required]]
}); });
this.subType = ''; this.subType = '';
switch (this.data.entityType) { switch (this.entityType) {
case EntityType.DEVICE: case EntityType.DEVICE:
this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; this.assignToEdgeTitle = 'device.assign-device-to-edge-title';
this.assignToEdgeText = 'device.assign-device-to-edge-text'; this.assignToEdgeText = 'device.assign-device-to-edge-text';
@ -118,7 +118,7 @@ export class AddEntitiesToEdgeDialogComponent extends
const tasks: Observable<any>[] = []; const tasks: Observable<any>[] = [];
entityIds.forEach( entityIds.forEach(
(entityId) => { (entityId) => {
tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId)); tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId, this.entityType));
} }
); );
forkJoin(tasks).subscribe( forkJoin(tasks).subscribe(
@ -128,8 +128,8 @@ export class AddEntitiesToEdgeDialogComponent extends
); );
} }
private getAssignToEdgeTask(edgeId: string, entityId: string): Observable<any> { private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable<any> {
switch (this.data.entityType) { switch (entityType) {
case EntityType.DEVICE: case EntityType.DEVICE:
return this.deviceService.assignDeviceToEdge(edgeId, entityId); return this.deviceService.assignDeviceToEdge(edgeId, entityId);
case EntityType.ASSET: case EntityType.ASSET:

View File

@ -121,14 +121,7 @@ export class WidgetsBundlesTableConfigResolver implements Resolve<EntityTableCon
this.config.entitySelectionEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); this.config.entitySelectionEnabled = (widgetsBundle) => this.isWidgetsBundleEditable(widgetsBundle, authUser.authority);
this.config.detailsReadonly = (widgetsBundle) => !this.isWidgetsBundleEditable(widgetsBundle, authUser.authority); this.config.detailsReadonly = (widgetsBundle) => !this.isWidgetsBundleEditable(widgetsBundle, authUser.authority);
const authState = getCurrentAuthState(this.store); const authState = getCurrentAuthState(this.store);
this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink).pipe( this.config.entitiesFetchFunction = pageLink => this.widgetsService.getWidgetBundles(pageLink);
map((widgetBundles) => {
if (!authState.edgesSupportEnabled) {
widgetBundles.data = widgetBundles.data.filter(widgetBundle => widgetBundle.alias !== 'edge_widgets');
}
return widgetBundles;
})
);
return this.config; return this.config;
} }