Skip to content

Commit f7f9ba1

Browse files
committed
IOT-1144 removed create,edit and delete from user with read permissions, from application, iot-device, datatarget, device model and top bar
1 parent 2c4cede commit f7f9ba1

File tree

12 files changed

+46
-18
lines changed

12 files changed

+46
-18
lines changed

src/app/applications/application-detail/application-detail.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div *ngIf="application">
22
<app-top-bar [data]="application" [backButton]="backButton" [subPage]="true"
3-
[ctaRouterLink]="['datatarget-list', application.name]" [ctaLabel]="'APPLICATION.DATATARGET-SHOW' | translate"
3+
[dtRouterLink]="['datatarget-list', application.name]" [dtLabel]="'APPLICATION.DATATARGET-SHOW' | translate"
44
[addDetailDowndown]="true" [dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteApplication()">
55
</app-top-bar>
66
<div class="container-fluid">

src/app/applications/applications-list/applications-table/applications-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<ng-container matColumnDef="menu">
3636
<th mat-header-cell *matHeaderCellDef class="col-1"></th>
3737
<td mat-cell *matCellDef="let element">
38-
<div class="dropdown">
38+
<div class="dropdown" *ngIf="canEdit">
3939
<a href="#" role="button" id="tableRowDropdown-{{element.id}}" class="applicationRow__edit dropdown-toggle"
4040
data-toggle="dropdown" aria-expanded="false"
4141
[attr.aria-label]="'APPLICATION-TABLE-ROW.SHOW-OPTIONS' | translate"></a>

src/app/applications/applications-list/applications-table/applications-table.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Component, ViewChild, AfterViewInit, Input } from '@angular/core';
1+
import { Component, ViewChild, AfterViewInit, Input, OnInit } from '@angular/core';
22
import { MatPaginator } from '@angular/material/paginator';
33
import { MatSort } from '@angular/material/sort';
44
import { Router } from '@angular/router';
55
import { Application, ApplicationData } from '@applications/application.model';
66
import { ApplicationService } from '@applications/application.service';
77
import { environment } from '@environments/environment';
88
import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service';
9+
import { MeService } from '@shared/services/me.service';
910
import { merge, Observable, of as observableOf } from 'rxjs';
1011
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
1112

