From: Pedro Gonzalez Gomez Date: Mon, 13 Jan 2025 19:28:33 +0000 (+0100) Subject: mgr/dashboard: add smb share delete action X-Git-Tag: v20.0.0~102^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b1405c3c5e1c6e3dd9c3adaf47a5f5921fa51a48;p=ceph.git mgr/dashboard: add smb share delete action Fixes: https://tracker.ceph.com/issues/69521 Signed-off-by: Pedro Gonzalez Gomez --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html index 73e7deb2fac83..269152a257ee6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html @@ -18,7 +18,6 @@ > - > diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.html index 010b510f3ee4e..cc41f447ead59 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.html @@ -6,6 +6,7 @@ selectionType="single" [hasDetails]="false" (fetchData)="loadSMBShares()" + (updateSelection)="updateSelection($event)" >
{ let component: SmbShareListComponent; @@ -9,8 +12,9 @@ describe('SmbShareListComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], - declarations: [SmbShareListComponent] + imports: [ToastrModule.forRoot(), SharedModule], + declarations: [SmbShareListComponent], + providers: [provideHttpClient(), provideHttpClientTesting()] }).compileComponents(); fixture = TestBed.createComponent(SmbShareListComponent); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.ts index d352533a423a8..9b9aa86204a1e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.ts @@ -13,6 +13,11 @@ import { CellTemplate } from '~/app/shared/enum/cell-template.enum'; import { CdTableSelection } from '~/app/shared/models/cd-table-selection'; import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; import { Icons } from '~/app/shared/enum/icons.enum'; +import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component'; +import { FinishedTask } from '~/app/shared/models/finished-task'; +import { ModalCdsService } from '~/app/shared/services/modal-cds.service'; +import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; @Component({ selector: 'cd-smb-share-list', @@ -32,11 +37,14 @@ export class SmbShareListComponent implements OnInit { smbShares$: Observable; subject$ = new BehaviorSubject([]); + modalRef: NgbModalRef; constructor( private authStorageService: AuthStorageService, public actionLabels: ActionLabelsI18n, - private smbService: SmbService + private smbService: SmbService, + private taskWrapper: TaskWrapperService, + private modalService: ModalCdsService ) { this.permission = this.authStorageService.getPermissions().smb; } @@ -87,6 +95,12 @@ export class SmbShareListComponent implements OnInit { icon: Icons.add, routerLink: () => ['/cephfs/smb/share/create', this.clusterId], canBePrimary: (selection: CdTableSelection) => !selection.hasSingleSelection + }, + { + permission: 'delete', + icon: Icons.destroy, + click: () => this.deleteShareModal(), + name: this.actionLabels.DELETE } ]; @@ -105,4 +119,26 @@ export class SmbShareListComponent implements OnInit { loadSMBShares() { this.subject$.next([]); } + + updateSelection(selection: CdTableSelection) { + this.selection = selection; + } + + deleteShareModal() { + const cluster_id = this.selection.first().cluster_id; + const share_id = this.selection.first().share_id; + const name = this.selection.first().name; + + this.modalRef = this.modalService.show(DeleteConfirmationModalComponent, { + itemDescription: $localize`SMB Share`, + itemNames: [`Share: ${share_id} (${name}) from cluster: ${cluster_id}`], + submitActionObservable: () => + this.taskWrapper.wrapTaskAroundCall({ + task: new FinishedTask('smb/share/delete', { + share_id: share_id + }), + call: this.smbService.deleteShare(cluster_id, share_id) + }) + }); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts index 014d614dda8bf..34f1156a72fb5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts @@ -101,4 +101,14 @@ describe('SmbService', () => { const req = httpTesting.expectOne('api/smb/share'); expect(req.request.method).toBe('POST'); }); + + it('should call delete for given share of a cluster', () => { + const cluster_id = 'foo'; + const share_id = 'bar'; + service.deleteShare(cluster_id, share_id).subscribe((response: null) => { + expect(response).toBeUndefined(); + }); + const req = httpTesting.expectOne(`api/smb/share/${cluster_id}/${share_id}`); + expect(req.request.method).toBe('DELETE'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts index ae6ef3303237c..c719519c12d74 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, Subject } from 'rxjs'; @@ -55,4 +55,10 @@ export class SmbService { createShare(requestModel: ShareRequestModel) { return this.http.post(`${this.baseURL}/share`, requestModel); } + + deleteShare(clusterId: string, shareId: string): Observable> { + return this.http.delete(`${this.baseURL}/share/${clusterId}/${shareId}`, { + observe: 'response' + }); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts index 05f7c460712ab..a943abe0febe4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts @@ -498,6 +498,9 @@ export class TaskMessageService { ), 'smb/share/create': this.newTaskMessage(this.commonOperations.create, (metadata) => this.smbShare(metadata) + ), + 'smb/share/delete': this.newTaskMessage(this.commonOperations.delete, (metadata) => + this.smbShare(metadata) ) }; @@ -565,10 +568,6 @@ export class TaskMessageService { return $localize`SMB Cluster '${metadata.cluster_id}'`; } - smbShare(metadata: { share_id: string }) { - return $localize`SMB Share '${metadata.share_id}'`; - } - service(metadata: any) { return $localize`service '${metadata.service_name}'`; } @@ -611,6 +610,11 @@ export class TaskMessageService { snapshotSchedule(metadata: any) { return $localize`snapshot schedule for path '${metadata?.path}'`; } + + smbShare(metadata: Record<'share_id', string>) { + return $localize`SMB share '${metadata?.share_id}'`; + } + crudMessageId(id: string) { return $localize`${id}`; }