Skip to content

Commit

Permalink
Merge pull request hashgraph#2170 from hashgraph/fix/1687
Browse files Browse the repository at this point in the history
Fix/1687
  • Loading branch information
artembuslaev authored May 26, 2023
2 parents 2c6541f + 1be51d7 commit 4ce9421
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 328 deletions.
2 changes: 0 additions & 2 deletions api-docs/api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,6 @@ components:
type: boolean
isCreator:
type: boolean
approverRoleFor:
type: string
gridColumns:
type: array
items:
Expand Down
10 changes: 3 additions & 7 deletions api-gateway/src/api/service/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ export class SchemaApi {
const schemas = await createSchema(
newSchema,
user.did,
topicId && ['null', 'undefined', ''].includes(topicId)
? undefined
: topicId
topicId,
);
return res.status(201).json(SchemaUtils.toOld(schemas));
} catch (error) {
Expand All @@ -202,10 +200,8 @@ export class SchemaApi {
await createSchemaAsync(
newSchema,
user.did,
topicId && ['null', 'undefined', ''].includes(topicId)
? undefined
: topicId,
taskId
topicId,
taskId,
);
}, async (error) => {
new Logger().error(error, ['API_GATEWAY']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<mat-icon class="delete-icon delete-policy-role-icon">delete</mat-icon>
</div>
</div>

<div class="policy-roles-add-container">
<mat-form-field class="full-width" appearance="outline">
<mat-label>* NAME:</mat-label>
Expand Down Expand Up @@ -87,7 +86,6 @@
<mat-option *ngFor="let role of policyRolesForm.value" [value]="role">{{role}}</mat-option>
</mat-select>
</mat-form-field>

<div class="form-field-info">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Produced schema:</mat-label>
Expand All @@ -103,15 +101,13 @@
<img [src]="'/assets/produced-schema.gif'" class="help-img">
</mat-menu>
</div>

<mat-form-field appearance="outline">
<mat-label>Relationship schema:</mat-label>
<mat-select formControlName="relationshipsSchemaIri">
<mat-option></mat-option>
<mat-option *ngFor="let schema of selectedSchemas" [value]="schema.iri">{{schema.name}}</mat-option>
</mat-select>
</mat-form-field>

<div class="form-field-info">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Initial for roles:</mat-label>
Expand All @@ -126,14 +122,12 @@
<img [src]="'/assets/initial-step.gif'" class="help-img">
</mat-menu>
</div>

<ng-container *ngTemplateOutlet="infoBtn; context: {
formControl : control.get('isApproveEnable'),
helpSrc: '/assets/approve.gif',
title: 'Approve and reject functionality',
visible: true}">
</ng-container>

<mat-slide-toggle class="slide-toggle" [formControl]="control.get('isMintSchema')" labelPosition="after"
color="primary">
Minting tokens
Expand Down Expand Up @@ -166,24 +160,14 @@
title: 'Is approver?',
visible: approveEnable}">
</ng-container>

<mat-form-field appearance="outline" class="full-width"
*ngIf="control.get('isApprover').value && initialSchemaFor.length">
<mat-label>Approver for initial step of roles:</mat-label>
<mat-select formControlName="approverRoleFor">
<mat-option></mat-option>
<mat-option *ngFor="let role of initialSchemaFor" [value]="role">{{role}}</mat-option>
</mat-select>
</mat-form-field>

<mat-slide-toggle class="slide-toggle" [formControl]="control.get('isCreator')" labelPosition="after"
color="primary">
Is creator?
</mat-slide-toggle>

<ng-container *ngTemplateOutlet="infoBtn; context: {
formControl : control.get('isCreator'),
helpSrc: '/assets/create.gif',
title: 'Is creator?',
visible: true}">
</ng-container>
<ng-container
*ngTemplateOutlet="roleGridColumns; context: {gridColumns: control.get('gridColumns')?.value , fields, approveEnable, dependencySchema }"></ng-container>