@@ -17,7 +18,7 @@ import { catchError, map, startWith, switchMap } from 'rxjs/operators';
1718
styleUrls: ['./applications-table.component.scss'],
1819
templateUrl: './applications-table.component.html',
1920
})
20-
export class ApplicationsTableComponent implements AfterViewInit {
21+
export class ApplicationsTableComponent implements AfterViewInit, OnInit {
2122
@Input() organizationId: number;
2223
@Input() permissionId: number;
2324
displayedColumns: string[] = ['name', 'devices', 'menu'];
@@ -27,16 +28,22 @@ export class ApplicationsTableComponent implements AfterViewInit {
2728
resultsLength = 0;
2829
isLoadingResults = true;
2930
public errorMessage: string;
31+
public canEdit = false;
3032

3133
@ViewChild(MatPaginator) paginator: MatPaginator;
3234
@ViewChild(MatSort) sort: MatSort;
3335

3436
constructor(
3537
private applicationService: ApplicationService,
3638
private router: Router,
39+
private meService: MeService,
3740
private deleteDialogService: DeleteDialogService
3841
) { }
3942

43+
ngOnInit() {
44+
this.canEdit = this.meService.canWriteInTargetOrganization()
45+
}
46+
4047
ngAfterViewInit() {
4148
// If the user changes the sort order, reset back to the first page.
4249
this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));

src/app/applications/datatarget/datatarget-table/datatarget-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<ng-container matColumnDef="menu">
2929
<th mat-header-cell *matHeaderCellDef class="col-1"></th>
3030
<td mat-cell *matCellDef="let element">
31-
<div class="dropdown">
31+
<div class="dropdown" *ngIf="canEdit">
3232
<a href="#" role="button" id="tableRowDropdown-{{element.id}}" class="applicationRow__edit dropdown-toggle"
3333
data-toggle="dropdown" aria-expanded="false"
3434
[attr.aria-label]="'DATATARGET-TABLE-ROW.SHOW-OPTIONS' | translate"></a>

src/app/applications/datatarget/datatarget-table/datatarget-table.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MatSort } from '@angular/material/sort';
1010
import { MatTableDataSource } from '@angular/material/table';
1111
import { environment } from '@environments/environment';
1212
import { tableSorter } from '@shared/helpers/table-sorting.helper';
13+
import { MeService } from '@shared/services/me.service';
1314

1415
@Component({
1516
selector: 'app-datatarget-table',
@@ -23,6 +24,7 @@ export class DatatargetTableComponent implements OnInit, AfterViewInit, OnDestro
2324
dataSource = new MatTableDataSource<Datatarget>();
2425
datatargets: Datatarget[];
2526
resultsLength = 0;
27+
public canEdit = false;
2628
@Input() isLoadingResults: boolean;
2729
public pageSize = environment.tablePageSize;
2830

@@ -38,6 +40,7 @@ export class DatatargetTableComponent implements OnInit, AfterViewInit, OnDestro
3840
private route: ActivatedRoute,
3941
private deleteDialogService: DeleteDialogService,
4042
private datatargetService: DatatargetService,
43+
private meService: MeService,
4144
public translate: TranslateService) {
4245
translate.use('da');
4346
}
@@ -46,6 +49,7 @@ export class DatatargetTableComponent implements OnInit, AfterViewInit, OnDestro
4649
this.applicationId = +Number(this.route.parent.parent.snapshot.paramMap.get('id'));
4750
console.log(this.applicationId);
4851
this.getDatatarget();
52+
this.canEdit = this.meService.canWriteInTargetOrganization()
4953
}
5054

5155
ngAfterViewInit() {

src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<ng-container matColumnDef="menu">
5757
<th mat-header-cell *matHeaderCellDef></th>
5858
<td mat-cell *matCellDef="let element">
59-
<div class="dropdown ">
59+
<div class="dropdown" *ngIf="canEdit">
6060
<a href="#" role="button" id="tableRowDropdown-{{element.id}}" class="applicationRow__edit dropdown-toggle"
6161
data-toggle="dropdown" aria-expanded="false"
6262
[attr.aria-label]="'APPLICATION-TABLE-ROW.SHOW-OPTIONS' | translate"></a>

src/app/applications/iot-devices/iot-devices-table/iot-devices-table.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ViewChild, AfterViewInit } from '@angular/core';
1+
import { Component, Input, ViewChild, AfterViewInit, OnInit } from '@angular/core';
22
import { merge, Observable, of as observableOf } from 'rxjs';
33
import { TranslateService } from '@ngx-translate/core';
44
import { RestService } from 'src/app/shared/services/rest.service';
@@ -17,16 +17,16 @@ import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dia
1717
import { ReceivedMessageMetadata } from '@shared/models/received-message-metadata.model';
1818
import { environment } from '@environments/environment';
1919
import { startWith, switchMap, map, catchError } from 'rxjs/operators';
20+
import { MeService } from '@shared/services/me.service';
2021

2122
@Component({
2223
selector: 'app-iot-devices-table',
2324
templateUrl: './iot-devices-table.component.html',
2425
styleUrls: ['./iot-devices-table.component.scss'],
2526
})
26-
export class IotDevicesTableComponent implements AfterViewInit {
27+
export class IotDevicesTableComponent implements AfterViewInit, OnInit {
2728
@Input() applicationId: number;
2829
data: IotDevice[] = [];
29-
3030
@ViewChild(MatPaginator) paginator: MatPaginator;
3131
@ViewChild(MatSort) sort: MatSort;
3232
public pageSize = environment.tablePageSize;
@@ -37,6 +37,7 @@ export class IotDevicesTableComponent implements AfterViewInit {
3737
'active',
3838
'menu',
3939
];
40+
public canEdit = false;
4041

4142
private readonly CHIRPSTACK_BATTERY_NOT_AVAILIBLE = 255;
4243

@@ -50,12 +51,17 @@ export class IotDevicesTableComponent implements AfterViewInit {
5051
private deleteDialogService: DeleteDialogService,
5152
public translate: TranslateService,
5253
public iotDeviceService: IoTDeviceService,
54+
private meService: MeService,
5355
private dialog: MatDialog
5456
) {
5557
translate.use('da');
5658
moment.locale('da');
5759
}
5860

61+
ngOnInit() {
62+
this.canEdit = this.meService.canWriteInTargetOrganization()
63+
}
64+
5965
ngAfterViewInit() {
6066
// If the user changes the sort order, reset back to the first page.
6167
this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));

src/app/device-model/device-model-table/device-model-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<ng-container matColumnDef="menu">
2929
<th mat-header-cell *matHeaderCellDef></th>
3030
<td mat-cell *matCellDef="let element">
31-
<div class="dropdown">
31+
<div class="dropdown" *ngIf="canEdit">
3232
<a href="#" role="button" id="tableRowDropdown-{{ element.id }}"
3333
class="applicationRow__edit dropdown-toggle" data-toggle="dropdown" aria-expanded="false"
3434
[attr.aria-label]="'DEVICE-MODEL.SHOW-OPTIONS' | translate"></a>

src/app/device-model/device-model-table/device-model-table.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { MatTableDataSource } from '@angular/material/table';
1212
import { environment } from '@environments/environment';
1313
import { TranslateService } from '@ngx-translate/core';
1414
import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service';
15+
import { MeService } from '@shared/services/me.service';
1516
import { SharedVariableService } from '@shared/shared-variable/shared-variable.service';
1617
import { merge, Observable, of as observableOf, Subscription } from 'rxjs';
1718
import { startWith, switchMap, map, catchError } from 'rxjs/operators';
@@ -26,26 +27,25 @@ import { DeviceModel, DeviceModelResponse } from '../device.model';
2627
export class DeviceModelTableComponent implements OnInit, AfterViewInit {
2728
@ViewChild(MatPaginator) paginator: MatPaginator;
2829
@ViewChild(MatSort) sort: MatSort;
29-
3030
public data: DeviceModel[];
31-
3231
public displayedColumns: string[] = ['name', 'id', 'menu'];
3332
public pageSize = environment.tablePageSize;
3433
public isLoadingResults = false;
3534
public resultsLength = 0;
36-
public hasWritePermission = false;
3735
deleteDialogSubscription: Subscription;
3836
errorTitle: string;
37+
public canEdit = false;
3938

4039
constructor(
4140
private sharedVariableService: SharedVariableService,
4241
private deviceModelService: DeviceModelService,
4342
private deleteDialogservice: DeleteDialogService,
44-
private translateService: TranslateService
43+
private translateService: TranslateService,
44+
private meService: MeService
4545
) {}
4646

4747
ngOnInit(): void {
48-
this.hasWritePermission = this.sharedVariableService.getHasWritePermission();
48+
this.canEdit = this.meService.canWriteInTargetOrganization()
4949
this.translateService
5050
.get(['DEVICE-MODEL.DELETE-FAILED'])
5151
.subscribe((translations) => {

src/app/shared/components/top-bar/top-bar.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ <h3 class="pl-md-3">{{title || staticTitle}}</h3>
2525

2626
<!-- action buttons -->
2727
<div class="action-group d-flex justify-content-end">
28-
<button *ngIf="ctaRouterLink && ctaRouterLink != ''" [routerLink]="ctaRouterLink" routerLinkActive="active"
28+
29+
<button *ngIf="ctaRouterLink && ctaRouterLink != '' && canEdit" [routerLink]="ctaRouterLink" routerLinkActive="active"
2930
class="btn btn-primary mr-1" type="button" [attr.aria-label]="ctaLabel">{{ctaLabel}}</button>
30-
<div class="btn-group float-md-right dropdown" *ngIf="dropDownButton && addDetailDowndown === true">
31+
32+
<button *ngIf="dtRouterLink && dtRouterLink != ''" [routerLink]="dtRouterLink" routerLinkActive="active"
33+
class="btn btn-primary mr-1" type="button" [attr.aria-label]="dtLabel">{{dtLabel}}</button>
34+
35+
<div class="btn-group float-md-right dropdown" *ngIf="dropDownButton && addDetailDowndown === true && canEdit">
3136
<button type="button" id="dropdown-{{ data.name }}" class="btn btn-primary dropdown-toggle"
3237
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
3338
{{dropDownButton.label}} <span class="caret"></span>

0 commit comments

Comments
 (0)