]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-user-list / rgw-user-list.component.ts
CommitLineData
f67539c2 1import { Component, NgZone, OnInit, TemplateRef, ViewChild } from '@angular/core';
11fdf7f2 2
11fdf7f2
TL
3import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
4
f67539c2
TL
5import { RgwUserService } from '~/app/shared/api/rgw-user.service';
6import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
f67539c2
TL
7import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
8import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9import { TableComponent } from '~/app/shared/datatable/table/table.component';
10import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
11import { Icons } from '~/app/shared/enum/icons.enum';
12import { CdTableAction } from '~/app/shared/models/cd-table-action';
13import { CdTableColumn } from '~/app/shared/models/cd-table-column';
14import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
15import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
16import { Permission } from '~/app/shared/models/permissions';
17import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
18import { ModalService } from '~/app/shared/services/modal.service';
19import { URLBuilderService } from '~/app/shared/services/url-builder.service';
11fdf7f2
TL
20
21const BASE_URL = 'rgw/user';
22
23@Component({
24 selector: 'cd-rgw-user-list',
25 templateUrl: './rgw-user-list.component.html',
26 styleUrls: ['./rgw-user-list.component.scss'],
27 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
28})
f67539c2 29export class RgwUserListComponent extends ListWithDetails implements OnInit {
9f95a23c 30 @ViewChild(TableComponent, { static: true })
11fdf7f2 31 table: TableComponent;
f67539c2
TL
32 @ViewChild('userSizeTpl', { static: true })
33 userSizeTpl: TemplateRef<any>;
34 @ViewChild('userObjectTpl', { static: true })
35 userObjectTpl: TemplateRef<any>;
11fdf7f2
TL
36 permission: Permission;
37 tableActions: CdTableAction[];
38 columns: CdTableColumn[] = [];
39 users: object[] = [];
40 selection: CdTableSelection = new CdTableSelection();
aee94f69 41 declare staleTimeout: number;
11fdf7f2
TL
42
43 constructor(
44 private authStorageService: AuthStorageService,
45 private rgwUserService: RgwUserService,
f67539c2 46 private modalService: ModalService,
11fdf7f2 47 private urlBuilder: URLBuilderService,
1911f103 48 public actionLabels: ActionLabelsI18n,
522d829b 49 protected ngZone: NgZone
11fdf7f2 50 ) {
522d829b 51 super(ngZone);
f67539c2
TL
52 }
53
54 ngOnInit() {
11fdf7f2
TL
55 this.permission = this.authStorageService.getPermissions().rgw;
56 this.columns = [
57 {
f67539c2 58 name: $localize`Username`,
11fdf7f2
TL
59 prop: 'uid',
60 flexGrow: 1
61 },
62 {
f67539c2
TL
63 name: $localize`Tenant`,
64 prop: 'tenant',
65 flexGrow: 1
66 },
67 {
68 name: $localize`Full name`,
11fdf7f2
TL
69 prop: 'display_name',
70 flexGrow: 1
71 },
72 {
f67539c2 73 name: $localize`Email address`,
11fdf7f2
TL
74 prop: 'email',
75 flexGrow: 1
76 },
77 {
f67539c2 78 name: $localize`Suspended`,
11fdf7f2
TL
79 prop: 'suspended',
80 flexGrow: 1,
81 cellClass: 'text-center',
82 cellTransformation: CellTemplate.checkIcon
83 },
84 {
f67539c2 85 name: $localize`Max. buckets`,
11fdf7f2 86 prop: 'max_buckets',
9f95a23c
TL
87 flexGrow: 1,
88 cellTransformation: CellTemplate.map,
89 customTemplateConfig: {
f67539c2
TL
90 '-1': $localize`Disabled`,
91 0: $localize`Unlimited`
9f95a23c 92 }
f67539c2
TL
93 },
94 {
95 name: $localize`Capacity Limit %`,
96 prop: 'size_usage',
97 cellTemplate: this.userSizeTpl,
98 flexGrow: 0.8
99 },
100 {
101 name: $localize`Object Limit %`,
102 prop: 'object_usage',
103 cellTemplate: this.userObjectTpl,
104 flexGrow: 0.8
11fdf7f2
TL
105 }
106 ];
107 const getUserUri = () =>
108 this.selection.first() && `${encodeURIComponent(this.selection.first().uid)}`;
109 const addAction: CdTableAction = {
110 permission: 'create',
9f95a23c 111 icon: Icons.add,
11fdf7f2 112 routerLink: () => this.urlBuilder.getCreate(),
9f95a23c
TL
113 name: this.actionLabels.CREATE,
114 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
11fdf7f2
TL
115 };
116 const editAction: CdTableAction = {
117 permission: 'update',
9f95a23c 118 icon: Icons.edit,
11fdf7f2
TL
119 routerLink: () => this.urlBuilder.getEdit(getUserUri()),
120 name: this.actionLabels.EDIT
121 };
122 const deleteAction: CdTableAction = {
123 permission: 'delete',
9f95a23c 124 icon: Icons.destroy,
11fdf7f2 125 click: () => this.deleteAction(),
9f95a23c
TL
126 disable: () => !this.selection.hasSelection,
127 name: this.actionLabels.DELETE,
128 canBePrimary: (selection: CdTableSelection) => selection.hasMultiSelection
11fdf7f2
TL
129 };
130 this.tableActions = [addAction, editAction, deleteAction];
522d829b 131 this.setTableRefreshTimeout();
11fdf7f2
TL
132 }
133
134 getUserList(context: CdTableFetchDataContext) {
522d829b 135 this.setTableRefreshTimeout();
11fdf7f2
TL
136 this.rgwUserService.list().subscribe(
137 (resp: object[]) => {
138 this.users = resp;
139 },
140 () => {
141 context.error();
142 }
143 );
144 }
145
146 updateSelection(selection: CdTableSelection) {
147 this.selection = selection;
148 }
149
150 deleteAction() {
f67539c2
TL
151 this.modalService.show(CriticalConfirmationModalComponent, {
152 itemDescription: this.selection.hasSingleSelection ? $localize`user` : $localize`users`,
153 itemNames: this.selection.selected.map((user: any) => user['uid']),
154 submitActionObservable: (): Observable<any> => {
155 return new Observable((observer: Subscriber<any>) => {
156 // Delete all selected data table rows.
157 observableForkJoin(
158 this.selection.selected.map((user: any) => {
159 return this.rgwUserService.delete(user.uid);
160 })
161 ).subscribe({
162 error: (error) => {
163 // Forward the error to the observer.
164 observer.error(error);
165 // Reload the data table content because some deletions might
166 // have been executed successfully in the meanwhile.
167 this.table.refreshBtn();
168 },
169 complete: () => {
170 // Notify the observer that we are done.
171 observer.complete();
172 // Reload the data table content.
173 this.table.refreshBtn();
174 }
11fdf7f2 175 });
f67539c2 176 });
11fdf7f2
TL
177 }
178 });
179 }
180}