Fix permissions for Rules and Plugins details

This commit is contained in:
Igor Kulikov 2017-06-08 12:20:41 +03:00
parent ec39c15e37
commit 1b469df40c
7 changed files with 49 additions and 17 deletions

View File

@ -326,7 +326,19 @@ public final class PluginProcessingContext implements PluginContext {
callback.onSuccess(this, Boolean.FALSE); callback.onSuccess(this, Boolean.FALSE);
} else { } else {
ListenableFuture<RuleMetaData> ruleFuture = pluginCtx.ruleService.findRuleByIdAsync(new RuleId(entityId.getId())); ListenableFuture<RuleMetaData> ruleFuture = pluginCtx.ruleService.findRuleByIdAsync(new RuleId(entityId.getId()));
Futures.addCallback(ruleFuture, getCallback(callback, rule -> rule != null && rule.getTenantId().equals(ctx.getTenantId()))); Futures.addCallback(ruleFuture, getCallback(callback, rule -> {
if (rule == null) {
return Boolean.FALSE;
} else {
if (ctx.isTenantAdmin() && !rule.getTenantId().equals(ctx.getTenantId())) {
return Boolean.FALSE;
} else if (ctx.isSystemAdmin() && !rule.getTenantId().isNullUid()) {
return Boolean.FALSE;
} else {
return Boolean.TRUE;
}
}
}));
} }
return; return;
case PLUGIN: case PLUGIN:
@ -334,7 +346,19 @@ public final class PluginProcessingContext implements PluginContext {
callback.onSuccess(this, Boolean.FALSE); callback.onSuccess(this, Boolean.FALSE);
} else { } else {
ListenableFuture<PluginMetaData> pluginFuture = pluginCtx.pluginService.findPluginByIdAsync(new PluginId(entityId.getId())); ListenableFuture<PluginMetaData> pluginFuture = pluginCtx.pluginService.findPluginByIdAsync(new PluginId(entityId.getId()));
Futures.addCallback(pluginFuture, getCallback(callback, plugin -> plugin != null && plugin.getTenantId().equals(ctx.getTenantId()))); Futures.addCallback(pluginFuture, getCallback(callback, plugin -> {
if (plugin == null) {
return Boolean.FALSE;
} else {
if (ctx.isTenantAdmin() && !plugin.getTenantId().equals(ctx.getTenantId())) {
return Boolean.FALSE;
} else if (ctx.isSystemAdmin() && !plugin.getTenantId().isNullUid()) {
return Boolean.FALSE;
} else {
return Boolean.TRUE;
}
}
}));
} }
return; return;
case CUSTOMER: case CUSTOMER:

View File

