Display edge related entities on customer level

This commit is contained in:
Volodymyr Babak 2020-12-29 16:03:22 +02:00
parent 15f4a85dec
commit 2ec11b2af1
12 changed files with 348 additions and 182 deletions

View File

@ -415,7 +415,7 @@ public class AssetController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/assets", params = {"limit"}, method = RequestMethod.GET)
@ResponseBody
public TimePageData<Asset> getEdgeAssets(
@ -431,7 +431,16 @@ public class AssetController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get());
TimePageData<Asset> nonFilteredResult = assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get();
List<Asset> filteredAssets = nonFilteredResult.getData().stream().filter(asset -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.ASSET, Operation.READ, asset.getId(), asset);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
return checkNotNull(new TimePageData<>(filteredAssets, nonFilteredResult.getNextPageLink(), nonFilteredResult.hasNext()));
} catch (Exception e) {
throw handleException(e);
}

View File

@ -50,6 +50,7 @@ import org.thingsboard.server.service.security.permission.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@TbCoreComponent
@ -554,7 +555,7 @@ public class DashboardController extends BaseController {
}
}
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<DashboardInfo> getEdgeDashboards(
@ -570,7 +571,16 @@ public class DashboardController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(dashboardService.findDashboardsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get());
TimePageData<DashboardInfo> nonFilteredResult = dashboardService.findDashboardsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get();
List<DashboardInfo> filteredDashboards = nonFilteredResult.getData().stream().filter(dashboard -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.DASHBOARD, Operation.READ, dashboard.getId(), dashboard);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
return checkNotNull(new TimePageData<>(filteredDashboards, nonFilteredResult.getNextPageLink(), nonFilteredResult.hasNext()));
} catch (Exception e) {
throw handleException(e);
}

View File

@ -631,7 +631,7 @@ public class DeviceController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/devices", params = {"limit"}, method = RequestMethod.GET)
@ResponseBody
public TimePageData<Device> getEdgeDevices(
@ -647,7 +647,16 @@ public class DeviceController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get());
TimePageData<Device> nonFilteredResult = deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get();
List<Device> filteredDevices = nonFilteredResult.getData().stream().filter(device -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, Operation.READ, device.getId(), device);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
return checkNotNull(new TimePageData<>(filteredDevices, nonFilteredResult.getNextPageLink(), nonFilteredResult.hasNext()));
} catch (Exception e) {
throw handleException(e);
}

View File

@ -449,7 +449,7 @@ public class EntityViewController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/entityViews", params = {"limit"}, method = RequestMethod.GET)
@ResponseBody
public TimePageData<EntityView> getEdgeEntityViews(
@ -465,7 +465,16 @@ public class EntityViewController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get());
TimePageData<EntityView> nonFilteredResult = entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink).get();
List<EntityView> filteredEntityViews = nonFilteredResult.getData().stream().filter(entityView -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.ENTITY_VIEW, Operation.READ, entityView.getId(), entityView);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
return checkNotNull(new TimePageData<>(filteredEntityViews, nonFilteredResult.getNextPageLink(), nonFilteredResult.hasNext()));
} catch (Exception e) {
throw handleException(e);
}

View File

