Skip to content

Commit b5bae52

Browse files
weandReamer
authored andcommitted
extend credential ui angular
1 parent 14e490e commit b5bae52

File tree

7 files changed

+194
-13
lines changed

7 files changed

+194
-13
lines changed

zeppelin-web-angular/src/app/interfaces/credential.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
*/
1212

1313
export interface Credential {
14-
userCredentials: {
15-
[key: string]: CredentialItem;
16-
};
14+
[key: string]: CredentialItem;
1715
}
1816

1917
export interface CredentialItem {
2018
username: string;
2119
password: string;
20+
readers: string[];
21+
owners: string[];
2222
}
2323

2424
export interface CredentialForm {
2525
entity: string;
2626
password: string;
2727
username: string;
28+
readers: string[];
29+
owners: string[];
2830
}

zeppelin-web-angular/src/app/pages/workspace/credential/credential.component.html

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
<h2>Add new credential</h2>
4242
<form nz-form nzLayout="inline" [formGroup]="addForm" (ngSubmit)="submitForm()">
4343
<div nz-row>
44-
<div nz-col [nzSpan]="16">
44+
<div nz-col [nzSpan]="20">
4545
<nz-form-item>
4646
<nz-form-label>Entity</nz-form-label>
4747
<nz-form-control nzErrorTip="Please input entity!">
4848
<input [nzAutocomplete]="auto"
4949
(input)="onEntityInput($event)"
5050
formControlName="entity"
5151
nz-input
52-
placeholder="Interpreter Name"/>
52+
placeholder="Credential entity (e.g. Interpreter Name)"/>
5353
<nz-autocomplete nzBackfill #auto>
5454
<nz-auto-option *ngFor="let option of interpreterFilteredNames" [nzValue]="option">
5555
{{ option }}
@@ -69,8 +69,30 @@ <h2>Add new credential</h2>
6969
<input formControlName="password" nz-input type="password" placeholder="Password"/>
7070
</nz-form-control>
7171
</nz-form-item>
72+
<nz-form-item>
73+
<nz-form-label>Owners</nz-form-label>
74+
<nz-form-control>
75+
<zeppelin-credential-permission-select
76+
mode="edit"
77+
reference="AddFormOwners"
78+
[permission]="{ items: addForm.get('owners').value }"
79+
(permissionsBack)="addForm.patchValue({owners: $event})">
80+
</zeppelin-credential-permission-select>
81+
</nz-form-control>
82+
</nz-form-item>
83+
<nz-form-item>
84+
<nz-form-label>Readers</nz-form-label>
85+
<nz-form-control>
86+
<zeppelin-credential-permission-select
87+
mode="edit"
88+
reference="AddFormReaders"
89+
[permission]="{ items: addForm.get('readers').value }"
90+
(permissionsBack)="addForm.patchValue({readers: $event})">
91+
</zeppelin-credential-permission-select>
92+
</nz-form-control>
93+
</nz-form-item>
7294
</div>
73-
<div class="new-actions" nz-col [nzSpan]="8">
95+
<div class="new-actions" nz-col [nzSpan]="4">
7496
<nz-form-item>
7597
<nz-form-control>
7698
<button nz-button nzType="primary" [disabled]="!addForm.valid || adding">Save</button>
@@ -92,6 +114,8 @@ <h2>Add new credential</h2>
92114
<th>Entity</th>
93115
<th>Username</th>
94116
<th>Password</th>
117+
<th>Owners</th>
118+
<th>Readers</th>
95119
<th nzWidth="225px" class="actions-head">Actions</th>
96120
</tr>
97121
</thead>
@@ -103,6 +127,22 @@ <h2>Add new credential</h2>
103127
<ng-container *ngIf="isEditing(control); else credentialDisplay">
104128
<td><input nz-input formControlName="username"></td>
105129
<td><input nz-input type="password" formControlName="password"></td>
130+
<td>
131+
<zeppelin-credential-permission-select
132+
mode="edit"
133+
[reference]="entity + 'Owners'"
134+
[permission]="{ items: control.get('owners')?.value }"
135+
(permissionsBack)="permissionSelect(control, 'owners', $event)">
136+
</zeppelin-credential-permission-select>
137+
</td>
138+
<td>
139+
<zeppelin-credential-permission-select
140+
mode="edit"
141+
[reference]="entity + 'Readers'"
142+
[permission]="{ items: control.get('readers')?.value }"
143+
(permissionsBack)="permissionSelect(control, 'readers', $event)">
144+
</zeppelin-credential-permission-select>
145+
</td>
106146
<td class="credential-actions">
107147
<button nz-button nzType="primary" (click)="saveCredential(control)"><i nz-icon nzType="save"
108148
nzTheme="outline"></i> Save
@@ -115,6 +155,20 @@ <h2>Add new credential</h2>
115155
<ng-template #credentialDisplay>
116156
<td>{{control.get('username')?.value}}</td>
117157
<td><strong>**********</strong></td>
158+
<td>
159+
<zeppelin-credential-permission-select
160+
mode="view"
161+
[reference]="entity + 'Owners'"
162+
[permission]="{ items: control.get('owners')?.value }">
163+
</zeppelin-credential-permission-select>
164+
</td>
165+
<td>
166+
<zeppelin-credential-permission-select
167+
mode="view"
168+
[reference]="entity + 'Readers'"
169+
[permission]="{ items: control.get('readers')?.value }">
170+
</zeppelin-credential-permission-select>
171+
</td>
118172
<td class="credential-actions">
119173
<button nz-button (click)="setEditable(control)"><i nz-icon nzType="edit" nzTheme="outline"></i> Edit
120174
</button>

