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
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2 id="search" class="border-bottom pb-2">{{messagePrefix + 'search.head' | tra
}
@if (!groupDto.group?.permanent && groupDto.ableToDelete) {
<button
(click)="deleteGroup(groupDto)" class="btn btn-outline-danger btn-sm btn-delete"
(click)="confirmDelete(groupDto)" class="btn btn-outline-danger btn-sm btn-delete"
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: dsoNameService.getName(groupDto.group) } }}">
<i class="fas fa-trash-alt fa-fw"></i>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ describe('GroupsRegistryComponent', () => {
deleteButton.click();
fixture.detectChanges();

(document as any).querySelector('.modal-footer .confirm').click();

expect(groupsDataServiceStub.delete).toHaveBeenCalledWith(mockGroups[0].id);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
UntypedFormBuilder,
} from '@angular/forms';
import { RouterLink } from '@angular/router';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import {
NgbModal,
NgbTooltipModule,
} from '@ng-bootstrap/ng-bootstrap';
import {
TranslateModule,
TranslateService,
Expand All @@ -27,6 +30,7 @@
defaultIfEmpty,
map,
switchMap,
takeUntil,
tap,
} from 'rxjs/operators';

Expand Down Expand Up @@ -57,6 +61,7 @@
} from '../../core/shared/operators';
import { PageInfo } from '../../core/shared/page-info.model';
import { BtnDisabledDirective } from '../../shared/btn-disabled.directive';
import { ConfirmationModalComponent } from '../../shared/confirmation-modal/confirmation-modal.component';
import { hasValue } from '../../shared/empty.util';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { NotificationsService } from '../../shared/notifications/notifications.service';
Expand Down Expand Up @@ -142,6 +147,7 @@
private paginationService: PaginationService,
public requestService: RequestService,
public dsoNameService: DSONameService,
private modalService: NgbModal,
) {
this.currentSearchQuery = '';
this.searchForm = this.formBuilder.group(({
Expand Down Expand Up @@ -314,4 +320,30 @@
this.paginationService.clearPagination(this.config.id);
}

confirmDelete(group: GroupDtoModel): void {
const modalRef = this.modalService.open(ConfirmationModalComponent);
modalRef.componentInstance.name = this.dsoNameService.getName(group.group);
modalRef.componentInstance.headerLabel = 'admin.access-control.epeople.table.edit.buttons.remove.modal.header';
modalRef.componentInstance.infoLabel = 'admin.access-control.epeople.table.edit.buttons.remove.modal.info';
modalRef.componentInstance.cancelLabel = 'admin.access-control.epeople.table.edit.buttons.remove.modal.cancel';
modalRef.componentInstance.confirmLabel = 'admin.access-control.epeople.table.edit.buttons.remove.modal.confirm';
modalRef.componentInstance.brandColor = 'danger';
modalRef.componentInstance.confirmIcon = 'fas fa-trash';

const modalSub: Subscription = modalRef.componentInstance.response.pipe(
takeUntil(modalRef.closed),
).subscribe((result: boolean) => {
if (result === true) {
this.deleteGroup(group);
}
});

void modalRef.result.then().finally(() => {
modalRef.close();
if (modalSub && !modalSub.closed) {
modalSub.unsubscribe();

Check warning on line 344 in src/app/access-control/group-registry/groups-registry.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/access-control/group-registry/groups-registry.component.ts#L344

Added line #L344 was not covered by tests
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h2 class="h4 w-100">
@if (hasCustomGroup$ | async) {
<button
class="btn btn-danger delete"
(click)="delete()">
(click)="confirmDelete(dsoNameService.getName(group))">
<i class="fas fa-trash" aria-hidden="true"></i> {{'comcol-role.edit.delete' | translate}}
</button>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';

Expand All @@ -36,17 +37,22 @@ describe('ComcolRoleComponent', () => {
let comcolRole;
let notificationsService;

const requestService = { hasByHref$: () => of(true) };
const requestService = {
hasByHref$: () => of(true),
setStaleByHrefSubstring: () => of(true),
};

const groupService = {
findByHref: jasmine.createSpy('findByHref'),
createComcolGroup: jasmine.createSpy('createComcolGroup').and.returnValue(of({})),
deleteComcolGroup: jasmine.createSpy('deleteComcolGroup').and.returnValue(of({})),
clearGroupsRequests: jasmine.createSpy('clearGroupsRequests'),
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
NgbModule,
RouterTestingModule.withRoutes([]),
TranslateModule.forRoot(),
NoopAnimationsModule,
Expand Down Expand Up @@ -178,13 +184,17 @@ describe('ComcolRoleComponent', () => {
fixture.detectChanges();
});

afterEach(() => {
const modal = document.querySelector('ds-confirmation-modal');
if (modal) {
modal.remove();
}
});

it('should have a delete button but no create or restrict button', (done) => {
expect(de.query(By.css('.btn.create')))
.toBeNull();
expect(de.query(By.css('.btn.restrict')))
.toBeNull();
expect(de.query(By.css('.btn.delete')))
.toBeTruthy();
expect(de.query(By.css('.btn.create'))).toBeNull();
expect(de.query(By.css('.btn.restrict'))).toBeNull();
expect(de.query(By.css('.btn.delete'))).toBeTruthy();
done();
});

Expand All @@ -195,6 +205,7 @@ describe('ComcolRoleComponent', () => {
});

it('should call the groupService delete method', (done) => {
(document as any).querySelector('.modal-footer .confirm').click();
expect(groupService.deleteComcolGroup).toHaveBeenCalled();
done();
});
Expand All @@ -207,9 +218,11 @@ describe('ComcolRoleComponent', () => {
});

it('should show an error notification', (done) => {
(document as any).querySelector('.modal-footer .confirm').click();
expect(notificationsService.error).toHaveBeenCalled();
done();
});
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
OnInit,
} from '@angular/core';
import { RouterLink } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import {
BehaviorSubject,
Observable,
Subscription,
} from 'rxjs';
import {
filter,
map,
switchMap,
takeUntil,
} from 'rxjs/operators';

import { getGroupEditRoute } from '../../../../../access-control/access-control-routing-paths';
Expand All @@ -34,6 +37,7 @@
getFirstCompletedRemoteData,
} from '../../../../../core/shared/operators';
import { AlertComponent } from '../../../../alert/alert.component';
import { ConfirmationModalComponent } from '../../../../confirmation-modal/confirmation-modal.component';
import {
hasNoValue,
hasValue,
Expand Down Expand Up @@ -115,6 +119,7 @@
protected notificationsService: NotificationsService,
protected translateService: TranslateService,
public dsoNameService: DSONameService,
private modalService: NgbModal,
) {
}

Expand Down Expand Up @@ -215,4 +220,31 @@

this.roleName$ = this.translateService.get(`comcol-role.edit.${this.comcolRole.name}.name`);
}

confirmDelete(groupName: string): void {
const modalRef = this.modalService.open(ConfirmationModalComponent);

modalRef.componentInstance.name = groupName;
modalRef.componentInstance.headerLabel = 'comcol-role.edit.delete.modal.header';
modalRef.componentInstance.infoLabel = 'comcol-role.edit.delete.modal.info';
modalRef.componentInstance.cancelLabel = 'comcol-role.edit.delete.modal.cancel';
modalRef.componentInstance.confirmLabel = 'comcol-role.edit.delete.modal.confirm';
modalRef.componentInstance.brandColor = 'danger';
modalRef.componentInstance.confirmIcon = 'fas fa-trash';

const modalSub: Subscription = modalRef.componentInstance.response.pipe(
takeUntil(modalRef.closed),
).subscribe((result: boolean) => {
if (result === true) {
this.delete();
}
});

void modalRef.result.then().finally(() => {
modalRef.close();
if (modalSub && !modalSub.closed) {
modalSub.unsubscribe();

Check warning on line 246 in src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts#L246

Added line #L246 was not covered by tests
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:host {
.modal {
&-body, &-header {
word-break: break-word;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TranslateModule } from '@ngx-translate/core';
@Component({
selector: 'ds-confirmation-modal',
templateUrl: 'confirmation-modal.component.html',
styleUrls: ['confirmation-modal.component.scss'],
standalone: true,
imports: [
TranslateModule,
Expand Down
35 changes: 34 additions & 1 deletion src/assets/i18n/ar.json5
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@
// "admin.access-control.epeople.table.edit.buttons.remove": "Delete \"{{name}}\"",
"admin.access-control.epeople.table.edit.buttons.remove": "حذف \"{{name}}\"",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.header": "Delete Group \"{{ dsoName }}\"",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.header": "Delete Group \"{{ dsoName }}\"",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.cancel": "Cancel",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.cancel": "Cancel",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.confirm": "Delete",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.confirm": "Delete",

// "admin.access-control.epeople.no-items": "No EPeople to show.",
"admin.access-control.epeople.no-items": "لا يوجد أشخاص إلكترونيين للعرض.",

Expand Down Expand Up @@ -651,7 +667,8 @@
// "admin.access-control.groups.form.delete-group.modal.header": "Delete Group \"{{ dsoName }}\"",
"admin.access-control.groups.form.delete-group.modal.header": "حذف المجموعة \"{{ dsoName }}\"",

// "admin.access-control.groups.form.delete-group.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\"",
// "admin.access-control.groups.form.delete-group.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO Source message changed - Revise the translation
"admin.access-control.groups.form.delete-group.modal.info": "هل أنت متأكد من أنك ترغب في حذف المجموعة \"{{ dsoName }}\"",

// "admin.access-control.groups.form.delete-group.modal.cancel": "Cancel",
Expand Down Expand Up @@ -2407,6 +2424,22 @@
// "comcol-role.edit.delete.error.title": "Failed to delete the '{{ role }}' role's group",
"comcol-role.edit.delete.error.title": "فشل حذف مجموعة الدور '{{ role }}'",

// "comcol-role.edit.delete.modal.header": "Delete Group \"{{ dsoName }}\"",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.header": "Delete Group \"{{ dsoName }}\"",

// "comcol-role.edit.delete.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",

// "comcol-role.edit.delete.modal.cancel": "Cancel",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.cancel": "Cancel",

// "comcol-role.edit.delete.modal.confirm": "Delete",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.confirm": "Delete",

// "comcol-role.edit.community-admin.name": "Administrators",
"comcol-role.edit.community-admin.name": "المسؤولون",

Expand Down
35 changes: 34 additions & 1 deletion src/assets/i18n/bn.json5
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@
// "admin.access-control.epeople.table.edit.buttons.remove": "Delete \"{{name}}\"",
"admin.access-control.epeople.table.edit.buttons.remove": "\"{{ name }}\" মুছে ফেলুন",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.header": "Delete Group \"{{ dsoName }}\"",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.header": "Delete Group \"{{ dsoName }}\"",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.cancel": "Cancel",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.cancel": "Cancel",

// "admin.access-control.epeople.table.edit.buttons.remove.modal.confirm": "Delete",
// TODO New key - Add a translation
"admin.access-control.epeople.table.edit.buttons.remove.modal.confirm": "Delete",

// "admin.access-control.epeople.no-items": "No EPeople to show.",
"admin.access-control.epeople.no-items": "কোন ই-পারসিওন প্রদর্শন করার জন্যে নেই।",

Expand Down Expand Up @@ -695,7 +711,8 @@
// "admin.access-control.groups.form.delete-group.modal.header": "Delete Group \"{{ dsoName }}\"",
"admin.access-control.groups.form.delete-group.modal.header": "গ্রুপ মুছে ফেলুন \"{{ dsoName }}\"",

// "admin.access-control.groups.form.delete-group.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\"",
// "admin.access-control.groups.form.delete-group.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO Source message changed - Revise the translation
"admin.access-control.groups.form.delete-group.modal.info": "আপনি কি গ্রুপ \"{{ dsoName }}\" মুছে ফেলতে চান তা নিশ্চিত করুন।",

// "admin.access-control.groups.form.delete-group.modal.cancel": "Cancel",
Expand Down Expand Up @@ -2558,6 +2575,22 @@
// TODO New key - Add a translation
"comcol-role.edit.delete.error.title": "Failed to delete the '{{ role }}' role's group",

// "comcol-role.edit.delete.modal.header": "Delete Group \"{{ dsoName }}\"",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.header": "Delete Group \"{{ dsoName }}\"",

// "comcol-role.edit.delete.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\" and all its associated policies?",

// "comcol-role.edit.delete.modal.cancel": "Cancel",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.cancel": "Cancel",

// "comcol-role.edit.delete.modal.confirm": "Delete",
// TODO New key - Add a translation
"comcol-role.edit.delete.modal.confirm": "Delete",

// "comcol-role.edit.community-admin.name": "Administrators",
"comcol-role.edit.community-admin.name": "প্রশাসক",

Expand Down
Loading
Loading