@ -51,7 +51,6 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.types = types; scope.types = types;
scope.entityType = attrs.entityType; scope.entityType = attrs.entityType;
scope.attributeScope = getAttributeScopeByValue(attrs.defaultAttributeScope);
if (scope.entityType === types.entityType.device) { if (scope.entityType === types.entityType.device) {
scope.attributeScopes = types.attributesScope; scope.attributeScopes = types.attributesScope;
@ -60,8 +59,13 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.attributeScopes = {}; scope.attributeScopes = {};
scope.attributeScopes.server = types.attributesScope.server; scope.attributeScopes.server = types.attributesScope.server;
scope.attributeScopeSelectionReadonly = true; scope.attributeScopeSelectionReadonly = true;
}
scope.attributeScope = getAttributeScopeByValue(attrs.defaultAttributeScope);
if (scope.entityType != types.entityType.device) {
if (scope.attributeScope != types.latestTelemetry) { if (scope.attributeScope != types.latestTelemetry) {
scope.attributeScope = scope.attributeScopes.server.value; scope.attributeScope = scope.attributeScopes.server;
} }
} }
@ -81,8 +85,8 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
search: null search: null
}; };
scope.$watch("entityId", function(newVal, prevVal) { scope.$watch("entityId", function(newVal) {
if (newVal && !angular.equals(newVal, prevVal)) { if (newVal) {
scope.resetFilter(); scope.resetFilter();
scope.getEntityAttributes(false, true); scope.getEntityAttributes(false, true);
} }

View File

@ -171,7 +171,7 @@ export default angular.module('thingsboard.locale', [])
"attribute": { "attribute": {
"attributes": "Attributes", "attributes": "Attributes",
"latest-telemetry": "Latest telemetry", "latest-telemetry": "Latest telemetry",
"attributes-scope": "Device attributes scope", "attributes-scope": "Entity attributes scope",
"scope-latest-telemetry": "Latest telemetry", "scope-latest-telemetry": "Latest telemetry",
"scope-client": "Client attributes", "scope-client": "Client attributes",
"scope-server": "Server attributes", "scope-server": "Server attributes",

View File

@ -138,6 +138,8 @@ export default function PluginController(pluginService, userService, importExpor
vm.pluginGridConfig.topIndex = $stateParams.topIndex; vm.pluginGridConfig.topIndex = $stateParams.topIndex;
} }
vm.isPluginEditable = isPluginEditable;
vm.activatePlugin = activatePlugin; vm.activatePlugin = activatePlugin;
vm.suspendPlugin = suspendPlugin; vm.suspendPlugin = suspendPlugin;
vm.exportPlugin = exportPlugin; vm.exportPlugin = exportPlugin;

View File

@ -19,7 +19,7 @@
<details-buttons tb-help="vm.helpLinkIdForPlugin()" help-container-id="help-container"> <details-buttons tb-help="vm.helpLinkIdForPlugin()" help-container-id="help-container">
<div id="help-container"></div> <div id="help-container"></div>
</details-buttons> </details-buttons>
<md-tabs ng-class="{'tb-headless': vm.grid.detailsConfig.isDetailsEditMode}" <md-tabs ng-class="{'tb-headless': (vm.grid.detailsConfig.isDetailsEditMode || !vm.isPluginEditable(vm.grid.operatingItem()))}"
id="tabs" md-border-bottom flex class="tb-absolute-fill"> id="tabs" md-border-bottom flex class="tb-absolute-fill">
<md-tab label="{{ 'plugin.details' | translate }}"> <md-tab label="{{ 'plugin.details' | translate }}">
<tb-plugin plugin="vm.grid.operatingItem()" <tb-plugin plugin="vm.grid.operatingItem()"
@ -31,7 +31,7 @@
on-export-plugin="vm.exportPlugin(event, vm.grid.detailsConfig.currentItem)" on-export-plugin="vm.exportPlugin(event, vm.grid.detailsConfig.currentItem)"
on-delete-plugin="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"></tb-plugin> on-delete-plugin="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"></tb-plugin>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'attribute.attributes' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isPluginEditable(vm.grid.operatingItem())" label="{{ 'attribute.attributes' | translate }}">
<tb-attribute-table flex <tb-attribute-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.plugin}}" entity-type="{{vm.types.entityType.plugin}}"
@ -39,7 +39,7 @@
default-attribute-scope="{{vm.types.attributesScope.server.value}}"> default-attribute-scope="{{vm.types.attributesScope.server.value}}">
</tb-attribute-table> </tb-attribute-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'attribute.latest-telemetry' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isPluginEditable(vm.grid.operatingItem())" label="{{ 'attribute.latest-telemetry' | translate }}">
<tb-attribute-table flex <tb-attribute-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.plugin}}" entity-type="{{vm.types.entityType.plugin}}"
@ -48,7 +48,7 @@
disable-attribute-scope-selection="true"> disable-attribute-scope-selection="true">
</tb-attribute-table> </tb-attribute-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'plugin.events' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isPluginEditable(vm.grid.operatingItem())" label="{{ 'plugin.events' | translate }}">
<tb-event-table flex entity-type="vm.types.entityType.plugin" <tb-event-table flex entity-type="vm.types.entityType.plugin"
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
tenant-id="vm.grid.operatingItem().tenantId.id" tenant-id="vm.grid.operatingItem().tenantId.id"
@ -56,7 +56,7 @@
disabled-event-types="{{vm.types.eventType.alarm.value}}"> disabled-event-types="{{vm.types.eventType.alarm.value}}">
</tb-event-table> </tb-event-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'relation.relations' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isPluginEditable(vm.grid.operatingItem())" label="{{ 'relation.relations' | translate }}">
<tb-relation-table flex <tb-relation-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.plugin}}"> entity-type="{{vm.types.entityType.plugin}}">