zeppelin-web-angular/src/app/pages/workspace/credential/credential.component.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { NzMessageService } from 'ng-zorro-antd/message';
1717

1818
import { finalize } from 'rxjs/operators';
1919

20-
import { CredentialForm } from '@zeppelin/interfaces';
20+
import { CredentialForm, ITicket } from '@zeppelin/interfaces';
2121
import { CredentialService, InterpreterService, TicketService } from '@zeppelin/services';
2222

2323
@Component({
@@ -36,6 +36,7 @@ export class CredentialComponent implements OnInit {
3636
editFlags: Map<string, CredentialForm> = new Map();
3737
credentialFormArray: FormArray = this.fb.array([]);
3838
docsLink: string;
39+
defaultOwners: string[];
3940

4041
get credentialControls(): FormGroup[] {
4142
return this.credentialFormArray.controls as FormGroup[];
@@ -140,13 +141,15 @@ export class CredentialComponent implements OnInit {
140141

141142
getCredentials() {
142143
this.credentialService.getCredentials().subscribe(data => {
143-
const controls = [...Object.entries(data.userCredentials)].map(e => {
144+
const controls = [...Object.entries(data)].map(e => {
144145
const entity = e[0];
145-
const { username, password } = e[1];
146+
const { username, password, owners, readers } = e[1];
146147
return this.fb.group({
147148
entity: [entity, [Validators.required]],
148149
username: [username, [Validators.required]],
149-
password: [password, [Validators.required]]
150+
password: [password, [Validators.required]],
151+
owners: [owners, []],
152+
readers: [readers, []]
150153
});
151154
});
152155
this.credentialFormArray = this.fb.array(controls);
@@ -185,18 +188,30 @@ export class CredentialComponent implements OnInit {
185188
this.addForm.reset({
186189
entity: null,
187190
username: null,
188-
password: null
191+
password: null,
192+
owners: this.defaultOwners,
193+
readers: []
189194
});
190195
this.cdr.markForCheck();
191196
}
192197

198+
permissionSelect(form: FormGroup, field: string, value: string[]) {
199+
const obj = {};
200+
obj[field] = value;
201+
form.patchValue(obj);
202+
}
203+
193204
ngOnInit(): void {
194205
this.getCredentials();
195206
this.getInterpreterNames();
207+
const ticket = this.ticketService.originTicket;
208+
this.defaultOwners = ticket.ticket === 'anonymous' ? [] : [ticket.principal];
196209
this.addForm = this.fb.group({
197210
entity: [null, [Validators.required]],
198211
username: [null, [Validators.required]],
199-
password: [null, [Validators.required]]
212+
password: [null, [Validators.required]],
213+
owners: [this.defaultOwners, []],
214+
readers: [[], []]
200215
});
201216
}
202217
}

zeppelin-web-angular/src/app/pages/workspace/credential/credential.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import { NzIconModule } from 'ng-zorro-antd/icon';
2424
import { NzInputModule } from 'ng-zorro-antd/input';
2525
import { NzMessageModule } from 'ng-zorro-antd/message';
2626
import { NzPopconfirmModule } from 'ng-zorro-antd/popconfirm';
27+
import { NzSelectModule } from 'ng-zorro-antd/select';
2728
import { NzTableModule } from 'ng-zorro-antd/table';
2829
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
2930
import { CredentialRoutingModule } from './credential-routing.module';
3031
import { CredentialComponent } from './credential.component';
32+
import { CredentialPermissionSelectComponent } from './permissions/permissions.component';
3133

3234
@NgModule({
33-
declarations: [CredentialComponent],
35+
declarations: [CredentialComponent, CredentialPermissionSelectComponent],
3436
imports: [
3537
CommonModule,
3638
CredentialRoutingModule,
@@ -44,6 +46,7 @@ import { CredentialComponent } from './credential.component';
4446
NzIconModule,
4547
NzDividerModule,
4648
NzInputModule,
49+
NzSelectModule,
4750
NzMessageModule,
4851
NzTableModule,
4952
NzPopconfirmModule,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
~ Licensed under the Apache License, Version 2.0 (the "License");
3+
~ you may not use this file except in compliance with the License.
4+
~ You may obtain a copy of the License at
5+
~ http://www.apache.org/licenses/LICENSE-2.0
6+
~ Unless required by applicable law or agreed to in writing, software
7+
~ distributed under the License is distributed on an "AS IS" BASIS,
8+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
~ See the License for the specific language governing permissions and
10+
~ limitations under the License.
11+
-->
12+
13+
<nz-select
14+
nzSize="small"
15+
[(ngModel)]="permission.items"
16+
nzServerSearch
17+
(nzOnSearch)="searchUser($event)"
18+
nzMode="tags"
19+
style="width: 100%;"
20+
nzPlaceHolder=""
21+
nzAllowClear
22+
[name]="reference"
23+
[nzDisabled]="mode === 'view'"
24+
(ngModelChange)="onChange()">
25+
<nz-option *ngFor="let item of permission.items" [nzLabel]="item" [nzValue]="item"></nz-option>
26+
<nz-option-group [nzLabel]="item.text" *ngFor="let item of listOfUserAndRole">
27+
<nz-option *ngFor="let o of item.children" [nzLabel]="o" [nzValue]="o"></nz-option>
28+
</nz-option-group>
29+
</nz-select>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
* Unless required by applicable law or agreed to in writing, software
7+
* distributed under the License is distributed on an "AS IS" BASIS,
8+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
* See the License for the specific language governing permissions and
10+
* limitations under the License.
11+
*/
12+
13+
@import "theme-mixin";
14+
15+
.themeMixin({
16+
17+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
* Unless required by applicable law or agreed to in writing, software
7+
* distributed under the License is distributed on an "AS IS" BASIS,
8+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
* See the License for the specific language governing permissions and
10+
* limitations under the License.
11+
*/
12+
13+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
14+
15+
import { DestroyHookComponent } from '@zeppelin/core';
16+
import { SecurityService } from '@zeppelin/services';
17+
18+
@Component({
19+
selector: 'zeppelin-credential-permission-select',
20+
templateUrl: './permissions.component.html',
21+
styleUrls: ['./permissions.component.less'],
22+
changeDetection: ChangeDetectionStrategy.OnPush
23+
})
24+
export class CredentialPermissionSelectComponent extends DestroyHookComponent {
25+
@Input() reference: string;
26+
@Input() permission: { items: string[] };
27+
@Input() mode: 'create' | 'view' | 'edit' = 'view';
28+
@Output() readonly permissionsBack = new EventEmitter<string[]>();
29+
listOfUserAndRole = [];
30+
31+
searchUser(search: string) {
32+
if (!search) {
33+
return;
34+
}
35+
this.securityService.searchUsers(search).subscribe(data => {
36+
const results = [];
37+
if (data.users.length) {
38+
results.push({
39+
text: 'Users :',
40+
children: data.users
41+
});
42+
}
43+
if (data.roles.length) {
44+
results.push({
45+
text: 'Roles :',
46+
children: data.roles
47+
});
48+
}
49+
this.listOfUserAndRole = results;
50+
this.cdr.markForCheck();
51+
});
52+
}
53+
54+
onChange() {
55+
this.permissionsBack.emit(this.permission.items);
56+
}
57+
58+
constructor(private securityService: SecurityService, private cdr: ChangeDetectorRef) {
59+
super();
60+
}
61+
}

0 commit comments

Comments
 (0)