@ -142,7 +142,11 @@ export function AssetController($rootScope, userService, assetService, customerS
var user = userService.getCurrentUser();
if (user.authority === 'CUSTOMER_USER') {
if (vm.assetsScope === 'edge') {
vm.assetsScope = 'edge_customer_user';
} else {
vm.assetsScope = 'customer_user';
}
customerId = user.customerId;
}
if (customerId) {
@ -323,10 +327,11 @@ export function AssetController($rootScope, userService, assetService, customerS
}
vm.assetGridConfig.addItemActions = [];
} else if (vm.assetsScope === 'edge') {
} else if (vm.assetsScope === 'edge' || vm.assetsScope === 'edge_customer_user') {
fetchAssetsFunction = function (pageLink) {
return assetService.getEdgeAssets(edgeId, pageLink, null);
};
if (vm.assetsScope === 'edge') {
deleteAssetFunction = function (assetId) {
return assetService.unassignAssetFromEdge(edgeId, assetId);
};
@ -339,8 +344,12 @@ export function AssetController($rootScope, userService, assetService, customerS
onAction: function ($event, item) {
unassignFromEdge($event, item, false);
},
name: function() { return $translate.instant('action.unassign') },
details: function() { return $translate.instant('edge.unassign-from-edge') },
name: function () {
return $translate.instant('action.unassign')
},
details: function () {
return $translate.instant('edge.unassign-from-edge')
},
icon: "assignment_return"
}
);
@ -350,7 +359,9 @@ export function AssetController($rootScope, userService, assetService, customerS
onAction: function ($event, items) {
unassignAssetsFromEdge($event, items);
},
name: function() { return $translate.instant('asset.unassign-assets') },
name: function () {
return $translate.instant('asset.unassign-assets')
},
details: function (selectedCount) {
return $translate.instant('asset.unassign-assets-from-edge-action-title', {count: selectedCount}, "messageformat");
},
@ -362,12 +373,18 @@ export function AssetController($rootScope, userService, assetService, customerS
onAction: function ($event) {
addAssetsToEdge($event);
},
name: function() { return $translate.instant('asset.assign-assets') },
details: function() { return $translate.instant('asset.assign-new-asset') },
name: function () {
return $translate.instant('asset.assign-assets')
},
details: function () {
return $translate.instant('asset.assign-new-asset')
},
icon: "add"
};
} else if (vm.assetsScope === 'edge_customer_user') {
vm.assetGridConfig.addItemAction = {};
}
vm.assetGridConfig.addItemActions = [];
}
vm.assetGridConfig.refreshParamsFunc = refreshAssetsParamsFunction;

View File

@ -141,7 +141,11 @@ export function DashboardsController(userService, dashboardService, customerServ
var user = userService.getCurrentUser();
if (user.authority === 'CUSTOMER_USER') {
if (vm.dashboardsScope === 'edge') {
vm.dashboardsScope = 'edge_customer_user';
} else {
vm.dashboardsScope = 'customer_user';
}
customerId = user.customerId;
}
@ -381,10 +385,12 @@ export function DashboardsController(userService, dashboardService, customerServ
} else if (vm.dashboardsScope === 'customer_user') {
vm.dashboardGridConfig.addItemAction = {};
}
} else if (vm.dashboardsScope === 'edge') {
} else if (vm.dashboardsScope === 'edge' || vm.dashboardsScope === 'edge_customer_user') {
fetchDashboardsFunction = function (pageLink) {
return dashboardService.getEdgeDashboards(edgeId, pageLink, null);
};
if (vm.dashboardsScope === 'edge') {
deleteDashboardFunction = function (dashboardId) {
return dashboardService.unassignDashboardFromEdge(edgeId, dashboardId);
};
@ -397,8 +403,12 @@ export function DashboardsController(userService, dashboardService, customerServ
onAction: function ($event, item) {
exportDashboard($event, item);
},
name: function() { $translate.instant('action.export') },
details: function() { return $translate.instant('dashboard.export') },
name: function () {
$translate.instant('action.export')
},
details: function () {
return $translate.instant('dashboard.export')
},
icon: "file_download"
}
);
@ -408,8 +418,12 @@ export function DashboardsController(userService, dashboardService, customerServ
onAction: function ($event, item) {
unassignFromEdge($event, item, edgeId);
},
name: function() { return $translate.instant('action.unassign') },
details: function() { return $translate.instant('edge.unassign-from-edge') },
name: function () {
return $translate.instant('action.unassign')
},
details: function () {
return $translate.instant('edge.unassign-from-edge')
},
icon: "assignment_return"
}
);
@ -419,7 +433,9 @@ export function DashboardsController(userService, dashboardService, customerServ
onAction: function ($event, items) {
unassignDashboardsFromEdge($event, items, edgeId);
},
name: function() { return $translate.instant('dashboard.unassign-dashboards') },
name: function () {
return $translate.instant('dashboard.unassign-dashboards')
},
details: function (selectedCount) {
return $translate.instant('dashboard.unassign-dashboards-from-edge-action-title', {count: selectedCount}, "messageformat");
},
@ -431,10 +447,18 @@ export function DashboardsController(userService, dashboardService, customerServ
onAction: function ($event) {
addDashboardsToEdge($event);
},
name: function() { return $translate.instant('dashboard.assign-dashboards') },
details: function() { return $translate.instant('dashboard.assign-new-dashboard') },
name: function () {
return $translate.instant('dashboard.assign-dashboards')
},
details: function () {
return $translate.instant('dashboard.assign-new-dashboard')
},
icon: "add"
};
} else if (vm.dashboardsScope === 'edge_customer_user') {
vm.dashboardGridConfig.addItemAction = {};
vm.dashboardGridConfig.addItemActions = [];
}
}
vm.dashboardGridConfig.refreshParamsFunc = refreshDashboardsParamsFunction;

