Skip to content

Commit

Permalink
NAS-132725: UI - Do not allow user to delete themselves (#11121)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKarpov98 authored Dec 4, 2024
1 parent 1d33b2f commit 05a0c9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</button>

<ng-container *ixRequiresRoles="[Role.AccountWrite]">
@if (!user().immutable) {
@if (!user().immutable && loggedInUser().pw_name !== user().username) {
<button
mat-button
[ixTest]="['delete', user().username]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ describe('UserDetailsRowComponent', () => {
expect(deleteButton).toBeNull();
});

it('does not show Delete button for logged in user', async () => {
spectator.setInput('user', { ...dummyUser, username: 'root' });

const deleteButton = await loader.getHarnessOrNull(MatButtonHarness.with({ text: /Delete/ }));
expect(deleteButton).toBeNull();
});

it('should open DeleteUserDialog when Delete button is pressed', async () => {
const deleteButton = await loader.getHarness(MatButtonHarness.with({ text: /Delete/ }));
await deleteButton.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {
Component, ChangeDetectionStrategy, input,
output,
} from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { MatButton } from '@angular/material/button';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { filter } from 'rxjs';
import { RequiresRolesDirective } from 'app/directives/requires-roles/requires-roles.directive';
import { Role } from 'app/enums/role.enum';
import { ActionOption } from 'app/interfaces/option.interface';
Expand All @@ -19,6 +21,7 @@ import {
DeleteUserDialogComponent,
} from 'app/pages/credentials/users/user-details-row/delete-user-dialog/delete-user-dialog.component';
import { UserFormComponent } from 'app/pages/credentials/users/user-form/user-form.component';
import { AuthService } from 'app/services/auth/auth.service';
import { SlideInService } from 'app/services/slide-in.service';
import { UrlOptionsService } from 'app/services/url-options.service';

Expand All @@ -41,6 +44,8 @@ export class UserDetailsRowComponent {
readonly user = input.required<User>();
readonly delete = output<number>();

loggedInUser = toSignal(this.authService.user$.pipe(filter(Boolean)));

protected readonly Role = Role;

constructor(
Expand All @@ -49,6 +54,7 @@ export class UserDetailsRowComponent {
private matDialog: MatDialog,
private yesNoPipe: YesNoPipe,
private urlOptions: UrlOptionsService,
private authService: AuthService,
private router: Router,
) {}

Expand Down

0 comments on commit 05a0c9d

Please sign in to comment.