Compare commits
2 Commits
2bde8b850a
...
0987affccc
Author | SHA1 | Date | |
---|---|---|---|
0987affccc | |||
44df0daddf |
@ -9,7 +9,7 @@
|
|||||||
<mat-label>User to impersonate</mat-label>
|
<mat-label>User to impersonate</mat-label>
|
||||||
<mat-select (selectionChange)="onChange($event)" [(value)]="impersonated">
|
<mat-select (selectionChange)="onChange($event)" [(value)]="impersonated">
|
||||||
<mat-option>{{getUsername()}}</mat-option>
|
<mat-option>{{getUsername()}}</mat-option>
|
||||||
@for (user of users; track user) {
|
@for (user of users; track user.id) {
|
||||||
<mat-option [value]="user.id">{{ user.name }}</mat-option>
|
<mat-option [value]="user.id">{{ user.name }}</mat-option>
|
||||||
}
|
}
|
||||||
</mat-select>
|
</mat-select>
|
||||||
|
@ -36,7 +36,7 @@ export class ImpersonationComponent implements OnInit {
|
|||||||
}).subscribe((data: any) => {
|
}).subscribe((data: any) => {
|
||||||
this.users = data.filter((d: any) => d.name != this.auth.getUsername());
|
this.users = data.filter((d: any) => d.name != this.auth.getUsername());
|
||||||
const id = this.auth.getImpersonatedId();
|
const id = this.auth.getImpersonatedId();
|
||||||
if (this.users.find(u => u.id == id)) {
|
if (id && this.users.find(u => u.id == id)) {
|
||||||
this.impersonated = id;
|
this.impersonated = id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
<table mat-table [dataSource]="policies" class="mat-elevation-z8">
|
<table mat-table [dataSource]="policies" class="mat-elevation-z8">
|
||||||
|
|
||||||
<!--- Note that these columns can be defined in any order.
|
|
||||||
The actual rendered columns are set as a property on the row definition" -->
|
|
||||||
|
|
||||||
<!-- Position Column -->
|
|
||||||
<ng-container matColumnDef="path">
|
<ng-container matColumnDef="path">
|
||||||
<th mat-header-cell *matHeaderCellDef>Path</th>
|
<th mat-header-cell *matHeaderCellDef>Path</th>
|
||||||
<td mat-cell *matCellDef="let policy">
|
<td mat-cell *matCellDef="let policy">
|
||||||
@ -17,13 +12,12 @@
|
|||||||
@if (policy.editing) {
|
@if (policy.editing) {
|
||||||
<input type="text" [(ngModel)]="policy.temp_group_name" />
|
<input type="text" [(ngModel)]="policy.temp_group_name" />
|
||||||
}
|
}
|
||||||
@if (!policy.editing) {
|
@if (!policy.editing && groups[policy.group_id]) {
|
||||||
{{groups[policy.group_id].name}}
|
{{groups[policy.group_id].name}}
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Name Column -->
|
|
||||||
<ng-container matColumnDef="usage">
|
<ng-container matColumnDef="usage">
|
||||||
<th mat-header-cell *matHeaderCellDef>Usage per span</th>
|
<th mat-header-cell *matHeaderCellDef>Usage per span</th>
|
||||||
<td mat-cell *matCellDef="let policy">
|
<td mat-cell *matCellDef="let policy">
|
||||||
@ -36,7 +30,6 @@
|
|||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Weight Column -->
|
|
||||||
<ng-container matColumnDef="span">
|
<ng-container matColumnDef="span">
|
||||||
<th mat-header-cell *matHeaderCellDef>Span (ms)</th>
|
<th mat-header-cell *matHeaderCellDef>Span (ms)</th>
|
||||||
<td mat-cell *matCellDef="let policy">
|
<td mat-cell *matCellDef="let policy">
|
||||||
@ -49,7 +42,6 @@
|
|||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Symbol Column -->
|
|
||||||
<ng-container matColumnDef="actions">
|
<ng-container matColumnDef="actions">
|
||||||
<th mat-header-cell *matHeaderCellDef> Actions </th>
|
<th mat-header-cell *matHeaderCellDef> Actions </th>
|
||||||
<td mat-cell *matCellDef="let policy">
|
<td mat-cell *matCellDef="let policy">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, ElementRef, Input, isDevMode, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { MatTable, MatTableModule } from '@angular/material/table';
|
import { MatTable, MatTableModule } from '@angular/material/table';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import EventService from '../shared/services/EventService';
|
import EventService from '../shared/services/EventService';
|
||||||
@ -44,6 +44,8 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
for (let policy of response.data) {
|
for (let policy of response.data) {
|
||||||
this.policies.push(new Policy(policy.id, policy.group_id, policy.path, policy.usage, policy.span, "", false, false));
|
this.policies.push(new Policy(policy.id, policy.group_id, policy.path, policy.usage, policy.span, "", false, false));
|
||||||
}
|
}
|
||||||
|
if (isDevMode())
|
||||||
|
console.log('policies', this.policies);
|
||||||
this.table.renderRows();
|
this.table.renderRows();
|
||||||
} else if (response.request.type == "create_policy") {
|
} else if (response.request.type == "create_policy") {
|
||||||
console.log("create policy", response);
|
console.log("create policy", response);
|
||||||
@ -83,6 +85,7 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
} else if (response.request.type == "get_permissions") {
|
} else if (response.request.type == "get_permissions") {
|
||||||
this.groups = Object.assign({}, ...response.data.groups.map((g: any) => ({ [g.id]: g })));
|
this.groups = Object.assign({}, ...response.data.groups.map((g: any) => ({ [g.id]: g })));
|
||||||
|
console.log('groups', response.data)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.hermes.fetchPolicies();
|
this.hermes.fetchPolicies();
|
||||||
@ -98,13 +101,21 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
if (!policy.editing)
|
if (!policy.editing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
policy.path = policy.old_path ?? '';
|
if (policy.isNew) {
|
||||||
policy.usage = policy.old_usage ?? 1;
|
const index = this.policies.indexOf(policy);
|
||||||
policy.span = policy.old_span ?? 5000;
|
if (index >= 0) {
|
||||||
policy.old_path = undefined;
|
this.policies.splice(index, 1);
|
||||||
policy.old_span = undefined;
|
this.table.renderRows();
|
||||||
policy.old_usage = undefined;
|
}
|
||||||
policy.editing = false;
|
} else {
|
||||||
|
policy.path = policy.old_path ?? '';
|
||||||
|
policy.usage = policy.old_usage ?? 1;
|
||||||
|
policy.span = policy.old_span ?? 5000;
|
||||||
|
policy.old_path = undefined;
|
||||||
|
policy.old_span = undefined;
|
||||||
|
policy.old_usage = undefined;
|
||||||
|
policy.editing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(policy: Policy) {
|
delete(policy: Policy) {
|
||||||
@ -124,12 +135,20 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
console.log('group must be valid.');
|
console.log('group must be valid.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const group = Object.values(this.groups).find(g => g.name);
|
const group = Object.values(this.groups).find(g => g.name == policy.temp_group_name);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
console.log('group does not exist.');
|
console.log('group does not exist.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (policy.isNew) {
|
||||||
|
const match = this.policies.find(p => p.group_id == group.id && p.path == policy.path);
|
||||||
|
if (match) {
|
||||||
|
console.log('policy already exists');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isNaN(policy.usage)) {
|
if (isNaN(policy.usage)) {
|
||||||
console.log('usage must be a whole number.');
|
console.log('usage must be a whole number.');
|
||||||
return;
|
return;
|
||||||
@ -156,18 +175,6 @@ export class PolicyTableComponent implements OnInit, OnDestroy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let group_id = policy?.group_id;
|
|
||||||
for (let groupId in this.groups) {
|
|
||||||
if (this.groups[groupId].name == policy?.temp_group_name) {
|
|
||||||
group_id = groupId;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (policy?.temp_group_name != this.groups[group_id].name) {
|
|
||||||
console.log('no group found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (policy.isNew) {
|
if (policy.isNew) {
|
||||||
this.hermes.createPolicy(group.id, policy.path, policy.usage, policy.span);
|
this.hermes.createPolicy(group.id, policy.path, policy.usage, policy.span);
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,11 +25,11 @@ export class ApiAuthenticationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getImpersonatedId() {
|
getImpersonatedId() {
|
||||||
return this.user.impersonation.id;
|
return this.user.impersonation?.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
getUsername() {
|
getUsername() {
|
||||||
return this.user.name;
|
return this.user?.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
|
Loading…
Reference in New Issue
Block a user