]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-user-details / rgw-user-details.component.ts
CommitLineData
11fdf7f2
TL
1import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
f67539c2
TL
3import _ from 'lodash';
4
5import { RgwUserService } from '~/app/shared/api/rgw-user.service';
6import { Icons } from '~/app/shared/enum/icons.enum';
7import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
9import { ModalService } from '~/app/shared/services/modal.service';
11fdf7f2
TL
10import { RgwUserS3Key } from '../models/rgw-user-s3-key';
11import { RgwUserSwiftKey } from '../models/rgw-user-swift-key';
12import { RgwUserS3KeyModalComponent } from '../rgw-user-s3-key-modal/rgw-user-s3-key-modal.component';
13import { RgwUserSwiftKeyModalComponent } from '../rgw-user-swift-key-modal/rgw-user-swift-key-modal.component';
14
15@Component({
16 selector: 'cd-rgw-user-details',
17 templateUrl: './rgw-user-details.component.html',
18 styleUrls: ['./rgw-user-details.component.scss']
19})
20export class RgwUserDetailsComponent implements OnChanges, OnInit {
f67539c2 21 @ViewChild('accessKeyTpl')
11fdf7f2 22 public accessKeyTpl: TemplateRef<any>;
f67539c2 23 @ViewChild('secretKeyTpl')
11fdf7f2
TL
24 public secretKeyTpl: TemplateRef<any>;
25
26 @Input()
e306af50 27 selection: any;
11fdf7f2
TL
28
29 // Details tab
30 user: any;
9f95a23c 31 maxBucketsMap: {};
11fdf7f2
TL
32
33 // Keys tab
34 keys: any = [];
35 keysColumns: CdTableColumn[] = [];
36 keysSelection: CdTableSelection = new CdTableSelection();
37
9f95a23c
TL
38 icons = Icons;
39
f67539c2 40 constructor(private rgwUserService: RgwUserService, private modalService: ModalService) {}
11fdf7f2
TL
41
42 ngOnInit() {
43 this.keysColumns = [
44 {
f67539c2 45 name: $localize`Username`,
11fdf7f2
TL
46 prop: 'username',
47 flexGrow: 1
48 },
49 {
f67539c2 50 name: $localize`Type`,
11fdf7f2
TL
51 prop: 'type',
52 flexGrow: 1
53 }
54 ];
9f95a23c 55 this.maxBucketsMap = {
f67539c2
TL
56 '-1': $localize`Disabled`,
57 0: $localize`Unlimited`
9f95a23c 58 };
11fdf7f2
TL
59 }
60
61 ngOnChanges() {
e306af50
TL
62 if (this.selection) {
63 this.user = this.selection;
11fdf7f2
TL
64
65 // Sort subusers and capabilities.
66 this.user.subusers = _.sortBy(this.user.subusers, 'id');
67 this.user.caps = _.sortBy(this.user.caps, 'type');
68
69 // Load the user/bucket quota of the selected user.
70 this.rgwUserService.getQuota(this.user.uid).subscribe((resp: object) => {
71 _.extend(this.user, resp);
72 });
73
74 // Process the keys.
75 this.keys = [];
9f95a23c
TL
76 if (this.user.keys) {
77 this.user.keys.forEach((key: RgwUserS3Key) => {
78 this.keys.push({
79 id: this.keys.length + 1, // Create an unique identifier
80 type: 'S3',
81 username: key.user,
82 ref: key
83 });
11fdf7f2 84 });
9f95a23c
TL
85 }
86 if (this.user.swift_keys) {
87 this.user.swift_keys.forEach((key: RgwUserSwiftKey) => {
88 this.keys.push({
89 id: this.keys.length + 1, // Create an unique identifier
90 type: 'Swift',
91 username: key.user,
92 ref: key
93 });
11fdf7f2 94 });
9f95a23c
TL
95 }
96
11fdf7f2
TL
97 this.keys = _.sortBy(this.keys, 'user');
98 }
99 }
100
101 updateKeysSelection(selection: CdTableSelection) {
102 this.keysSelection = selection;
103 }
104
105 showKeyModal() {
106 const key = this.keysSelection.first();
f67539c2 107 const modalRef = this.modalService.show(
11fdf7f2
TL
108 key.type === 'S3' ? RgwUserS3KeyModalComponent : RgwUserSwiftKeyModalComponent
109 );
110 switch (key.type) {
111 case 'S3':
f67539c2
TL
112 modalRef.componentInstance.setViewing();
113 modalRef.componentInstance.setValues(key.ref.user, key.ref.access_key, key.ref.secret_key);
11fdf7f2
TL
114 break;
115 case 'Swift':
f67539c2 116 modalRef.componentInstance.setValues(key.ref.user, key.ref.secret_key);
11fdf7f2
TL
117 break;
118 }
119 }
120}