View File

@ -143,7 +143,11 @@ export function DeviceController($rootScope, userService, deviceService, custome
var user = userService.getCurrentUser();
if (user.authority === 'CUSTOMER_USER') {
if (vm.devicesScope === 'edge') {
vm.devicesScope = 'edge_customer_user';
} else {
vm.devicesScope = 'customer_user';
}
customerId = user.customerId;
}
if (customerId) {
@ -356,10 +360,12 @@ export function DeviceController($rootScope, userService, deviceService, custome
}
vm.deviceGridConfig.addItemActions = [];
} else if (vm.devicesScope === 'edge') {
} else if (vm.devicesScope === 'edge' || vm.devicesScope === 'edge_customer_user') {
fetchDevicesFunction = function (pageLink) {
return deviceService.getEdgeDevices(edgeId, pageLink, null);
};
if (vm.devicesScope === 'edge') {
deleteDeviceFunction = function (deviceId) {
return deviceService.unassignDeviceFromEdge(edgeId, deviceId);
};
@ -399,6 +405,19 @@ export function DeviceController($rootScope, userService, deviceService, custome
details: function() { return $translate.instant('device.assign-new-device') },
icon: "add"
};
} else if (vm.devicesScope === 'edge_customer_user') {
deviceActionsList.push(
{
onAction: function ($event, item) {
manageCredentials($event, item);
},
name: function() { return $translate.instant('device.credentials') },
details: function() { return $translate.instant('device.view-credentials') },
icon: "security"
}
);
vm.deviceGridConfig.addItemAction = {};
}
vm.deviceGridConfig.addItemActions = [];
}

View File

@ -31,16 +31,16 @@
</div>
<div layout="row">
<md-button ng-click="onManageEdgeAssets({event: $event})"
ng-show="!isEdit && edgeScope === 'tenant'"
ng-show="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')"
class="md-raised md-primary">{{ 'edge.assets' | translate }}</md-button>
<md-button ng-click="onManageEdgeDevices({event: $event})"
ng-show="!isEdit && edgeScope === 'tenant'"
ng-show="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')"
class="md-raised md-primary">{{ 'edge.devices' | translate }}</md-button>
<md-button ng-click="onManageEdgeEntityViews({event: $event})"
ng-show="!isEdit && edgeScope === 'tenant'"
ng-show="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')"
class="md-raised md-primary">{{ 'edge.entity-views' | translate }}</md-button>
<md-button ng-click="onManageEdgeDashboards({event: $event})"
ng-show="!isEdit && edgeScope === 'tenant'"
ng-show="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')"
class="md-raised md-primary">{{ 'edge.dashboards' | translate }}</md-button>
<md-button ng-click="onManageEdgeRuleChains({event: $event})"
ng-show="!isEdit && edgeScope === 'tenant'"

View File

@ -399,9 +399,59 @@ export function EdgeController($rootScope, userService, edgeService, customerSer
} else if (vm.edgesScope === 'customer_user') {
vm.edgeGridConfig.addItemAction = {};
edgeActionsList.push(
{
onAction: function ($event, item) {
openEdgeAssets($event, item);
},
name: function() { return $translate.instant('asset.assets') },
details: function() {
return $translate.instant('edge.manage-edge-assets');
},
icon: "domain"
}
);
edgeActionsList.push(
{
onAction: function ($event, item) {
openEdgeDevices($event, item);
},
name: function() { return $translate.instant('device.devices') },
details: function() {
return $translate.instant('edge.manage-edge-devices');
},
icon: "devices_other"
}
);
edgeActionsList.push(
{
onAction: function ($event, item) {
openEdgeEntityViews($event, item);
},
name: function() { return $translate.instant('entity-view.entity-views') },
details: function() {
return $translate.instant('edge.manage-edge-entity-views');
},
icon: "view_quilt"
}
);
edgeActionsList.push(
{
onAction: function ($event, item) {
openEdgeDashboards($event, item);
},
name: function() { return $translate.instant('dashboard.dashboards') },
details: function() {
return $translate.instant('edge.manage-edge-dashboards');
},
icon: "dashboard"
}
);
}
vm.edgeGridConfig.addItemActions = [];
}
vm.edgeGridConfig.refreshParamsFunc = refreshEdgesParamsFunction;

