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

Added organization filter to permissions #139

Merged
merged 2 commits into from
Jul 5, 2023
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
150 changes: 75 additions & 75 deletions src/app/admin/permission/permission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,94 @@ import { Injectable } from '@angular/core';
import { RestService } from '../../shared/services/rest.service';
import { Observable } from 'rxjs';
import {
PermissionGetManyResponse,
PermissionResponse,
PermissionRequest,
PermissionRequestAcceptUser,
PermissionGetManyResponse,
PermissionResponse,
PermissionRequest,
PermissionRequestAcceptUser,
} from './permission.model';
import { map } from 'rxjs/operators';
import { UserMinimalService } from '../users/user-minimal.service';

@Injectable({
providedIn: 'root',
providedIn: 'root',
})
export class PermissionService {
endpoint = 'permission';
constructor(
private restService: RestService,
private userMinimalService: UserMinimalService
) {}
endpoint = 'permission';
constructor(
private restService: RestService,
private userMinimalService: UserMinimalService
) {}

createPermission(body: PermissionRequest): Observable<PermissionResponse> {
return this.restService.post(this.endpoint, body, {
observe: 'response',
});
}
createPermission(body: PermissionRequest): Observable<PermissionResponse> {
return this.restService.post(this.endpoint, body, {
observe: 'response',
});
}

createPermissionAcceptUser(body: PermissionRequestAcceptUser): Observable<PermissionResponse> {
return this.restService.put(this.endpoint + '/acceptUser', body, undefined, {
observe: 'response',
});
}
createPermissionAcceptUser(
body: PermissionRequestAcceptUser
): Observable<PermissionResponse> {
return this.restService.put(
this.endpoint + '/acceptUser',
body,
undefined,
{
observe: 'response',
}
);
}

updatePermission(
body: PermissionRequest,
id: number
): Observable<PermissionResponse> {
return this.restService.put(this.endpoint, body, id, {
observe: 'response',
});
}
updatePermission(
body: PermissionRequest,
id: number
): Observable<PermissionResponse> {
return this.restService.put(this.endpoint, body, id, {
observe: 'response',
});
}

getPermission(id: number): Observable<PermissionResponse> {
return this.restService.get(this.endpoint, {}, id).pipe(
map((response: PermissionResponse) => {
response.createdByName = this.userMinimalService.getUserNameFrom(
response.createdBy
);
response.updatedByName = this.userMinimalService.getUserNameFrom(
response.updatedBy
);
return response;
})
getPermission(id: number): Observable<PermissionResponse> {
return this.restService.get(this.endpoint, {}, id).pipe(
map((response: PermissionResponse) => {
response.createdByName = this.userMinimalService.getUserNameFrom(
response.createdBy
);
}
response.updatedByName = this.userMinimalService.getUserNameFrom(
response.updatedBy
);
return response;
})
);
}

getPermissions(
limit: number = 1000,
offset: number = 0,
orderByColumn?: string,
orderByDirection?: string,
userId?: number,
organisationId?: number
): Observable<PermissionGetManyResponse> {
if (userId) {
return this.restService.get(this.endpoint, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
userId: userId,
});
} else if (organisationId) {
return this.restService.get(this.endpoint, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
organisationId: organisationId,
});
} else {
return this.restService.get(this.endpoint, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
});
}
getPermissions(
limit: number = 1000,
offset: number = 0,
orderByColumn?: string,
orderByDirection?: string,
userId?: number,
organisationId?: number
): Observable<PermissionGetManyResponse> {
if (userId || organisationId) {
return this.restService.get(this.endpoint, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
userId: userId,
organisationId: organisationId,
});
} else {
return this.restService.get(this.endpoint, {
limit: limit,
offset: offset,
orderOn: orderByColumn,
sort: orderByDirection,
});
}
}

