]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
6cc47f165a8593d4883e02bc6dda7190c727f956
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { Observable, BehaviorSubject, of } from 'rxjs';
3 import { switchMap, catchError } from 'rxjs/operators';
4 import { SmbService } from '~/app/shared/api/smb.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { CdTableAction } from '~/app/shared/models/cd-table-action';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
9 import { Permission } from '~/app/shared/models/permissions';
10 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11 import { SMBJoinAuth } from '../smb.model';
12 import { Router } from '@angular/router';
13 import { Icons } from '~/app/shared/enum/icons.enum';
14 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
15 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
16 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
17 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
18 import { FinishedTask } from '~/app/shared/models/finished-task';
19 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
20
21 export const JOINAUTH_URL = '/cephfs/smb/ad';
22
23 @Component({
24   selector: 'cd-smb-join-auth-list',
25   templateUrl: './smb-join-auth-list.component.html',
26   styleUrls: ['./smb-join-auth-list.component.scss'],
27   providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(JOINAUTH_URL) }]
28 })
29 export class SmbJoinAuthListComponent implements OnInit {
30   columns: CdTableColumn[];
31   permission: Permission;
32   tableActions: CdTableAction[];
33   context: CdTableFetchDataContext;
34
35   joinAuth$: Observable<SMBJoinAuth[]>;
36   subject$ = new BehaviorSubject<SMBJoinAuth[]>([]);
37   selection: CdTableSelection = new CdTableSelection();
38
39   constructor(
40     private router: Router,
41     private urlBuilder: URLBuilderService,
42     private authStorageService: AuthStorageService,
43     public actionLabels: ActionLabelsI18n,
44     private smbService: SmbService,
45     private modalService: ModalCdsService,
46     private taskWrapper: TaskWrapperService
47   ) {
48     this.permission = this.authStorageService.getPermissions().smb;
49   }
50
51   ngOnInit() {
52     this.columns = [
53       {
54         name: $localize`Name`,
55         prop: 'auth_id',
56         flexGrow: 2
57       },
58       {
59         name: $localize`Username`,
60         prop: 'auth.username',
61         flexGrow: 2
62       },
63       {
64         name: $localize`Linked to cluster`,
65         prop: 'linked_to_cluster',
66         flexGrow: 2
67       }
68     ];
69
70     this.tableActions = [
71       {
72         name: `${this.actionLabels.CREATE} AD`,
73         permission: 'create',
74         icon: Icons.add,
75         click: () => this.router.navigate([this.urlBuilder.getCreate()]),
76         canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
77       },
78       {
79         name: this.actionLabels.EDIT,
80         permission: 'update',
81         icon: Icons.edit,
82         click: () =>
83           this.router.navigate([this.urlBuilder.getEdit(String(this.selection.first().auth_id))])
84       },
85       {
86         name: this.actionLabels.DELETE,
87         permission: 'update',
88         icon: Icons.destroy,
89         click: () => this.openDeleteModal()
90       }
91     ];
92
93     this.joinAuth$ = this.subject$.pipe(
94       switchMap(() =>
95         this.smbService.listJoinAuths().pipe(
96           catchError(() => {
97             this.context.error();
98             return of(null);
99           })
100         )
101       )
102     );
103   }
104
105   loadJoinAuth() {
106     this.subject$.next([]);
107   }
108
109   openDeleteModal() {
110     const authId = this.selection.first().auth_id;
111
112     this.modalService.show(DeleteConfirmationModalComponent, {
113       itemDescription: $localize`Active directory access resource`,
114       itemNames: [authId],
115       submitActionObservable: () =>
116         this.taskWrapper.wrapTaskAroundCall({
117           task: new FinishedTask('smb/ad/remove', {
118             authId: authId
119           }),
120           call: this.smbService.deleteJoinAuth(authId)
121         })
122     });
123   }
124
125   updateSelection(selection: CdTableSelection) {
126     this.selection = selection;
127   }
128 }