Skip to content

Commit

Permalink
Merge pull request hashgraph#2184 from hashgraph/feature/block-deprec…
Browse files Browse the repository at this point in the history
…ation

Feature/block deprecation
  • Loading branch information
artembuslaev authored May 26, 2023
2 parents 4ce9421 + 6f4c8a6 commit 4478e0d
Show file tree
Hide file tree
Showing 27 changed files with 465 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ComparePolicyComponent implements OnInit {
"aggregateDocumentBlock": "calendar_month",
"reassigningBlock": "content_copy",
"revokeBlock": "restart_alt",
"revocationBlock": "restart_alt",
"setRelationshipsBlock": "settings",
"splitBlock": "content_cut",
"filtersAddon": "filter_alt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
<span class="readonly-prop">{{about.children}}</span>
</td>
</tr>
<tr class="propRow" [attr.collapse]="propHidden.about">
<td class="propRowCol"></td>
<td class="propRowCell cellName">Deprecated</td>
<td class="propRowCell">
<span class="readonly-prop">{{about.deprecated?'Yes':'No'}}</span>
</td>
</tr>
</ng-container>

<tr class="propHeader">
Expand Down Expand Up @@ -169,11 +176,11 @@
<td class="propHeaderCell"></td>
</tr>
<div *ngFor="let property of customProperties" common-property class="custom-properties"
[block]="currentBlock"
[data]="block.properties"
[property]="property"
[block]="currentBlock"
[data]="block.properties"
[property]="property"
[readonly]="readonly"
[collapse]="propHidden.customProperties"
[collapse]="propHidden.customProperties"
(update)="onSave()">
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ export class PolicyConfigurationComponent implements OnInit {
this.componentsList.unGrouped = [];
const search = this.search ? this.search.toLowerCase() : null;
for (const block of all) {
if (search && block.search.indexOf(search) === -1) {
if (
(search && block.search.indexOf(search) === -1) ||
block?.deprecated
) {
continue;
}
if (block.header === 'UI Components') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,23 @@
grid-template-columns: auto 1px !important;
}

.block-container[deprecated="true"] .block-item {
background-color: lightgray !important;
border-color: lightgray !important;
}

.block-container[deprecated="true"] .block-item::after {
content: "";
width: 110%;
height: 3px;
background-color: black;
position: absolute;
left: -5%;
}

.block-container[selected="true"][deprecated="true"] .block-item {
border-color: #5161e1 !important;
}

.cdk-drag-animating {
transition: transform 50ms cubic-bezier(0, 0, 0.2, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[attr.collapsed]="item.collapsed" [attr.selected]="isSelect(item)" [attr.error]="item.error"
[attr.root]="item.root" [attr.block-id]="item.id" [attr.block-instance]="item.node.tag"
[attr.block-type]="item.type" [style.paddingLeft]="item.offset" cdkDrag [cdkDragData]="item.level"
[cdkDragDisabled]="item.root">
[cdkDragDisabled]="item.root" [attr.deprecated]="item.deprecated">
<div class="block-expand" (click)="onCollapse($event, item)">
<mat-icon>arrow_drop_down</mat-icon>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class PolicyTreeComponent implements OnInit {
node.level = level;
node.root = block === this.root;
node.expandable = block.expandable && !node.root;
node.deprecated = this.registeredService.getDeprecated(block.blockType);
node.about = this.registeredService.getAbout(block, this.module);
node.icon = this.registeredService.getIcon(block.blockType);
node.type = this.registeredService.getHeader(block.blockType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const Container: IBlockSetting = {
{ type: BlockType.CustomLogicBlock },
{ type: BlockType.Report },
{ type: BlockType.RevokeBlock },
{ type: BlockType.RevocationBlock },
{ type: BlockType.SetRelationshipsBlock },
{ type: BlockType.ButtonBlock },
{ type: BlockType.TokenActionBlock },
Expand Down Expand Up @@ -124,6 +125,7 @@ const Step: IBlockSetting = {
{ type: BlockType.CustomLogicBlock },
{ type: BlockType.Report },
{ type: BlockType.RevokeBlock },
{ type: BlockType.RevocationBlock },
{ type: BlockType.SetRelationshipsBlock },
{ type: BlockType.ButtonBlock },
{ type: BlockType.TokenActionBlock },
Expand Down Expand Up @@ -378,6 +380,15 @@ const RevokeBlock: IBlockSetting = {
property: RevokeConfigComponent,
}

const RevocationBlock: IBlockSetting = {
type: BlockType.RevocationBlock,
icon: 'restart_alt',
group: BlockGroup.Documents,
header: BlockHeaders.ServerBlocks,
factory: null,
property: null,
}

const SetRelationshipsBlock: IBlockSetting = {
type: BlockType.SetRelationshipsBlock,
icon: 'settings',
Expand Down Expand Up @@ -625,6 +636,7 @@ export default [
AggregateDocument,
ReassigningBlock,
RevokeBlock,
RevocationBlock,
SetRelationshipsBlock,
SplitBlock,
FiltersAddon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Module: IBlockSetting = {
{ type: BlockType.CustomLogicBlock },
{ type: BlockType.Report },
{ type: BlockType.RevokeBlock },
{ type: BlockType.RevocationBlock },
{ type: BlockType.SetRelationshipsBlock },
{ type: BlockType.ButtonBlock },
{ type: BlockType.TokenActionBlock },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class RegisteredService {

private blockName: { [type: string]: string };
private blockTitle: { [type: string]: string };
private blockDeprecation: { [type: string]: boolean };
private blockAbout: { [type: string]: BlockAbout };
private blockProperties: { [type: string]: BlockAbout };

Expand All @@ -38,14 +39,16 @@ export class RegisteredService {
this.blockTitle = {};
this.blockAbout = {};
this.blockProperties = {};
this.blockDeprecation = {};
this.defaultAbout = new BlockAbout({
post: false,
get: false,
input: null,
output: null,
children: ChildrenType.None,
control: ControlType.None,
defaultEvent: false
defaultEvent: false,
deprecated: false,
})

for (const config of blocks) {
Expand Down Expand Up @@ -103,6 +106,7 @@ export class RegisteredService {
this.blockTitle[type] = setting.title;
this.blockAbout[type] = new BlockAbout(setting, this.about[type]);
this.blockProperties[type] = setting.properties;
this.blockDeprecation[type] = !!setting.deprecated;
}
this.update();
}
Expand All @@ -119,7 +123,8 @@ export class RegisteredService {
group: this.group[type],
header: this.header[type],
title: this.blockTitle[type],
data: `new:${type}`
data: `new:${type}`,
deprecated: this.blockDeprecation[type],
});
}
this.list = this.list.sort((a, b) => a.name > b.name ? 1 : -1);
Expand Down Expand Up @@ -181,4 +186,8 @@ export class RegisteredService {
public getHeader(blockType: string): string {
return this.header[blockType] || '';
}
}

public getDeprecated(blockType: string): boolean {
return this.blockDeprecation[blockType];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface IBlockAboutConfig {
children: ChildrenType;
control: ControlType;
defaultEvent: boolean;
deprecated?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface IBlockAbout {
defaultEvent: boolean;
prev?: IBlockAbout;
next?: boolean;
deprecated?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface IBlockDynamicAboutConfig {
children?: ConfigFunction<ChildrenType>;
control?: ConfigFunction<ControlType>;
defaultEvent?: ConfigFunction<boolean>;
deprecated?: ConfigFunction<boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class BlockAbout {
this._setProp(about, dynamic, 'children');
this._setProp(about, dynamic, 'control');
this._setProp(about, dynamic, 'defaultEvent');
this._setProp(about, dynamic, 'deprecated');
}

public getAbout(
Expand All @@ -48,6 +49,7 @@ export class BlockAbout {
children: this._propFunc.children(this._propVal.children, block, module),
control: this._propFunc.control(this._propVal.control, block, module),
defaultEvent: this._propFunc.defaultEvent(this._propVal.defaultEvent, block, module),
deprecated: this._propFunc.deprecated(this._propVal.deprecated, block, module),
};
}

Expand Down Expand Up @@ -81,6 +83,9 @@ export class BlockAbout {
get defaultEvent() {
return this._func.defaultEvent(this._val.defaultEvent, this._block, this._module);
},
get deprecated() {
return this._func.defaultEvent(this._val.deprecated, this._block, this._module);
},
set module(value: PolicyModel | PolicyModuleModel) {
this._module = value;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class FlatBlockNode {
public parentNode!: FlatBlockNode;
public data!: any;
public error!: boolean;
public deprecated!: boolean;

constructor(node: PolicyBlockModel) {
this.node = node;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/modules/policy-engine/themes/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const defaultTheme = {
'reassigningBlock',
'httpRequestBlock',
'revokeBlock',
'revocationBlock',
'sendToGuardianBlock',
'setRelationshipsBlock',
'splitBlock',
Expand Down
35 changes: 34 additions & 1 deletion guardian-service/src/policy-engine/block-about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ export const BlockAbout = {
'revokeBlock': {
'label': 'Revoke Document',
'title': 'Add \'Revoke\' Block',
'post': true,
'get': true,
'children': 'None',
'control': 'Server',
'input': [
'RunEvent'
],
'output': [
'RunEvent',
'ErrorEvent'
],
'defaultEvent': true,
'deprecated': true,
},
'revocationBlock': {
'label': 'Revocation',
'title': 'Add \'Revocation\' Block',
'post': false,
'get': false,
'children': 'None',
Expand All @@ -505,7 +522,23 @@ export const BlockAbout = {
'RunEvent',
'ErrorEvent'
],
'defaultEvent': true
'defaultEvent': true,
'properties': [
{
'name': 'updatePrevDoc',
'label': 'Update previous document status',
'title': 'Update previous document status',
'type': 'Checkbox',
'default': false
},
{
'name': 'prevDocStatus',
'label': 'Status value',
'title': 'Status value',
'type': 'Input',
'default': ''
},
],
},
'setRelationshipsBlock': {
'label': 'Set Relationships',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ReportItemBlock } from './blocks/report-item-block';
import { RequestVcDocumentBlock } from './blocks/request-vc-document-block';
import { RetirementBlock } from './blocks/retirement-block';
import { RevokeBlock } from './blocks/revoke-block';
import { RevocationBlock } from './blocks/revocation-block';
import { SelectiveAttributes } from './blocks/selective-attributes-addon';
import { SendToGuardianBlock } from './blocks/send-to-guardian-block';
import { SetRelationshipsBlock } from './blocks/set-relationships-block';
Expand Down Expand Up @@ -75,6 +76,7 @@ export const validators = [
RequestVcDocumentBlock,
RetirementBlock,
RevokeBlock,
RevocationBlock,
SelectiveAttributes,
SendToGuardianBlock,
SetRelationshipsBlock,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { BlockValidator, IBlockProp } from '@policy-engine/block-validators';

/**
* Revoke document action with UI
*/
export class RevocationBlock {
/**
* Block type
*/
public static readonly blockType: string = 'revocationBlock';

/**
* Validate block options
* @param validator
* @param config
*/
public static async validate(
validator: BlockValidator,
ref: IBlockProp
): Promise<void> {
try {
if (ref.options.updatePrevDoc && !ref.options.prevDocStatus) {
validator.addError('Option "Status Value" is not set');
}
} catch (error) {
validator.addError(
`Unhandled exception ${validator.getErrorMessage(error)}`
);
}
}
}
10 changes: 7 additions & 3 deletions guardian-service/src/policy-engine/policy-converter-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Policy } from '@guardian/common';
import { GenerateUUIDv4, UserType } from '@guardian/interfaces';
import { EventActor, EventConfig, PolicyInputEventType, PolicyOutputEventType } from './interfaces';
import { BlockType, GenerateUUIDv4, UserType } from '@guardian/interfaces';
import { EventConfig, PolicyInputEventType, PolicyOutputEventType, EventActor } from './interfaces';

/**
* Policy converter utils
Expand Down Expand Up @@ -390,7 +390,7 @@ export class PolicyConverterUtils {
const currentBlock = stack.pop();
if (
currentBlock?.blockType ===
'interfaceDocumentsSourceBlock' &&
BlockType.DocumentsViewer &&
Array.isArray(currentBlock.uiMetaData?.fields)
) {
currentBlock.uiMetaData.fields =
Expand All @@ -404,6 +404,10 @@ export class PolicyConverterUtils {
}
};
clearOldRevokeColumns(root, block.tag);
block.blockType = BlockType.RevocationBlock;
block.updatePrevDoc = block.uiMetaData.updatePrevDoc;
block.prevDocStatus = block.uiMetaData.prevDocStatus;
delete block.uiMetaData;
return block;
}
}
1 change: 1 addition & 0 deletions interfaces/src/type/block.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum BlockType {
CustomLogicBlock = 'customLogicBlock',
Switch = 'switchBlock',
RevokeBlock = 'revokeBlock',
RevocationBlock = 'revocationBlock',
SetRelationshipsBlock = 'setRelationshipsBlock',
ButtonBlock = 'buttonBlock',
TokenActionBlock = 'tokenActionBlock',
Expand Down
Loading

0 comments on commit 4478e0d

Please sign in to comment.