Skip to content
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
27 changes: 10 additions & 17 deletions src/app/admin/users/accept-user/accept-user.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<div *ngIf="user">
<app-top-bar
[backButtonTitle]="backButtonTitle"
[title]="title"
></app-top-bar>
<app-top-bar [backButtonTitle]="backButtonTitle" [title]="title"></app-top-bar>

<form (ngSubmit)="onSubmit()" class="os2-form p-3 mt-4">
<div *ngIf="errorMessages" class="error-messages p-3">
Expand All @@ -19,32 +16,28 @@
<h3>
{{ 'USERS.ACCEPT-USER.QUESTION-ACCEPT' | translate }}
{{ user.name }}
<ng-container *ngIf="organizationName">
{{ 'USERS.ACCEPT-USER.IN-ORGANIZATION' | translate }}
{{ organizationName}}
</ng-container>
</h3>
<mat-divider></mat-divider>

<div class="form-group mt-3 col-12">
<label class="form-label" for="level">{{
'PERMISSION.EDIT.TYPE' | translate
}}</label
>*
<mat-select id="permissionIds" class="form-control" name="permissionIds"
required
[formControl]="permissionsCtrl"
[(value)]="permission.permissionIds"
}}</label>*
<mat-select id="permissionIds" class="form-control" name="permissionIds" required
[formControl]="permissionsCtrl" [(value)]="permission.permissionIds"
[ngClass]="{'is-invalid' : formFailedSubmit && errorFields.includes('permissionIds'), 'is-valid' : formFailedSubmit && !errorFields.includes('permissionIds')}"
[placeholder]="'PERMISSION.EDIT.TYPE-PLACEHOLDER' | translate"
[multiple]="true">
[placeholder]="'PERMISSION.EDIT.TYPE-PLACEHOLDER' | translate" [multiple]="true">
<mat-option *ngFor="let permission of permissions" [value]="permission.id">
{{ permission.name }}
</mat-option>
</mat-select>
</div>
<div class="form-group mt-5">
<button
(click)="routeBack()"
class="btn btn-secondary"
type="button"
>
<button (click)="routeBack()" class="btn btn-secondary" type="button">
{{ 'GEN.CANCEL' | translate }}
</button>
<button class="btn btn-primary ml-2" type="submit">
Expand Down
3 changes: 3 additions & 0 deletions src/app/admin/users/accept-user/accept-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AcceptUserComponent implements OnInit, OnDestroy {
user: UserResponse;
errorFields: string[];
organizationId: number;
organizationName: string;
public formFailedSubmit = false;
errorMessages: any;
allowedLevels: PermissionTypes[] = [
Expand All @@ -54,6 +55,7 @@ export class AcceptUserComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.userId = +this.route.snapshot.paramMap.get('user-id');
this.organizationId = +this.route.snapshot.paramMap.get('org-id');

if (this.userId) {
this.getUser(this.userId);
}
Expand Down Expand Up @@ -93,6 +95,7 @@ export class AcceptUserComponent implements OnInit, OnDestroy {
(x) => x.organization?.id === this.organizationId
);
this.permissionsCtrl.setValue(this.permissions);
this.organizationName = permissionsResponse.data[0]?.organization?.name;
},
(error: HttpErrorResponse) => {
this.showError(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
[routerLink]="[
'/admin/users/accept-user/',
element.id,
organizationId
element.requestedOrganization.id
]"
routerLinkActive="active"
>{{ 'USERS.TABLE-ROW.APPROVE' | translate }}
</a>
</li>
<li class="dropdown-item">
<a (click)="rejectUser(element.id)" [routerLink]="">{{
<a (click)="rejectUser(element.id, element.requestedOrganization.id)" [routerLink]="">{{
'USERS.TABLE-ROW.REJECT' | translate
}}</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
RejectUserDto,
UserGetManyResponse,
UserResponse,
UserResponsePerRequestedOrganization,
} from '../../user.model';
import { UserService } from '../../user.service';
import { SharedVariableService } from '@shared/shared-variable/shared-variable.service';
Expand All @@ -22,15 +23,14 @@ import { DefaultPageSizeOptions } from '@shared/constants/page.constants';
})
export class AwaitingUsersTableComponent implements AfterViewInit {
displayedColumns: string[] = ['name', 'email', 'menu'];
users: UserResponse[];
users: UserResponsePerRequestedOrganization[];

public pageSize = environment.tablePageSize;
pageSizeOptions = DefaultPageSizeOptions;

resultsLength = 0;
public errorMessage: string;
isLoadingResults = true;
public organizationId: number;
message: string;
infoTitle: string;
@ViewChild(MatPaginator) paginator: MatPaginator;
Expand All @@ -47,7 +47,6 @@ export class AwaitingUsersTableComponent implements AfterViewInit {
) {}

ngAfterViewInit() {
this.organizationId = this.sharedService.getSelectedOrganisationId();
// If the user changes the sort order, reset back to the first page.
this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));

Expand All @@ -67,10 +66,24 @@ export class AwaitingUsersTableComponent implements AfterViewInit {
}),
catchError(() => {
this.isLoadingResults = false;
return observableOf([]);
return observableOf([] as UserResponse[]);
})
)
.subscribe((data) => (this.users = data));
.subscribe((userResponses) => {
this.users = [];

// Flatten users so each table row is exactly one request
for (const response of userResponses) {
const { requestedOrganizations, ...user} = response;

for (const organizationId of response.requestedOrganizations) {
this.users.push({
...user,
requestedOrganization: organizationId,
});
}
}
});

