1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2 import { catchError, switchMap } from 'rxjs/operators';
3 import { BehaviorSubject, Observable, of } from 'rxjs';
5 import _ from 'lodash';
7 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
8 import { CdTableAction } from '~/app/shared/models/cd-table-action';
9 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
10 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
11 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
12 import { Permission } from '~/app/shared/models/permissions';
14 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
15 import { SmbService } from '~/app/shared/api/smb.service';
16 import { SMBUsersGroups } from '../smb.model';
17 import { Router } from '@angular/router';
18 import { Icons } from '~/app/shared/enum/icons.enum';
19 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
20 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
21 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
22 import { FinishedTask } from '~/app/shared/models/finished-task';
23 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
24 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
26 export const USERSGROUPS_PATH = 'cephfs/smb/standalone';
29 selector: 'cd-smb-users-list',
30 templateUrl: './smb-usersgroups-list.component.html',
31 styleUrls: ['./smb-usersgroups-list.component.scss'],
32 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(USERSGROUPS_PATH) }]
34 export class SmbUsersgroupsListComponent extends ListWithDetails implements OnInit {
35 @ViewChild('groupsNamesTpl', { static: true })
36 groupsNamesTpl: TemplateRef<any>;
37 columns: CdTableColumn[];
38 permission: Permission;
39 tableActions: CdTableAction[];
40 context: CdTableFetchDataContext;
42 usersGroups$: Observable<SMBUsersGroups[]>;
43 subject$ = new BehaviorSubject<SMBUsersGroups[]>([]);
44 selection: CdTableSelection = new CdTableSelection();
47 private router: Router,
48 private urlBuilder: URLBuilderService,
49 private authStorageService: AuthStorageService,
50 public actionLabels: ActionLabelsI18n,
51 private smbService: SmbService,
52 private modalService: ModalCdsService,
53 private taskWrapper: TaskWrapperService
56 this.permission = this.authStorageService.getPermissions().smb;
62 name: $localize`Name`,
63 prop: 'users_groups_id',
67 name: $localize`Number of users`,
68 prop: 'values.users.length',
72 name: $localize`Groups`,
73 prop: 'values.groups',
74 cellTemplate: this.groupsNamesTpl,
78 name: $localize`Linked to cluster`,
79 prop: 'values.linked_to_cluster',
86 name: `${this.actionLabels.CREATE} standalone`,
89 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
90 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
93 name: this.actionLabels.EDIT,
97 this.router.navigate([
98 this.urlBuilder.getEdit(String(this.selection.first().users_groups_id))
102 name: this.actionLabels.DELETE,
103 permission: 'delete',
105 click: () => this.openDeleteModal()
109 this.usersGroups$ = this.subject$.pipe(
111 this.smbService.listUsersGroups().pipe(
113 this.context.error();
122 this.subject$.next([]);
126 const usersGroupsId = this.selection.first().users_groups_id;
128 this.modalService.show(DeleteConfirmationModalComponent, {
129 itemDescription: $localize`Users and groups access resource`,
130 itemNames: [usersGroupsId],
131 submitActionObservable: () =>
132 this.taskWrapper.wrapTaskAroundCall({
133 task: new FinishedTask(`${USERSGROUPS_PATH}/${URLVerbs.DELETE}`, {
134 usersGroupsId: usersGroupsId
136 call: this.smbService.deleteUsersgroups(usersGroupsId)
141 updateSelection(selection: CdTableSelection) {
142 this.selection = selection;