From c5dfb16de77c7458cec39276bcba4f2ca9251ec5 Mon Sep 17 00:00:00 2001 From: Naman Munet Date: Wed, 8 Jan 2025 13:11:58 +0530 Subject: [PATCH] mgr/dashboard: Delete account integrated Fixes: https://tracker.ceph.com/issues/69140 Signed-off-by: Naman Munet --- .../rgw-user-accounts.component.html | 2 +- .../rgw-user-accounts.component.ts | 55 ++++++++++++++++++- .../shared/api/rgw-user-accounts.service.ts | 4 ++ .../shared/services/task-message.service.ts | 3 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.html index bddb749b466..ab53cd71baa 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.html @@ -10,8 +10,8 @@ [autoReload]="false" [data]="accounts" [columns]="columns" + selectionType="single" columnMode="flex" - selectionType="multiClick" [hasDetails]="true" (setExpandedRow)="setExpandedRow($event)" (updateSelection)="updateSelection($event)" diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.ts index 0ad449761c1..a4195530286 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-accounts/rgw-user-accounts.component.ts @@ -14,6 +14,11 @@ import { URLBuilderService } from '~/app/shared/services/url-builder.service'; import { Icons } from '~/app/shared/enum/icons.enum'; import { Router } from '@angular/router'; import { ListWithDetails } from '~/app/shared/classes/list-with-details.class'; +import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component'; +import { ModalCdsService } from '~/app/shared/services/modal-cds.service'; +import { Observable, Subscriber, forkJoin as observableForkJoin } from 'rxjs'; +import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; +import { FinishedTask } from '~/app/shared/models/finished-task'; const BASE_URL = 'rgw/accounts'; @@ -36,7 +41,9 @@ export class RgwUserAccountsComponent extends ListWithDetails implements OnInit private authStorageService: AuthStorageService, public actionLabels: ActionLabelsI18n, private router: Router, - private rgwUserAccountsService: RgwUserAccountsService + private rgwUserAccountsService: RgwUserAccountsService, + private cdsModalService: ModalCdsService, + private taskWrapper: TaskWrapperService ) { super(); } @@ -110,7 +117,13 @@ export class RgwUserAccountsComponent extends ListWithDetails implements OnInit click: () => this.router.navigate([`${BASE_URL}/${getEditURL()}`]), name: this.actionLabels.EDIT }; - this.tableActions = [addAction, editAction]; + const deleteAction: CdTableAction = { + permission: 'delete', + icon: Icons.destroy, + click: () => this.deleteAction(), + name: this.actionLabels.DELETE + }; + this.tableActions = [addAction, editAction, deleteAction]; } getAccountsList(context?: CdTableFetchDataContext) { @@ -129,4 +142,42 @@ export class RgwUserAccountsComponent extends ListWithDetails implements OnInit updateSelection(selection: CdTableSelection) { this.selection = selection; } + + deleteAction() { + const account_name = this.selection.first().name; + this.cdsModalService.show(CriticalConfirmationModalComponent, { + itemDescription: $localize`Account`, + itemNames: [account_name], + submitActionObservable: () => { + return new Observable((observer: Subscriber) => { + this.taskWrapper + .wrapTaskAroundCall({ + task: new FinishedTask(BASE_URL, { + account_names: [account_name] + }), + call: observableForkJoin( + this.selection.selected.map((account: Account) => { + return this.rgwUserAccountsService.remove(account.id); + }) + ) + }) + .subscribe({ + error: (error: any) => { + // Forward the error to the observer. + observer.error(error); + // Reload the data table content because some deletions might + // have been executed successfully in the meanwhile. + this.table.refreshBtn(); + }, + complete: () => { + // Notify the observer that we are done. + observer.complete(); + // Reload the data table content. + this.table.refreshBtn(); + } + }); + }); + } + }); + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user-accounts.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user-accounts.service.ts index af53724d47d..bd407357c61 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user-accounts.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user-accounts.service.ts @@ -34,6 +34,10 @@ export class RgwUserAccountsService { return this.http.put(`${this.url}/set`, payload); } + remove(accountId: string) { + return this.http.delete(`${this.url}/${accountId}`); + } + setQuota( account_id: string, payload: { quota_type: string; max_size: string; max_objects: string; enabled: boolean } 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 cf7662eac65..4813af4fb4f 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 @@ -324,6 +324,9 @@ export class TaskMessageService { metadata.bucket_names.length > 1 ? 'selected buckets' : metadata.bucket_names[0] }`; }), + 'rgw/accounts': this.newTaskMessage(this.commonOperations.delete, (metadata) => { + return $localize`${`account '${metadata.account_names[0]}'`}`; + }), 'rgw/multisite/sync-policy/delete': this.newTaskMessage( this.commonOperations.delete, (metadata) => { -- 2.39.5