this.translate
.get(['USERS.DIALOG.QUESTION-REJECT', 'USERS.DIALOG.HEAD-REJECT'])
Expand All @@ -87,22 +100,20 @@ export class AwaitingUsersTableComponent implements AfterViewInit {
return this.userService.getAwaitingUsers(
this.paginator.pageSize,
this.paginator.pageIndex * this.paginator.pageSize,
this.organizationId,
orderByColumn,
orderByDirection
);
}

rejectUser(userId: number) {
rejectUser(userId: number, organizationId: number) {
this.deleteDialogService
.showSimpleDialog(this.message, false, true, false, this.infoTitle, true)
.subscribe((response) => {

if (response) {
const rejectUserOrgDto: RejectUserDto = {
orgId: this.organizationId,
userIdToReject: userId
}
const rejectUserOrgDto: RejectUserDto = {
orgId: organizationId,
userIdToReject: userId,
};

this.userService
.rejectUser(rejectUserOrgDto)
Expand Down
17 changes: 5 additions & 12 deletions src/app/admin/users/user-page/user-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,18 @@ export class UserPageComponent implements OnInit {
private translate: TranslateService,
private organizationService: OrganisationService,
private sharedService: SharedVariableService,
private errorMessageService: ErrorMessageService
private errorMessageService: ErrorMessageService,
private sharedVariableService: SharedVariableService,
) {}

ngOnInit(): void {
this.translate.get([
'USER_PAGE.AWAITING_CONFIRMATION',
'USER_PAGE.APPLY_ORGANISATIONS',
'USER_PAGE.APPLIED_ORGANISATIONS',
'USER_PAGE.QUESTION_APPLY_ORGANISAIONS',
'USER_PAGE.NO_APPLIED_ORGS',
'USER_PAGE.NO_ORGS',
]);

this.userInfo = this.sharedService.getUserInfo();
const hasSomePermission = this.sharedVariableService.getHasAnyPermission();

this.userService
.getOneSimple(this.userInfo.user.id)
.subscribe((response: UserResponse) => {
//When used as user-page, check for users organizations so it's only possible to apply not already joined organizations
// When used as user-page, check for users organizations so it's only possible to apply not already joined organizations
this.requestedUserOrganizations = response.requestedOrganizations;
if (this.userInfo.organizations.length > 0) {
this.compareRequestedAndAlreadyJoinedOrganizations(
Expand All @@ -80,7 +73,7 @@ export class UserPageComponent implements OnInit {
}

this.awaitingConfirmation = response.awaitingConfirmation;
if (!this.awaitingConfirmation) {
if (!this.awaitingConfirmation && hasSomePermission) {
this.translate
.get('GEN.BACK')
.subscribe((translation) => (this.backButtonTitle = translation));
Expand Down
7 changes: 6 additions & 1 deletion src/app/admin/users/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class UserRequest {
password: string;
active: boolean;
globalAdmin: boolean;
showWelcomeScreen: boolean;
showWelcomeScreen: boolean;
}

export interface UserResponse {
Expand All @@ -33,6 +33,11 @@ export interface UserResponse {
requestedOrganizations: OrganisationResponse[];
}

export interface UserResponsePerRequestedOrganization
extends Omit<UserResponse, 'requestedOrganizations'> {
requestedOrganization: OrganisationResponse;
}

export interface UserGetManyResponse {
data: UserResponse[];
count: number;
Expand Down
27 changes: 15 additions & 12 deletions src/app/admin/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
})
export class UserService {
URL = 'user';
URL_NEW_KOMBIT = "kombitCreation"
URL_NEW_KOMBIT = 'kombitCreation';

constructor(
private restService: RestService,
Expand All @@ -37,7 +37,7 @@ export class UserService {

getOne(id: number, extendedInfo = false): Observable<UserResponse> {
return this.restService
.get(this.URL, { extendedInfo: extendedInfo }, id)
.get(this.URL, { extendedInfo }, id)
.pipe(
map((response: UserResponse) => {
response.createdByName = this.userMinimalService.getUserNameFrom(
Expand All @@ -60,13 +60,13 @@ export class UserService {
): Observable<UserGetManyResponse> {
if (permissionId != null) {
return this.restService.get(`permission/${permissionId}/users`, {
limit: limit,
offset: offset,
limit,
offset,
});
} else {
return this.restService.get(this.URL, {
limit: limit,
offset: offset,
limit,
offset,
orderOn: orderByColumn,
sort: orderByDirection,
});
Expand All @@ -76,11 +76,10 @@ export class UserService {
hideWelcome(id: number): Observable<boolean> {
return this.restService.put(`${this.URL}/${id}/hide-welcome`, null, null);
}

getAwaitingUsers(
limit: number = 1000,
offset: number = 0,
organizationId: number,
orderByColumn?: string,
orderByDirection?: string
): Observable<UserGetManyResponse> {
Expand All @@ -92,7 +91,6 @@ export class UserService {
orderOn: orderByColumn,
sort: orderByDirection,
},
organizationId
);
}

Expand All @@ -115,9 +113,14 @@ export class UserService {
}

updateUserOrgs(body: UpdateUserOrgsDto): Observable<void> {
return this.restService.put(this.URL_NEW_KOMBIT + '/updateUserOrgs', body, undefined, {
observe: 'response',
});
return this.restService.put(
this.URL_NEW_KOMBIT + '/updateUserOrgs',
body,
undefined,
{
observe: 'response',
}
);
}

rejectUser(body: RejectUserDto): Observable<Organisation> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ApplicationsListComponent implements OnInit {
});
} else {
// Clear the URL from the parameter
this.router.navigate(['/applications']);
this.router.navigate(['/applications'], { replaceUrl: true });
}
} else {
const error = params['error'];
Expand Down Expand Up @@ -139,6 +139,13 @@ export class ApplicationsListComponent implements OnInit {
hasSomePermission: this.hasSomePermission,
} as WelcomeDialogModel,
});

if (!this.hasSomePermission) {
// In case a previous .navigate() was fired, ensure this is called after
setTimeout(() => {
this.router.navigate(['/user-page'], { replaceUrl: true });
});
}
}

if (this.hasSomePermission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
</div>
<div class="container">
<header mat-dialog-title class="text-center header">
<h1>
<h2>
{{'WELCOME-DIALOG.WELCOME' | translate}}
</h1>
<h2>{{ (dialogModel?.hasSomePermission ? 'WELCOME-DIALOG.WELCOME-SUB' : 'WELCOME-DIALOG.NO-ACCESS') | translate}}</h2>
</h2>
<p>{{ (dialogModel?.hasSomePermission ? 'WELCOME-DIALOG.WELCOME-SUB' : 'WELCOME-DIALOG.NO-ACCESS') | translate}}</p>
</header>
<div mat-dialog-content class="col-md-12 px-md-4" *ngIf="dialogModel?.hasSomePermission">
<p class="sub-header"><strong>{{'WELCOME-DIALOG.SUB-HEADER-1' | translate}}</strong></p>
Expand All @@ -33,7 +33,6 @@ <h2>{{ (dialogModel?.hasSomePermission ? 'WELCOME-DIALOG.WELCOME-SUB' : 'WELCOME
<button (click)="close()" mat-dialog-close class="btn ok text--big">
{{'DIALOG.OK' | translate | uppercase}}
</button>

</div>
</div>
<mat-checkbox *ngIf="dialogModel?.hasSomePermission" [(ngModel)]="dontShowAgain" name="dontShowAgain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ $spacing: 5rem;
}

.header {
h1 {
font-size: 3rem;
h2 {
color: $color-white-001;
margin-bottom: 0 !important;
}
h2 {
p {
color: $color-white-001;
}
}
Expand Down Expand Up @@ -47,7 +46,7 @@ $spacing: 5rem;
}

.btn.ok {
margin-top: 5rem;
margin-top: 1rem;
margin-bottom: 1rem;

background-color: #f79267;
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,8 @@
},
"ACCEPT-USER": {
"ACCEPT": "Godkend bruger",
"QUESTION-ACCEPT": "Vælg brugergruppe til "
"QUESTION-ACCEPT": "Vælg brugergruppe til ",
"IN-ORGANIZATION": "i organisationen "
}
},
"AUTH": {
Expand Down