<ng-template #roleGridColumns let-gridColumns="gridColumns" let-fields="fields">
<h2 class="grid-columns-title">Grid Columns</h2>
<div class="grid-columns-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,28 @@ export class PolicyWizardDialogComponent implements OnInit {
schemas: groupedSchemasByTopic[policy?.topicId],
},
{
name: 'Ungrouped schemas',
schemas: groupedSchemasByTopic[''],
name: 'Draft schemas',
schemas: groupedSchemasByTopic['draft'],
},
]
: [
{
name: 'Ungrouped schemas',
schemas: groupedSchemasByTopic[''],
name: 'Draft schemas',
schemas: groupedSchemasByTopic['draft'],
},
];
for (const group of Object.entries(groupedSchemasByTopic)) {
if (group[0] && group[0] !== policy?.topicId) {
if (
group[0] &&
group[0] !== 'draft' &&
group[0] !== policy?.topicId
) {
const policy = policies.find(
(policy) => policy.topicId === group[0]
);
if (!policy) {
continue;
}
mappedSchemas.push({
name:
policy.name +
Expand Down Expand Up @@ -405,7 +412,6 @@ export class PolicyWizardDialogComponent implements OnInit {
role: [role],
isApprover: [false],
isCreator: [false],
approverRoleFor: [],
gridColumns: [[]],
});
schemaRoleConfigControl.push(schemaRoleConfigForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,11 @@ export class PoliciesComponent implements OnInit, OnDestroy {
forkJoin([
this.tokenService.getTokens(),
this.schemaService.getSchemas(),
this.policyEngineService.all(),
]).subscribe((result) => {
const schemas = result[1].map((schema) => new Schema(schema));
const tokens = result[0].map((token) => new Token(token));
this.loading = false;
const schemas = result[1].map((schema) => new Schema(schema));
const policies = result[2];
this.wizardService.openPolicyWizardDialog(
WizardMode.CREATE,
(value) => {
Expand All @@ -651,8 +652,8 @@ export class PoliciesComponent implements OnInit, OnDestroy {
},
tokens,
schemas,
this.policies as any[]
policies
);
});
}, () => undefined, () => this.loading = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export class PolicyConfigurationComponent implements OnInit {
public currentBlock!: PolicyBlockModel | undefined;

public schemas!: Schema[];
public allSchemas!: Schema[];
public allPolicies!: any[];
public tokens!: Token[];
public errors: any[] = [];
public errorsCount: number = -1;
Expand Down Expand Up @@ -212,13 +210,6 @@ export class PolicyConfigurationComponent implements OnInit {
}, (error) => {
console.error(error);
});

this.schemaService.getSchemas().subscribe(value => {
this.allSchemas = value.map((schema) => new Schema(schema));
});
this.policyEngineService.all().subscribe(value => {
this.allPolicies = value;
})
}

public select(name: string) {
Expand Down Expand Up @@ -1186,55 +1177,58 @@ export class PolicyConfigurationComponent implements OnInit {
}

public openPolicyWizardDialog() {
this.wizardService.openPolicyWizardDialog(
WizardMode.EDIT,
(value) => {
if (value.create) {
this.loading = true;
this.wizardService
.getPolicyConfig(this.policyId, value.config)
.subscribe((result) => {
this.loading = false;
this.policyModel.setPolicyInfo(
value.config.policy
);
const roles = value.config.roles;
const policy = this.policyModel.getJSON();
policy.policyRoles = roles.filter(
(role: string) => role !== 'OWNER'
);
policy.config = result.policyConfig;
this.updatePolicyModel(policy);
if (value.saveState) {
this.wizardService.setWizardPreset(
this.policyId,
{
data: result?.wizardConfig,
currentNode: value?.currentNode,
}
this.loading = true;
forkJoin([
this.tokenService.getTokens(),
this.schemaService.getSchemas(),
this.policyEngineService.all(),
]).subscribe((result) => {
const tokens = result[0].map((token) => new Token(token));
const schemas = result[1].map((schema) => new Schema(schema));
const policies = result[2];
this.wizardService.openPolicyWizardDialog(
WizardMode.EDIT,
(value) => {
if (value.create) {
this.loading = true;
this.wizardService
.getPolicyConfig(this.policyId, value.config)
.subscribe((result) => {
this.loading = false;
this.policyModel.setPolicyInfo(
value.config.policy
);
}
this.schemaService
.getSchemas()
.subscribe((value) => {
this.allSchemas = value.map(
(schema) => new Schema(schema)
const roles = value.config.roles;
const policy = this.policyModel.getJSON();
policy.policyRoles = roles.filter(
(role: string) => role !== 'OWNER'
);
policy.config = result.policyConfig;
this.updatePolicyModel(policy);
if (value.saveState) {
this.wizardService.setWizardPreset(
this.policyId,
{
data: result?.wizardConfig,
currentNode: value?.currentNode,
}
);
});
}
});
} else if (value.saveState) {
this.wizardService.setWizardPreset(this.policyId, {
data: value.config,
currentNode: value.currentNode,
});
} else if (value.saveState) {
this.wizardService.setWizardPreset(this.policyId, {
data: value.config,
currentNode: value.currentNode,
});
} else {
this.wizardService.removeWizardPreset(this.policyId);
}
},
this.tokens,
this.allSchemas,
this.allPolicies,
this.policyModel
);
} else {
this.wizardService.removeWizardPreset(this.policyId);
}
},
tokens,
schemas,
policies,
this.policyModel
);
}, () => undefined, () => this.loading = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
</mat-form-field>

<div class="optional-row">
<mat-form-field *ngIf="isPolicy" appearance="outline" [attr.disabled]="type=='version' || !!value?.topicId">
<mat-label>Policy</mat-label>
<mat-form-field *ngIf="isPolicy" appearance="outline"
[attr.disabled]="type=='version' || (value?.topicId && (value?.topicId !== 'draft'))">
<mat-label>* Policy</mat-label>
<mat-select formControlName="topicId" tabindex='-1' (selectionChange)="onFilter($event)">
<mat-option>Empty</mat-option>
<mat-option [value]="'draft'">Draft</mat-option>
<mat-option *ngFor="let policy of policies" [value]="policy.topicId">{{policy.name}}</mat-option>
</mat-select>
</mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class SchemaConfigurationComponent implements OnInit {
props = {
name: ['', Validators.required],
description: [''],
topicId: [this.topicId],
topicId: [this.topicId, Validators.required],
entity: new FormControl(SchemaEntity.VC, Validators.required),
fields: this.fieldsForm,
conditions: this.conditionsForm
Expand All @@ -271,10 +271,10 @@ export class SchemaConfigurationComponent implements OnInit {
this.updateSubSchemas(topicId);
}

updateSubSchemas(topicId: any) {
updateSubSchemas(topicId: string | null) {
this.schemaTypes = [];
if (this.schemasMap) {
this.schemas = this.schemasMap[topicId || '']
if (this.schemasMap && topicId) {
this.schemas = this.schemasMap[topicId]
?.filter(s => {
if (this.value?.document?.$id) {
const isInDefs = Object.keys(s.document?.$defs || {})
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/app/views/schemas/schemas.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<mat-label>Policy</mat-label>
<mat-select [(value)]="currentTopicPolicy" (selectionChange)="onFilter()">
<mat-option value="">All policies</mat-option>
<mat-option value="draft">Draft</mat-option>
<mat-option *ngFor="let policy of policies" [value]="policy.topicId">
<span>{{policy.name}}</span>
<span> ({{policy.topicId}})</span>
Expand Down Expand Up @@ -67,7 +68,12 @@
<ng-container matColumnDef="topic">
<th mat-header-cell *matHeaderCellDef> Topic </th>
<td mat-cell *matCellDef="let element">
<hedera-explorer type="topics" [params]="element.topicId">{{element.topicId}}</hedera-explorer>
<ng-container *ngIf="element.topicId === 'draft'; else topicExplorer">
<span>Draft</span>
</ng-container>
<ng-template #topicExplorer>
<hedera-explorer type="topics" [params]="element.topicId">{{element.topicId}}</hedera-explorer>
</ng-template>
</td>
</ng-container>
<ng-container matColumnDef="version">
Expand Down
Loading

0 comments on commit 4ce9421

Please sign in to comment.