View File

@ -134,6 +134,8 @@ export default function RuleController(ruleService, userService, importExport, $
vm.ruleGridConfig.topIndex = $stateParams.topIndex; vm.ruleGridConfig.topIndex = $stateParams.topIndex;
} }
vm.isRuleEditable = isRuleEditable;
vm.activateRule = activateRule; vm.activateRule = activateRule;
vm.suspendRule = suspendRule; vm.suspendRule = suspendRule;
vm.exportRule = exportRule; vm.exportRule = exportRule;

View File

@ -19,7 +19,7 @@
<details-buttons tb-help="'rules'" help-container-id="help-container"> <details-buttons tb-help="'rules'" help-container-id="help-container">
<div id="help-container"></div> <div id="help-container"></div>
</details-buttons> </details-buttons>
<md-tabs ng-class="{'tb-headless': vm.grid.detailsConfig.isDetailsEditMode}" <md-tabs ng-class="{'tb-headless': (vm.grid.detailsConfig.isDetailsEditMode || !vm.isRuleEditable(vm.grid.operatingItem()))}"
id="tabs" md-border-bottom flex class="tb-absolute-fill"> id="tabs" md-border-bottom flex class="tb-absolute-fill">
<md-tab label="{{ 'rule.details' | translate }}"> <md-tab label="{{ 'rule.details' | translate }}">
<tb-rule rule="vm.grid.operatingItem()" <tb-rule rule="vm.grid.operatingItem()"
@ -31,7 +31,7 @@
on-export-rule="vm.exportRule(event, vm.grid.detailsConfig.currentItem)" on-export-rule="vm.exportRule(event, vm.grid.detailsConfig.currentItem)"
on-delete-rule="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"></tb-rule> on-delete-rule="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"></tb-rule>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'attribute.attributes' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isRuleEditable(vm.grid.operatingItem())" label="{{ 'attribute.attributes' | translate }}">
<tb-attribute-table flex <tb-attribute-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.rule}}" entity-type="{{vm.types.entityType.rule}}"
@ -39,7 +39,7 @@
default-attribute-scope="{{vm.types.attributesScope.server.value}}"> default-attribute-scope="{{vm.types.attributesScope.server.value}}">
</tb-attribute-table> </tb-attribute-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'attribute.latest-telemetry' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isRuleEditable(vm.grid.operatingItem())" label="{{ 'attribute.latest-telemetry' | translate }}">
<tb-attribute-table flex <tb-attribute-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.rule}}" entity-type="{{vm.types.entityType.rule}}"
@ -48,7 +48,7 @@
disable-attribute-scope-selection="true"> disable-attribute-scope-selection="true">
</tb-attribute-table> </tb-attribute-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'rule.events' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isRuleEditable(vm.grid.operatingItem())" label="{{ 'rule.events' | translate }}">
<tb-event-table flex entity-type="vm.types.entityType.rule" <tb-event-table flex entity-type="vm.types.entityType.rule"
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
tenant-id="vm.grid.operatingItem().tenantId.id" tenant-id="vm.grid.operatingItem().tenantId.id"
@ -56,7 +56,7 @@
disabled-event-types="{{vm.types.eventType.alarm.value}}"> disabled-event-types="{{vm.types.eventType.alarm.value}}">
</tb-event-table> </tb-event-table>
</md-tab> </md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" label="{{ 'relation.relations' | translate }}"> <md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.isRuleEditable(vm.grid.operatingItem())" label="{{ 'relation.relations' | translate }}">
<tb-relation-table flex <tb-relation-table flex
entity-id="vm.grid.operatingItem().id.id" entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.rule}}"> entity-type="{{vm.types.entityType.rule}}">