Skip to content

Commit 8fae8d0

Browse files
authored
Merge pull request ceph#61353 from rhcs-dashboard/smb-share-delete
mgr/dashboard: add smb delete share action Reviewed-by: Afreen Misbah <[email protected]>
2 parents 4aa6ff9 + b1405c3 commit 8fae8d0

File tree

7 files changed

+70
-10
lines changed

7 files changed

+70
-10
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-list/smb-cluster-list.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
>
1919
</cd-table-actions>
2020
</div>
21-
>
2221
<cd-smb-cluster-tabs
2322
*cdTableDetail
2423
[selection]="expandedRow">

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
selectionType="single"
77
[hasDetails]="false"
88
(fetchData)="loadSMBShares()"
9+
(updateSelection)="updateSelection($event)"
910
>
1011
<div class="table-actions">
1112
<cd-table-actions

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { SmbShareListComponent } from './smb-share-list.component';
4-
import { HttpClientTestingModule } from '@angular/common/http/testing';
4+
import { provideHttpClientTesting } from '@angular/common/http/testing';
5+
import { provideHttpClient } from '@angular/common/http';
6+
import { ToastrModule } from 'ngx-toastr';
7+
import { SharedModule } from '~/app/shared/shared.module';
58

69
describe('SmbShareListComponent', () => {
710
let component: SmbShareListComponent;
811
let fixture: ComponentFixture<SmbShareListComponent>;
912

1013
beforeEach(async () => {
1114
await TestBed.configureTestingModule({
12-
imports: [HttpClientTestingModule],
13-
declarations: [SmbShareListComponent]
15+
imports: [ToastrModule.forRoot(), SharedModule],
16+
declarations: [SmbShareListComponent],
17+
providers: [provideHttpClient(), provideHttpClientTesting()]
1418
}).compileComponents();
1519

1620
fixture = TestBed.createComponent(SmbShareListComponent);

src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-share-list/smb-share-list.component.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
1313
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
1414
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
1515
import { Icons } from '~/app/shared/enum/icons.enum';
16+
import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
17+
import { FinishedTask } from '~/app/shared/models/finished-task';
18+
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
19+
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
20+
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
1621

1722
@Component({
1823
selector: 'cd-smb-share-list',
@@ -32,11 +37,14 @@ export class SmbShareListComponent implements OnInit {
3237

3338
smbShares$: Observable<SMBShare[]>;
3439
subject$ = new BehaviorSubject<SMBShare[]>([]);
40+
modalRef: NgbModalRef;
3541

3642
constructor(
3743
private authStorageService: AuthStorageService,
3844
public actionLabels: ActionLabelsI18n,
39-
private smbService: SmbService
45+
private smbService: SmbService,
46+
private taskWrapper: TaskWrapperService,
47+
private modalService: ModalCdsService
4048
) {
4149
this.permission = this.authStorageService.getPermissions().smb;
4250
}
@@ -87,6 +95,12 @@ export class SmbShareListComponent implements OnInit {
8795
icon: Icons.add,
8896
routerLink: () => ['/cephfs/smb/share/create', this.clusterId],
8997
canBePrimary: (selection: CdTableSelection) => !selection.hasSingleSelection
98+
},
99+
{
100+
permission: 'delete',
101+
icon: Icons.destroy,
102+
click: () => this.deleteShareModal(),
103+
name: this.actionLabels.DELETE
90104
}
91105
];
92106

@@ -105,4 +119,26 @@ export class SmbShareListComponent implements OnInit {
105119
loadSMBShares() {
106120
this.subject$.next([]);
107121
}
122+
123+
updateSelection(selection: CdTableSelection) {
124+
this.selection = selection;
125+
}
126+
127+
deleteShareModal() {
128+
const cluster_id = this.selection.first().cluster_id;
129+
const share_id = this.selection.first().share_id;
130+
const name = this.selection.first().name;
131+
132+
this.modalRef = this.modalService.show(DeleteConfirmationModalComponent, {
133+
itemDescription: $localize`SMB Share`,
134+
itemNames: [`Share: ${share_id} (${name}) from cluster: ${cluster_id}`],
135+
submitActionObservable: () =>
136+
this.taskWrapper.wrapTaskAroundCall({
137+
task: new FinishedTask('smb/share/delete', {
138+
share_id: share_id
139+
}),
140+
call: this.smbService.deleteShare(cluster_id, share_id)
141+
})
142+
});
143+
}
108144
}

src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,14 @@ describe('SmbService', () => {
101101
const req = httpTesting.expectOne('api/smb/share');
102102
expect(req.request.method).toBe('POST');
103103
});
104+
105+
it('should call delete for given share of a cluster', () => {
106+
const cluster_id = 'foo';
107+
const share_id = 'bar';
108+
service.deleteShare(cluster_id, share_id).subscribe((response: null) => {
109+
expect(response).toBeUndefined();
110+
});
111+
const req = httpTesting.expectOne(`api/smb/share/${cluster_id}/${share_id}`);
112+
expect(req.request.method).toBe('DELETE');
113+
});
104114
});

src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpClient } from '@angular/common/http';
1+
import { HttpClient, HttpResponse } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { Observable, Subject } from 'rxjs';
44

@@ -55,4 +55,10 @@ export class SmbService {
5555
createShare(requestModel: ShareRequestModel) {
5656
return this.http.post(`${this.baseURL}/share`, requestModel);
5757
}
58+
59+
deleteShare(clusterId: string, shareId: string): Observable<HttpResponse<null>> {
60+
return this.http.delete<null>(`${this.baseURL}/share/${clusterId}/${shareId}`, {
61+
observe: 'response'
62+
});
63+
}
5864
}

src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ export class TaskMessageService {
498498
),
499499
'smb/share/create': this.newTaskMessage(this.commonOperations.create, (metadata) =>
500500
this.smbShare(metadata)
501+
),
502+
'smb/share/delete': this.newTaskMessage(this.commonOperations.delete, (metadata) =>
503+
this.smbShare(metadata)
501504
)
502505
};
503506

@@ -565,10 +568,6 @@ export class TaskMessageService {
565568
return $localize`SMB Cluster '${metadata.cluster_id}'`;
566569
}
567570

568-
smbShare(metadata: { share_id: string }) {
569-
return $localize`SMB Share '${metadata.share_id}'`;
570-
}
571-
572571
service(metadata: any) {
573572
return $localize`service '${metadata.service_name}'`;
574573
}
@@ -611,6 +610,11 @@ export class TaskMessageService {
611610
snapshotSchedule(metadata: any) {
612611
return $localize`snapshot schedule for path '${metadata?.path}'`;
613612
}
613+
614+
smbShare(metadata: Record<'share_id', string>) {
615+
return $localize`SMB share '${metadata?.share_id}'`;
616+
}
617+
614618
crudMessageId(id: string) {
615619
return $localize`${id}`;
616620
}

0 commit comments

Comments
 (0)