Skip to content

Commit 82d5568

Browse files
Merge branch 'stage' into feature/IoT-1500_GatewayAlarms
2 parents 1e8b92e + bf8490e commit 82d5568

File tree

5 files changed

+83
-24
lines changed

5 files changed

+83
-24
lines changed

.github/workflows/on-push-pr.action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ jobs:
1717
vulnerabilities-scan:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v2
21-
name: Checkout repository
22-
- uses: debricked/actions/scan@v1
23-
name: Run a vulnerability scan
20+
- uses: actions/checkout@v4
21+
- uses: debricked/actions@v4
2422
env:
25-
# Token must have API access scope to run scans
2623
DEBRICKED_TOKEN: ${{ secrets.DEBRICKED_TOKEN }}
2724
code-build:
2825
runs-on: ubuntu-latest

src/app/admin/permission/permission.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export class PermissionService {
5151
orderByColumn?: string,
5252
orderByDirection?: string,
5353
userId?: number,
54-
organisationId?: number
54+
organisationId?: number,
55+
ignoreGlobalAdmin?: boolean
5556
): Observable<PermissionGetManyResponse> {
5657
if (userId || organisationId) {
5758
return this.restService.get(this.endpoint, {
@@ -61,17 +62,28 @@ export class PermissionService {
6162
sort: orderByDirection,
6263
userId: userId,
6364
organisationId: organisationId,
65+
ignoreGlobalAdmin: ignoreGlobalAdmin,
6466
});
6567
} else {
6668
return this.restService.get(this.endpoint, {
6769
limit: limit,
6870
offset: offset,
6971
orderOn: orderByColumn,
7072
sort: orderByDirection,
73+
ignoreGlobalAdmin: ignoreGlobalAdmin,
7174
});
7275
}
7376
}
7477

78+
getPermissionsWithoutUsers(userId?: number): Observable<PermissionGetManyResponse> {
79+
return this.restService.get(this.endpoint + "/getAllPermissionsWithoutUsers", {
80+
limit: 1000,
81+
offset: 0,
82+
userId: userId ?? undefined,
83+
ignoreGlobalAdmin: true,
84+
});
85+
}
86+
7587
deletePermission(id: number) {
7688
return this.restService.delete(this.endpoint, id);
7789
}

src/app/admin/users/user-edit/user-edit.component.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@
7777
/>
7878
</div>
7979
</div>
80+
81+
<div class="row mb-5">
82+
<div class="form-group mt-3 col-12">
83+
<label class="form-label" id="permissions" for="permissions">{{ "QUESTION.PERMISSION.SELECT-PERMISSION" | translate }}</label
84+
>*
85+
<mat-select
86+
class="form-control"
87+
name="permissions"
88+
[compareWith]="compare"
89+
[(ngModel)]="user.permissionIds"
90+
[multiple]="true"
91+
>
92+
<mat-option *ngFor="let permission of permissions" [value]="permission.id">
93+
{{ permission.name }}
94+
</mat-option>
95+
</mat-select>
96+
</div>
97+
</div>
98+
8099
<div class="row mb-5">
81100
<mat-slide-toggle [(ngModel)]="user.active" id="active" name="active">
82101
{{ "USERS.FORM.ACTIVE" | translate }}</mat-slide-toggle

src/app/admin/users/user-edit/user-edit.component.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import { HttpErrorResponse } from "@angular/common/http";
2-
import { Component, OnInit } from "@angular/core";
3-
import { UntypedFormGroup } from "@angular/forms";
2+
import { Component, OnDestroy, OnInit } from "@angular/core";
3+
import { UntypedFormControl, UntypedFormGroup } from "@angular/forms";
44
import { ActivatedRoute } from "@angular/router";
55
import { UserRequest } from "../user.model";
66
import { TranslateService } from "@ngx-translate/core";
77
import { UserService } from "../user.service";
8-
import { Subscription } from "rxjs";
8+
import { Subject, Subscription } from "rxjs";
99
import { Location } from "@angular/common";
10-
import { PermissionType } from "@app/admin/permission/permission.model";
11-
import { AuthService, CurrentUserInfoResponse } from "@auth/auth.service";
12-
import { SharedVariableService } from "@shared/shared-variable/shared-variable.service";
10+
import { PermissionResponse, PermissionType } from "@app/admin/permission/permission.model";
1311
import { MeService } from "@shared/services/me.service";
1412
import { OrganizationAccessScope } from "@shared/enums/access-scopes";
13+
import { PermissionService } from "@app/admin/permission/permission.service";
14+
import { SharedVariableService } from "@shared/shared-variable/shared-variable.service";
1515

1616
@Component({
1717
selector: "app-user-edit",
1818
templateUrl: "./user-edit.component.html",
1919
styleUrls: ["./user-edit.component.scss"],
2020
})
21-
export class UserEditComponent implements OnInit {
22-
user = new UserRequest();
21+
export class UserEditComponent implements OnInit, OnDestroy {
22+
public user = new UserRequest();
23+
public permissions: PermissionResponse[];
24+
public permissionsSubscription: Subscription;
2325
public errorMessage: string;
2426
public errorMessages: any;
2527
public errorFields: string[];
@@ -28,20 +30,22 @@ export class UserEditComponent implements OnInit {
2830
public backButtonTitle = "";
2931
public title = "";
3032
public submitButton = "";
31-
id: number;
32-
subscription: Subscription;
33-
isGlobalAdmin = false;
34-
isKombit: boolean;
35-
canEdit: boolean;
33+
public id: number;
34+
public subscription: Subscription;
35+
public isGlobalAdmin = false;
36+
public isKombit: boolean;
37+
public canEdit: boolean;
38+
public permissionMultiCtrl: UntypedFormControl = new UntypedFormControl();
39+
private _onDestroy = new Subject<void>();
3640

3741
constructor(
3842
private translate: TranslateService,
3943
private route: ActivatedRoute,
4044
private userService: UserService,
4145
private location: Location,
42-
private authService: AuthService,
43-
private sharedVariableService: SharedVariableService,
44-
private meService: MeService
46+
private meService: MeService,
47+
private permissionService: PermissionService,
48+
private sharedVariableService: SharedVariableService
4549
) {}
4650

4751
ngOnInit(): void {
@@ -60,6 +64,7 @@ export class UserEditComponent implements OnInit {
6064
}
6165
this.amIGlobalAdmin();
6266
this.canEdit = this.meService.hasAccessToTargetOrganization(OrganizationAccessScope.UserAdministrationWrite);
67+
this.getPermissions(this.sharedVariableService.getUserInfo().user.id);
6368
}
6469

6570
private getUser(id: number) {
@@ -70,6 +75,8 @@ export class UserEditComponent implements OnInit {
7075
this.user.active = response.active;
7176
this.user.globalAdmin = response.permissions.some(perm => perm.name === PermissionType.GlobalAdmin);
7277
this.isKombit = response.nameId != null;
78+
this.user.permissionIds = response.permissions.map(pm => pm.id);
79+
7380
// We cannot set the password.
7481
});
7582
}
@@ -80,8 +87,7 @@ export class UserEditComponent implements OnInit {
8087

8188
private create(): void {
8289
this.userService.post(this.user).subscribe(
83-
response => {
84-
console.log(response);
90+
() => {
8591
this.routeBack();
8692
},
8793
(error: HttpErrorResponse) => {
@@ -132,4 +138,28 @@ export class UserEditComponent implements OnInit {
132138
routeBack(): void {
133139
this.location.back();
134140
}
141+
142+
public compare(matOptionValue: number, ngModelObject: number): boolean {
143+
return matOptionValue === ngModelObject;
144+
}
145+
146+
private getPermissions(userId: number) {
147+
this.permissionsSubscription = this.permissionService
148+
.getPermissionsWithoutUsers(this.meService.hasGlobalAdmin() ? undefined : userId)
149+
.subscribe(res => {
150+
this.permissions = res.data.sort((a, b) => a.name.localeCompare(b.name, "da-DK", { numeric: true }));
151+
if (!this.id) {
152+
this.permissionMultiCtrl.setValue(this.user.permissionIds);
153+
}
154+
});
155+
}
156+
157+
ngOnDestroy() {
158+
// prevent memory leak by unsubscribing
159+
if (this.permissionsSubscription) {
160+
this.permissionsSubscription.unsubscribe();
161+
}
162+
this._onDestroy.next();
163+
this._onDestroy.complete();
164+
}
135165
}

src/app/admin/users/user.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class UserRequest {
99
active: boolean;
1010
globalAdmin: boolean;
1111
showWelcomeScreen: boolean;
12+
permissionIds: number[]
1213
}
1314

1415
export interface UserResponse {

0 commit comments

Comments
 (0)