Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify revised permission migration #98

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ <h3>
{{ 'PERMISSION.DETAIL.APPLICATIONS' | translate }}
</h3>

<app-applications-table *ngIf="!isApplicationAdmin()" [permissionId]="id" [organizationId]="permission.organization?.id"></app-applications-table>
<app-applications-table *ngIf="isApplicationAdmin()"></app-applications-table>
<app-applications-table [permissionId]="id" [organizationId]="permission.organization?.id"></app-applications-table>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,4 @@ export class PermissionDetailComponent implements OnInit, OnChanges {
onEditPermission() {
this.router.navigate(['edit-permission'], { relativeTo: this.route });
}

isApplicationAdmin () {
if (this.permission) {
if (this.permission.type.some(perm => perm.type === PermissionType.OrganizationApplicationAdmin)) {
return true;
}
}

return false;
}
}
1 change: 1 addition & 0 deletions src/app/admin/permission/permission.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface PermissionResponse {
users?: UserResponse[];
organization?: OrganisationResponse;
applications?: Application[];
applicationIds?: number[];
id: number;
createdAt: Date;
updatedAt: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
label: '',
editRouterLink: '../../edit-application/' + this.id,
isErasable: true,
};
};
}

this.translate
Expand All @@ -68,7 +68,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
translations['APPLICATION-TABLE-ROW.SHOW-OPTIONS'];
this.titleService.setTitle(translations['TITLE.APPLICATION']);
});
this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite);
this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, undefined, this.id);
}

onDeleteApplication() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ng-container matColumnDef="menu">
<th mat-header-cell *matHeaderCellDef class="col-1"></th>
<td mat-cell *matCellDef="let element">
<div class="dropdown" *ngIf="canEdit">
<div class="dropdown" *ngIf="element?.id | canEditApplication">
<a href="#" role="button" id="tableRowDropdown-{{element.id}}" class="applicationRow__edit dropdown-toggle"
data-toggle="dropdown" aria-expanded="false"
[attr.aria-label]="'APPLICATION-TABLE-ROW.SHOW-OPTIONS' | translate"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<app-top-bar [backButtonTitle]="'NAV.APPLICATION' | translate" [title]="'APPLICATION.BULK.TITLE' | translate" [canEdit]="canEdit">
<app-top-bar [backButtonTitle]="'NAV.APPLICATION' | translate" [title]="'APPLICATION.BULK.TITLE' | translate">
</app-top-bar>
<div class="row">
<div class="col-12">
Expand Down
4 changes: 0 additions & 4 deletions src/app/applications/bulk-import/bulk-import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class BulkImportComponent implements OnInit {
private bulkMapper = new BulkMapping();
public backButtonTitle: string;
private applicationId;
canEdit: boolean;

constructor(
private papa: Papa,
Expand All @@ -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 }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div *ngIf="datatarget">
<app-top-bar [data]="datatarget" [backButton]="backButton" [subPage]="true" [addDetailDowndown]="true"
[dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteDatatarget()"></app-top-bar>
[dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteDatatarget()" [canEdit]="canEdit">
</app-top-bar>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 d-flex align-items-stretch">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -28,18 +30,21 @@ export class MqttDetailComponent
private deleteDialogSubscription: Subscription;
public dropdownButton: DropdownButton;
arrowsAltH = faArrowsAltH;
canEdit: boolean;

constructor(
private route: ActivatedRoute,
private deleteDialogService: DeleteDialogService,
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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<app-top-bar *ngIf="payloadDecoder" [data]="payloadDecoder" [backButton]="backButton" [subPage]="true"
[addDetailDowndown]="true" [dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeletePayload()"
[canEdit]="canEdit">
[canEdit]="payloadDecoder?.canEdit">
</app-top-bar>
<div *ngIf="payloadDecoder">
<div class=" jumbotron">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PayloadDecoderDetailComponent implements OnInit, OnDestroy {
});
}

canEdit() {
private canEdit() {
this.payloadDecoder.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.ApplicationWrite, this.payloadDecoder?.organizationId);
}

Expand Down
18 changes: 18 additions & 0 deletions src/app/shared/pipes/permission/can-edit-application.pipe.ts
Original file line number Diff line number Diff line change
@@ -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
);
}
}
11 changes: 7 additions & 4 deletions src/app/shared/pipes/pipes.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -24,7 +25,8 @@ import { GatewayStatusClassPipe } from './gateway/gateway-status-class.pipe';
TranslatePermissionsPipe,
SortByPipe,
GatewayStatusTooltipPipe,
GatewayStatusClassPipe
GatewayStatusClassPipe,
CanEditApplicationPipe,
],
imports: [CommonModule],
exports: [
Expand All @@ -39,7 +41,8 @@ import { GatewayStatusClassPipe } from './gateway/gateway-status-class.pipe';
TranslatePermissionsPipe,
SortByPipe,
GatewayStatusTooltipPipe,
GatewayStatusClassPipe
GatewayStatusClassPipe,
CanEditApplicationPipe,
],
providers: [
DateOnlyPipe
Expand Down
Loading