deletePermission(id: number) {
return this.restService.delete(this.endpoint, id);
}
deletePermission(id: number) {
return this.restService.delete(this.endpoint, id);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div *ngIf="application">
<app-top-bar [data]="application" [backButton]="backButton" [subPage]="true"
[addDetailDowndown]="true" [dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteApplication()"
[canEdit]="canEdit">
[addDetailDowndown]="true" [dropDownButton]="dropdownButton"
(deleteSelectedInDropdown)="onDeleteApplication()"
[canEdit]="canEdit">
</app-top-bar>
<div class="container-fluid">
<div class="row">
Expand All @@ -15,17 +16,20 @@ <h3>{{ 'APPLICATION.DETAILS' | translate }}</h3>
<p *ngIf="application.description">
<strong>{{ 'APPLICATION.DESCRIPTION' | translate }}</strong></p>
<pre><p>{{application.description}}</p></pre>
<app-metadata-details [status]="application.status" [startDate]="application.startDate"
[endDate]="application.endDate"
[category]="application.category"
[owner]="application.owner"
[contactPerson]="application.contactPerson"
[contactEmail]="application.contactEmail"
[contactPhone]="application.contactPhone"
[personalData]="application.personalData"
[hardware]="application.hardware"
[controlledProperties]="application.controlledProperties"
[deviceTypes]="application.deviceTypes"
<app-metadata-details
[permissions]="application.permissions"
[status]="application.status"
[startDate]="application.startDate"
[endDate]="application.endDate"
[category]="application.category"
[owner]="application.owner"
[contactPerson]="application.contactPerson"
[contactEmail]="application.contactEmail"
[contactPhone]="application.contactPhone"
[personalData]="application.personalData"
[hardware]="application.hardware"
[controlledProperties]="application.controlledProperties"
[deviceTypes]="application.deviceTypes"
></app-metadata-details>
</div>
</div>
Expand All @@ -36,7 +40,7 @@ <h3>{{ 'APPLICATION.DETAILS' | translate }}</h3>
[routerLink]="link.link"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive"
>{{ link.label | translate }}</a>
>{{ link.label | translate }}</a>
</nav>
<router-outlet></router-outlet>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/app/applications/application.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Organisation } from '../admin/organisation/organisation.model';
import { ApplicationStatus } from './enums/status.enum';
import { IotDevice } from './iot-devices/iot-device.model';
import { ApplicationDeviceType } from './models/application-device-type.model';
import { PermissionResponse } from '@app/admin/permission/permission.model';

export class Application {
public id: number;
Expand All @@ -30,6 +31,7 @@ export class Application {
public hardware?: string;
public controlledProperties?: ControlledProperty[];
public deviceTypes?: ApplicationDeviceType[];
public permissions: PermissionResponse[];
public permissionIds: number[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export class FormBodyApplicationComponent implements OnInit, OnDestroy {
0,
undefined,
undefined,
this.meService.hasGlobalAdmin() ? undefined : userId
this.meService.hasGlobalAdmin() ? undefined : userId,
this.sharedVariableService.getSelectedOrganisationId()
)
.subscribe((res) => {
this.permissions = res.data.sort((a, b) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p *ngIf="permissions.length !== 0"><strong>{{ 'APPLICATION.METADATA-FIELD.PERMISSIONS' | translate }}</strong></p>
<ul *ngIf="permissions.length !== 0">
<li *ngFor="let permission of permissions">{{ permission.name }}</li>
</ul>
<p *ngIf="status && status !== ApplicationStatus.NONE">
<strong>{{ 'APPLICATION.METADATA-FIELD.STATUS' | translate }}</strong>{{ 'APPLICATION.STATUS.' + status | translate }}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { ApplicationDeviceType } from '@applications/models/application-device-t
import { TranslateService } from '@ngx-translate/core';
import { toPascalKebabCase } from '@shared/helpers/string.helper';
import { ControlledProperty } from '@shared/models/controlled-property.model';
import { PermissionResponse } from '@app/admin/permission/permission.model';

@Component({
selector: 'app-metadata-details',
templateUrl: './metadata-details.component.html',
styleUrls: ['./metadata-details.component.scss'],
})
export class MetadataDetailsComponent implements OnInit {
@Input() permissions?: PermissionResponse[];
@Input() status?: ApplicationStatus;
@Input() startDate?: Date;
@Input() endDate?: Date;
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
},
"DETAILS": "Detaljer",
"METADATA-FIELD": {
"PERMISSIONS": "Brugergrupper",
"STATUS": "Status",
"START-DATE": "Startdato",
"END-DATE": "Slutdato",
Expand Down