diff --git a/src/app/admin/permission/permission-detail/permission-detail.component.html b/src/app/admin/permission/permission-detail/permission-detail.component.html
index bd6774bed..5bd2decaa 100644
--- a/src/app/admin/permission/permission-detail/permission-detail.component.html
+++ b/src/app/admin/permission/permission-detail/permission-detail.component.html
@@ -33,8 +33,7 @@
|
-
+
diff --git a/src/app/applications/applications-list/applications-table/applications-table.component.ts b/src/app/applications/applications-list/applications-table/applications-table.component.ts
index 697c512a1..5b60ddf27 100644
--- a/src/app/applications/applications-list/applications-table/applications-table.component.ts
+++ b/src/app/applications/applications-list/applications-table/applications-table.component.ts
@@ -38,7 +38,6 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
resultsLength = 0;
isLoadingResults = true;
public errorMessage: string;
- public canEdit = false;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@@ -47,12 +46,10 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
public translate: TranslateService,
private applicationService: ApplicationService,
private router: Router,
- private meService: MeService,
private deleteDialogService: DeleteDialogService
) {}
ngOnInit() {
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
}
ngAfterViewInit() {
diff --git a/src/app/applications/bulk-import/bulk-import.component.html b/src/app/applications/bulk-import/bulk-import.component.html
index 466dcaf36..129225a5e 100644
--- a/src/app/applications/bulk-import/bulk-import.component.html
+++ b/src/app/applications/bulk-import/bulk-import.component.html
@@ -1,4 +1,4 @@
-
+
diff --git a/src/app/applications/bulk-import/bulk-import.component.ts b/src/app/applications/bulk-import/bulk-import.component.ts
index c6c1dc0bb..c39bf3f54 100644
--- a/src/app/applications/bulk-import/bulk-import.component.ts
+++ b/src/app/applications/bulk-import/bulk-import.component.ts
@@ -59,7 +59,6 @@ export class BulkImportComponent implements OnInit {
private bulkMapper = new BulkMapping();
public backButtonTitle: string;
private applicationId;
- canEdit: boolean;
constructor(
private papa: Papa,
@@ -80,9 +79,6 @@ export class BulkImportComponent implements OnInit {
this.titleService.setTitle(translations['TITLE.BULKIMPORT']);
});
this.applicationId = +this.route.snapshot.paramMap.get('id');
- this.canEdit = this.meService.hasAccessToTargetOrganization(
- OrganizationAccessScope.ApplicationWrite
- );
}
download({ name, url }: { name: string; url: string }) {
diff --git a/src/app/applications/datatarget/datatarget-table/datatarget-table.component.ts b/src/app/applications/datatarget/datatarget-table/datatarget-table.component.ts
index 293f36e9d..91e083357 100644
--- a/src/app/applications/datatarget/datatarget-table/datatarget-table.component.ts
+++ b/src/app/applications/datatarget/datatarget-table/datatarget-table.component.ts
@@ -51,7 +51,7 @@ export class DatatargetTableComponent implements OnInit, AfterViewInit, OnDestro
ngOnInit(): void {
this.applicationId = +Number(this.route.parent.snapshot.paramMap.get('id'));
this.getDatatarget();
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, this.applicationId);
}
ngAfterViewInit() {
diff --git a/src/app/applications/datatarget/fiware/fiware-detail/fiware-detail.component.ts b/src/app/applications/datatarget/fiware/fiware-detail/fiware-detail.component.ts
index 24b64bb80..8d70b1691 100644
--- a/src/app/applications/datatarget/fiware/fiware-detail/fiware-detail.component.ts
+++ b/src/app/applications/datatarget/fiware/fiware-detail/fiware-detail.component.ts
@@ -43,6 +43,7 @@ export class FiwareDetailComponent implements DatatargetDetail, OnInit, OnDestr
ngOnInit(): void {
const id: number = +this.route.snapshot.paramMap.get('datatargetId');
+ const appId: number = +this.route.snapshot.paramMap.get('id');
if (id) {
this.getDatatarget(id);
@@ -58,7 +59,7 @@ export class FiwareDetailComponent implements DatatargetDetail, OnInit, OnDestr
this.backButton.label = translations['NAV.MY-DATATARGET'];
this.dropdownButton.label = translations['DATATARGET.SHOW-OPTIONS'];
});
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, appId);
}
getDatatarget(id: number) {
diff --git a/src/app/applications/datatarget/httppush/httppush-detail/httppush-detail.component.ts b/src/app/applications/datatarget/httppush/httppush-detail/httppush-detail.component.ts
index 1cad19ae3..a8490bd54 100644
--- a/src/app/applications/datatarget/httppush/httppush-detail/httppush-detail.component.ts
+++ b/src/app/applications/datatarget/httppush/httppush-detail/httppush-detail.component.ts
@@ -43,6 +43,7 @@ export class HttppushDetailComponent implements DatatargetDetail, OnInit, OnDes
ngOnInit(): void {
const id: number = +this.route.snapshot.paramMap.get('datatargetId');
+ const appId: number = +this.route.snapshot.paramMap.get('id');
this.applicationName = this.route.snapshot.paramMap.get('name');
if (id) {
this.getDatatarget(id);
@@ -58,7 +59,7 @@ export class HttppushDetailComponent implements DatatargetDetail, OnInit, OnDes
this.backButton.label = translations['NAV.MY-DATATARGET'];
this.dropdownButton.label = translations['DATATARGET.SHOW-OPTIONS'];
});
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, appId);
}
getDatatarget(id: number) {
diff --git a/src/app/applications/datatarget/httppush/httppush-edit/httppush-edit.component.ts b/src/app/applications/datatarget/httppush/httppush-edit/httppush-edit.component.ts
index f48f868de..c68dc4304 100644
--- a/src/app/applications/datatarget/httppush/httppush-edit/httppush-edit.component.ts
+++ b/src/app/applications/datatarget/httppush/httppush-edit/httppush-edit.component.ts
@@ -114,7 +114,7 @@ export class HttppushEditComponent
}
this.getPayloadDecoders();
this.setDataSetExcists();
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, this.applicationId);
}
addRow() {
diff --git a/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.html b/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.html
index 6161fee8c..dd7f70585 100644
--- a/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.html
+++ b/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.html
@@ -1,6 +1,7 @@
+ [dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteDatatarget()" [canEdit]="canEdit">
+
diff --git a/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.ts b/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.ts
index a97552241..b1de51fb7 100644
--- a/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.ts
+++ b/src/app/applications/datatarget/mqtt-detail/mqtt-detail.component.ts
@@ -12,6 +12,8 @@ import { DropdownButton } from '@shared/models/dropdown-button.model';
import { Subscription } from 'rxjs';
import { Datatarget } from '../datatarget.model';
import { DatatargetService } from '../datatarget.service';
+import { MeService } from '@shared/services/me.service';
+import { OrganizationAccessScope } from '@shared/enums/access-scopes';
@Component({
selector: 'app-mqtt-detail',
@@ -28,6 +30,7 @@ export class MqttDetailComponent
private deleteDialogSubscription: Subscription;
public dropdownButton: DropdownButton;
arrowsAltH = faArrowsAltH;
+ canEdit: boolean;
constructor(
private route: ActivatedRoute,
@@ -35,11 +38,13 @@ export class MqttDetailComponent
private location: Location,
private datatargetRelationService: PayloadDeviceDatatargetService,
private datatargetService: DatatargetService,
- public translate: TranslateService
+ public translate: TranslateService,
+ private meService: MeService,
) {}
ngOnInit(): void {
const id: number = +this.route.snapshot.paramMap.get('datatargetId');
+ const appId: number = +this.route.snapshot.paramMap.get('id');
if (id) {
this.getDatatarget(id);
@@ -56,6 +61,7 @@ export class MqttDetailComponent
this.backButton.label = translations['NAV.MY-DATATARGET'];
this.dropdownButton.label = translations['DATATARGET.SHOW-OPTIONS'];
});
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, appId);
}
getDatatarget(id: number) {
diff --git a/src/app/applications/iot-devices/iot-device-detail/iot-device-detail.component.ts b/src/app/applications/iot-devices/iot-device-detail/iot-device-detail.component.ts
index c5bc0e05e..fc2b418da 100644
--- a/src/app/applications/iot-devices/iot-device-detail/iot-device-detail.component.ts
+++ b/src/app/applications/iot-devices/iot-device-detail/iot-device-detail.component.ts
@@ -97,8 +97,9 @@ export class IoTDeviceDetailComponent implements OnInit, OnDestroy {
) { }
ngOnInit(): void {
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
this.deviceId = +this.route.snapshot.paramMap.get('deviceId');
+ const appId: number = +this.route.snapshot.paramMap.get('id');
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, appId);
if (this.deviceId) {
this.bindIoTDeviceAndApplication(this.deviceId);
diff --git a/src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts b/src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts
index 6b7d316cc..c1458f336 100644
--- a/src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts
+++ b/src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts
@@ -93,7 +93,7 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
this.getServiceProfiles();
this.getDeviceProfiles();
this.getDeviceModels();
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, this.iotDevice.applicationId);
}
public compare(o1: any, o2: any): boolean {
diff --git a/src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts b/src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts
index 5efed1033..8fced9beb 100644
--- a/src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts
+++ b/src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts
@@ -25,6 +25,7 @@ import { catchError, map, startWith, switchMap } from 'rxjs/operators';
import { RestService } from 'src/app/shared/services/rest.service';
import { IoTDeviceService } from '../iot-device.service';
import { DefaultPageSizeOptions } from '@shared/constants/page.constants';
+import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-iot-devices-table',
@@ -64,14 +65,16 @@ export class IotDevicesTableComponent implements AfterViewInit, OnInit {
public translate: TranslateService,
public iotDeviceService: IoTDeviceService,
private meService: MeService,
- private dialog: MatDialog
+ private dialog: MatDialog,
+ private route: ActivatedRoute,
) {
translate.use('da');
moment.locale('da');
}
ngOnInit() {
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ const applicationId = +this.route.snapshot.paramMap.get('id');
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, applicationId);
}
ngAfterViewInit() {
diff --git a/src/app/applications/multicast/multicast-table/multicast-table.component.ts b/src/app/applications/multicast/multicast-table/multicast-table.component.ts
index a2cf6a480..2a8e91ea6 100644
--- a/src/app/applications/multicast/multicast-table/multicast-table.component.ts
+++ b/src/app/applications/multicast/multicast-table/multicast-table.component.ts
@@ -57,7 +57,9 @@ export class MulticastTableComponent
ngOnInit(): void {
this.applicationId = +Number(this.route.parent.snapshot.paramMap.get('id'));
this.canEdit = this.meService.hasAccessToTargetOrganization(
- OrganizationAccessScope.ApplicationWrite
+ OrganizationAccessScope.ApplicationWrite,
+ undefined,
+ this.applicationId
);
}
diff --git a/src/app/device-model/device-model-detail/device-model-detail.component.ts b/src/app/device-model/device-model-detail/device-model-detail.component.ts
index d3cdebc30..a98105967 100644
--- a/src/app/device-model/device-model-detail/device-model-detail.component.ts
+++ b/src/app/device-model/device-model-detail/device-model-detail.component.ts
@@ -37,6 +37,8 @@ export class DeviceModelDetailComponent implements OnInit, OnDestroy {
ngOnInit(): void {
const deviceModelId = +this.route.snapshot.paramMap.get('deviceId');
+ const appId: number = +this.route.snapshot.paramMap.get('id');
+
if (deviceModelId) {
this.getDeviceModel(deviceModelId);
this.dropdownButton = {
@@ -53,7 +55,7 @@ export class DeviceModelDetailComponent implements OnInit, OnDestroy {
this.title = translations['DEVICE-MODEL.DETAIL-TITLE'];
this.errorTitle = translations['DEVICE-MODEL.DELETE-FAILED'];
});
- this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
+ this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, appId);
}
private getDeviceModel(id: number) {
diff --git a/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.html b/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.html
index c9b29cc68..87a931172 100644
--- a/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.html
+++ b/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.html
@@ -1,7 +1,7 @@
+ [canEdit]="payloadDecoder?.canEdit">
diff --git a/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.ts b/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.ts
index 2bd8a0d67..a93207262 100644
--- a/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.ts
+++ b/src/app/payload-decoder/payload-decoder-detail/payload-decoder-detail.component.ts
@@ -57,7 +57,7 @@ export class PayloadDecoderDetailComponent implements OnInit, OnDestroy {
});
}
- canEdit() {
+ private canEdit() {
this.payloadDecoder.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, this.payloadDecoder?.organizationId);
}
diff --git a/src/app/shared/pipes/permission/can-edit-application.pipe.ts b/src/app/shared/pipes/permission/can-edit-application.pipe.ts
new file mode 100644
index 000000000..545892866
--- /dev/null
+++ b/src/app/shared/pipes/permission/can-edit-application.pipe.ts
@@ -0,0 +1,18 @@
+import { Pipe, PipeTransform } from '@angular/core';
+import { OrganizationAccessScope } from '@shared/enums/access-scopes';
+import { MeService } from '@shared/services/me.service';
+
+@Pipe({
+ name: 'canEditApplication',
+})
+export class CanEditApplicationPipe implements PipeTransform {
+ constructor(private meService: MeService) {}
+
+ transform(id: number | undefined): boolean {
+ return this.meService.hasAccessToTargetOrganization(
+ OrganizationAccessScope.ApplicationWrite,
+ undefined,
+ id
+ );
+ }
+}
diff --git a/src/app/shared/pipes/is-global-admin.pipe.ts b/src/app/shared/pipes/permission/is-global-admin.pipe.ts
similarity index 100%
rename from src/app/shared/pipes/is-global-admin.pipe.ts
rename to src/app/shared/pipes/permission/is-global-admin.pipe.ts
diff --git a/src/app/shared/pipes/translate-permissions.pipe.ts b/src/app/shared/pipes/permission/translate-permissions.pipe.ts
similarity index 100%
rename from src/app/shared/pipes/translate-permissions.pipe.ts
rename to src/app/shared/pipes/permission/translate-permissions.pipe.ts
diff --git a/src/app/shared/pipes/pipes.module.ts b/src/app/shared/pipes/pipes.module.ts
index f81deb1b3..d0ce9cb0c 100644
--- a/src/app/shared/pipes/pipes.module.ts
+++ b/src/app/shared/pipes/pipes.module.ts
@@ -2,14 +2,15 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { YesNoPipe } from './yesNo.pipe';
import { ActiveDeactivePipe } from './activeDeactive.pipe';
-import { IsGlobalAdminPipe } from './is-global-admin.pipe';
+import { IsGlobalAdminPipe } from './permission/is-global-admin.pipe';
import { CreatedUpdatedByPipe } from './created-updated-by.pipe';
import { CustomDatePipe, CustomTableDatePipe, DateOnlyPipe } from './custom-date.pipe';
import { FilterDevicesPipe } from './filter-devices.pipe';
-import { TranslatePermissionsPipe } from './translate-permissions.pipe';
+import { TranslatePermissionsPipe } from './permission/translate-permissions.pipe';
import { SortByPipe } from './sort-by.pipe';
import { GatewayStatusTooltipPipe } from './gateway/gateway-status-tooltip.pipe';
import { GatewayStatusClassPipe } from './gateway/gateway-status-class.pipe';
+import { CanEditApplicationPipe } from './permission/can-edit-application.pipe';
@NgModule({
declarations: [
@@ -24,7 +25,8 @@ import { GatewayStatusClassPipe } from './gateway/gateway-status-class.pipe';
TranslatePermissionsPipe,
SortByPipe,
GatewayStatusTooltipPipe,
- GatewayStatusClassPipe
+ GatewayStatusClassPipe,
+ CanEditApplicationPipe,
],
imports: [CommonModule],
exports: [
@@ -39,7 +41,8 @@ import { GatewayStatusClassPipe } from './gateway/gateway-status-class.pipe';
TranslatePermissionsPipe,
SortByPipe,
GatewayStatusTooltipPipe,
- GatewayStatusClassPipe
+ GatewayStatusClassPipe,
+ CanEditApplicationPipe,
],
providers: [
DateOnlyPipe
diff --git a/src/app/shared/services/me.service.ts b/src/app/shared/services/me.service.ts
index aa09d93d7..f1d2d32e8 100644
--- a/src/app/shared/services/me.service.ts
+++ b/src/app/shared/services/me.service.ts
@@ -1,12 +1,12 @@
import { Injectable } from '@angular/core';
import {
- PermissionType,
PermissionResponse,
+ PermissionType,
PermissionTypes,
} from '@app/admin/permission/permission.model';
import { UserResponse } from '@app/admin/users/user.model';
-import { SharedVariableService } from '@shared/shared-variable/shared-variable.service';
import { OrganizationAccessScope } from '@shared/enums/access-scopes';
+import { SharedVariableService } from '@shared/shared-variable/shared-variable.service';
@Injectable({
providedIn: 'root',
@@ -18,7 +18,8 @@ export class MeService {
hasAccessToTargetOrganization(
scope: OrganizationAccessScope,
- id: number = this.sharedVariableService.getSelectedOrganisationId()
+ organizationId: number = this.sharedVariableService.getSelectedOrganisationId(),
+ applicationId?: number
): boolean {
const { permissions } = this.sharedVariableService.getUserInfo().user;
@@ -30,11 +31,16 @@ export class MeService {
return true;
}
- let canWriteCallback: (p: PermissionResponse) => boolean;
+ let canWriteCallback: (
+ p: PermissionResponse,
+ appId: number | undefined
+ ) => boolean;
switch (scope) {
case OrganizationAccessScope.ApplicationWrite:
- canWriteCallback = this.canWriteApplicationInTargetOrganization.bind(this);
+ canWriteCallback = this.canWriteApplicationInTargetOrganization.bind(
+ this
+ );
break;
case OrganizationAccessScope.GatewayWrite:
canWriteCallback = this.canWriteGatewayInTargetOrganization.bind(this);
@@ -50,7 +56,8 @@ export class MeService {
return permissions.some(
(permission) =>
this.hasPermissions(permission, PermissionType.GlobalAdmin) ||
- (permission.organization.id === id && canWriteCallback(permission))
+ (permission.organization.id === organizationId &&
+ canWriteCallback(permission, applicationId))
);
}
@@ -76,11 +83,16 @@ export class MeService {
}
private canWriteApplicationInTargetOrganization(
- permission: PermissionResponse
+ permission: PermissionResponse,
+ targetAppId: number | undefined
): boolean {
- return this.hasPermissions(
- permission,
- PermissionType.OrganizationApplicationAdmin
+ return (
+ this.hasPermissions(
+ permission,
+ PermissionType.OrganizationApplicationAdmin
+ ) &&
+ (!targetAppId ||
+ permission.applicationIds?.some((appId) => appId === targetAppId))
);
}
|