View File

@ -55,7 +55,7 @@ export default function EdgeRoutes($stateProvider, types) {
url: '/:edgeId/entityViews',
params: {'topIndex': 0},
module: 'private',
auth: ['TENANT_ADMIN'],
auth: ['TENANT_ADMIN', 'CUSTOMER_USER'],
views: {
"content@home": {
templateUrl: entityViewsTemplate,
@ -77,7 +77,7 @@ export default function EdgeRoutes($stateProvider, types) {
url: '/:edgeId/devices',
params: {'topIndex': 0},
module: 'private',
auth: ['TENANT_ADMIN'],
auth: ['TENANT_ADMIN', 'CUSTOMER_USER'],
views: {
"content@home": {
templateUrl: devicesTemplate,
@ -99,7 +99,7 @@ export default function EdgeRoutes($stateProvider, types) {
url: '/:edgeId/assets',
params: {'topIndex': 0},
module: 'private',
auth: ['TENANT_ADMIN'],
auth: ['TENANT_ADMIN', 'CUSTOMER_USER'],
views: {
"content@home": {
templateUrl: assetsTemplate,
@ -121,7 +121,7 @@ export default function EdgeRoutes($stateProvider, types) {
url: '/:edgeId/dashboards',
params: {'topIndex': 0},
module: 'private',
auth: ['TENANT_ADMIN'],
auth: ['TENANT_ADMIN', 'CUSTOMER_USER'],
views: {
"content@home": {
templateUrl: dashboardsTemplate,

View File

@ -118,7 +118,11 @@ export function EntityViewController($rootScope, userService, entityViewService,
var user = userService.getCurrentUser();
if (user.authority === 'CUSTOMER_USER') {
if (vm.entityViewsScope === 'edge') {
vm.entityViewsScope = 'edge_customer_user';
} else {
vm.entityViewsScope = 'customer_user';
}
customerId = user.customerId;
}
if (customerId) {
@ -284,10 +288,12 @@ export function EntityViewController($rootScope, userService, entityViewService,
} else if (vm.entityViewsScope === 'customer_user') {
vm.entityViewGridConfig.addItemAction = {};
}
} else if (vm.entityViewsScope === 'edge') {
} else if (vm.entityViewsScope === 'edge' || vm.entityViewsScope === 'edge_customer_user') {
fetchEntityViewsFunction = function (pageLink) {
return entityViewService.getEdgeEntityViews(edgeId, pageLink, null);
};
if (vm.entityViewsScope === 'edge') {
deleteEntityViewFunction = function (entityViewId) {
return entityViewService.unassignEntityViewFromEdge(edgeId, entityViewId);
};
@ -299,8 +305,12 @@ export function EntityViewController($rootScope, userService, entityViewService,
onAction: function ($event, item) {
unassignFromEdge($event, item, false);
},
name: function() { return $translate.instant('action.unassign') },
details: function() { return $translate.instant('edge.unassign-from-edge') },
name: function () {
return $translate.instant('action.unassign')
},
details: function () {
return $translate.instant('edge.unassign-from-edge')
},
icon: "assignment_return"
}
);
@ -310,7 +320,9 @@ export function EntityViewController($rootScope, userService, entityViewService,
onAction: function ($event, items) {
unassignEntityViewsFromEdge($event, items);
},
name: function() { return $translate.instant('entity-view.unassign-entity-views') },
name: function () {
return $translate.instant('entity-view.unassign-entity-views')
},
details: function (selectedCount) {
return $translate.instant('entity-view.unassign-entity-views-from-edge-action-title', {count: selectedCount}, "messageformat");
},
@ -322,10 +334,17 @@ export function EntityViewController($rootScope, userService, entityViewService,
onAction: function ($event) {
addEntityViewsToEdge($event);
},
name: function() { return $translate.instant('entity-view.assign-entity-views') },
details: function() { return $translate.instant('entity-view.assign-new-entity-view') },
name: function () {
return $translate.instant('entity-view.assign-entity-views')
},
details: function () {
return $translate.instant('entity-view.assign-new-entity-view')
},
icon: "add"
};
} else if (vm.entityViewsScope === 'edge_customer_user') {
vm.entityViewGridConfig.addItemAction = {};
}
vm.entityViewGridConfig.addItemActions = [];
}