Skip to content

Commit

Permalink
Integrating with backend
Browse files Browse the repository at this point in the history
Former-commit-id: 3098d4de3aced709b636caa23a84821e037e4fb6
  • Loading branch information
rmathis committed Aug 10, 2022
1 parent 77e7a40 commit 34b9b93
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 98 deletions.
137 changes: 77 additions & 60 deletions backend/src/main/resources/algorithm-filter.schema.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,82 @@
{
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"title": "label.filter-name",
"description": "tooltip.filter-name",
"type": "string"
},
"filterEnabled": {
"title": "label.enable-filter",
"description": "tooltip.enable-filter",
"type": "boolean",
"default": false
},
"AlgorithmFilterTarget": {
"title": "label.search-criteria",
"description": "tooltip.search-criteria",
"type": "object",
"properties": {
"nameIdFormatFilterTargetType": {
"title": "label.filter-target-type",
"type": "string",
"default": "ENTITY",
"enum": [
"ENTITY",
"CONDITION_REF",
"CONDITION_SCRIPT"
],
"enumNames": [
"value.entity-id",
"value.reference",
"value.script"
]
},
"value": {
"title": "label.filter-target-value",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string"
}
}
},
"required": [
"value",
"algorithmFilterTargetType"
]
},
"@type": {
"type": "string",
"default": "Algorithm"
},
"version": {
"type": "integer"
"type": "object",
"required": ["name"],
"properties": {
"name": {
"title": "label.filter-name",
"description": "tooltip.filter-name",
"type": "string"
},
"filterEnabled": {
"title": "label.enable-filter",
"description": "tooltip.enable-filter",
"type": "boolean",
"default": false
},
"algorithmFilterTarget": {
"title": "label.search-criteria",
"description": "tooltip.search-criteria",
"type": "object",
"properties": {
"algorithmFilterTargetType": {
"title": "label.filter-target-type",
"type": "string",
"default": "ENTITY",
"enum": ["ENTITY", "CONDITION_REF", "CONDITION_SCRIPT"],
"enumNames": ["value.entity-id", "value.reference", "value.script"]
},
"resourceId": {
"value": {
"title": "label.filter-target-value",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string"
}
}
},
"required": ["value", "algorithmFilterTargetType"]
},
"@type": {
"type": "string",
"default": "Algorithm"
},
"version": {
"type": "integer"
},
"resourceId": {
"type": "string"
},
"definitions": {}
}
"algorithms": {
"$ref": "#/definitions/AlgorithmList"
}
},
"definitions": {
"AlgorithmList": {
"title": "label.algorithm",
"description": "tooltip.algorithm",
"type": "array",
"items": {
"type": "string",
"enum": [
"http://www.w3.org/2009/xmlenc11#aes256-gcm",
"http://www.w3.org/2009/xmlenc11#aes192-gcm",
"http://www.w3.org/2009/xmlenc11#aes128-gcm",
"http://www.w3.org/2001/04/xmlenc#aes256-cbc",
"http://www.w3.org/2001/04/xmlenc#aes192-cbc",
"http://www.w3.org/2001/04/xmlenc#aes128-cbc",
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
],
"enumNames": [
"value.algorithm-gcm-256",
"value.algorithm-gcm-192",
"value.algorithm-gcm-128",
"value.algorithm-cbc-256",
"value.algorithm-cbc-192",
"value.algorithm-cbc-128",
"value.algorithm-cbc-tripledes"
]
}
}
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ message.wizard-status=Step { index } of { length }
message.entity-id-min-unique=You must add at least one entity id target and they must each be unique.
message.required-for-scripts=Required for Scripts
message.required-for-regex=Required for Regex
message.required-for-condition-ref=Required for Condition Ref
message.file-doesnt-exist=The requested file to be processed does not exist on the server.
message.database-constraint=There was a database constraint problem processing the request. Check the request to ensure that fields that must be unique are truly unique.

Expand Down
60 changes: 35 additions & 25 deletions ui/public/assets/schema/filter/algorithm.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"title": "label.filter-target-type",
"type": "string",
"default": "ENTITY",
"enum": ["ENTITY", "REGEX", "CONDITION_SCRIPT"],
"enum": ["ENTITY", "CONDITION_REF", "CONDITION_SCRIPT"],
"enumNames": [
"value.entity-id",
"value.regex",
"value.reference",
"value.script"
]
},
Expand All @@ -43,34 +43,44 @@
},
"@type": {
"type": "string",
"default": "NameIDFormat"
"default": "Algorithm"
},
"version": {
"type": "integer"
},
"algorithm": {
"resourceId": {
"type": "string"
},
"algorithms": {
"$ref": "#/definitions/AlgorithmList"
}
},
"definitions": {
"AlgorithmList": {
"title": "label.algorithm",
"description": "tooltip.algorithm",
"type": "string",
"enum": [
"http://www.w3.org/2009/xmlenc11#aes256-gcm",
"http://www.w3.org/2009/xmlenc11#aes192-gcm",
"http://www.w3.org/2009/xmlenc11#aes128-gcm",
"http://www.w3.org/2001/04/xmlenc#aes256-cbc",
"http://www.w3.org/2001/04/xmlenc#aes192-cbc",
"http://www.w3.org/2001/04/xmlenc#aes128-cbc",
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
],
"enumNames": [
"value.algorithm-gcm-256",
"value.algorithm-gcm-192",
"value.algorithm-gcm-128",
"value.algorithm-cbc-256",
"value.algorithm-cbc-192",
"value.algorithm-cbc-128",
"value.algorithm-cbc-tripledes"
]
"type": "array",
"items": {
"type": "string",
"enum": [
"http://www.w3.org/2009/xmlenc11#aes256-gcm",
"http://www.w3.org/2009/xmlenc11#aes192-gcm",
"http://www.w3.org/2009/xmlenc11#aes128-gcm",
"http://www.w3.org/2001/04/xmlenc#aes256-cbc",
"http://www.w3.org/2001/04/xmlenc#aes192-cbc",
"http://www.w3.org/2001/04/xmlenc#aes128-cbc",
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
],
"enumNames": [
"value.algorithm-gcm-256",
"value.algorithm-gcm-192",
"value.algorithm-gcm-128",
"value.algorithm-cbc-256",
"value.algorithm-cbc-192",
"value.algorithm-cbc-128",
"value.algorithm-cbc-tripledes"
]
}
}
},
"definitions": {}
}
}
7 changes: 6 additions & 1 deletion ui/src/app/core/components/ProtectRoute.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { isUndefined } from 'lodash';
import React from 'react';
import { Redirect } from 'react-router-dom';

import { useIsAdmin } from '../user/UserContext';
import { useCurrentUser, useIsAdmin } from '../user/UserContext';

export function ProtectRoute({ children, redirectTo, ...rest }) {
const user = useCurrentUser();
const isAdmin = useIsAdmin();
if (isUndefined(user.role)) {
return <></>
}
return isAdmin ? children : <Redirect to={redirectTo} />;
}
24 changes: 21 additions & 3 deletions ui/src/app/form/component/fields/FilterTargetField.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ const FilterTargetField = ({
};

const selectType = (option) => {
setSelectedTarget([]);
const t = option.value === 'REGEX' || option.value === 'CONDITION_REF' ? [''] : [];
setSelectedTarget(t);
setSelectedType(option);
};

Expand Down Expand Up @@ -240,7 +241,6 @@ const FilterTargetField = ({
{errorSchema?.value?.__errors ?
<small className="form-text text-danger">
{errors}

</small> :
<small id="regex-help" className="form-text text-secondary">
<Translate value="message.required-for-regex">Required for Regex</Translate>
Expand All @@ -249,7 +249,25 @@ const FilterTargetField = ({
}
</>
}

{targetType === 'CONDITION_REF' &&
<>
<input id="targetInput"
className="form-control"
type="text"
name="script"
value={selectedTarget[0]}
onChange={ ({target: { value }}) => handleTextChange(value) } />
{errorSchema?.value?.__errors ?
<small className="form-text text-danger">
{errors}
</small> :
<small id="regex-help" className="form-text text-secondary">
<Translate value="message.required-for-condition-ref">Required for Condition Ref</Translate>
&nbsp;
</small>
}
</>
}
</div>
{targetType === 'ENTITY' &&
<div className="ms-2">
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/metadata/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function Filter() {

const { path, url } = useRouteMatch();

console.log(path, url)

return (
<Switch>
<Route path={`${path}/list`} render={() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import defaultsDeep from "lodash/defaultsDeep";
// import API_BASE_PATH from "../../../../App.constant";
import { BASE_PATH } from '../../../../App.constant';
import API_BASE_PATH from "../../../../App.constant";
import { BaseFilterDefinition } from "./BaseFilterDefinition";

export const AlgorithmFilterWizard = {
Expand All @@ -10,19 +9,16 @@ export const AlgorithmFilterWizard = {
'ui:field': 'FilterTargetField',
api: ''
},
formats: {
algorithms: {
"ui:options": {
orderable: false
},
items: {
'ui:widget': 'OptionWidget'
}
}
}, BaseFilterDefinition.uiSchema),
label: 'Algorithm',
type: 'Algorithm',
// schema: `${API_BASE_PATH}/ui/AlgorithmFilter`,
schema: `${BASE_PATH}assets/schema/filter/algorithm.schema.json`,
schema: `${API_BASE_PATH}/ui/AlgorithmFilter`,
// schema: `${BASE_PATH}assets/schema/filter/algorithm.schema.json`,
steps: [],
validator: (data = [], current = { resourceId: null }, group) => {
return BaseFilterDefinition.validator(data, current, group, 'algorithmFilterTarget', 'algorithmFilterTargetType')
Expand Down Expand Up @@ -54,7 +50,7 @@ export const AlgorithmFilterEditor = {
index: 2,
initialValues: [],
fields: [
'algorithm'
'algorithms'
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export const BaseFilterDefinition = {
errors[targetProp].value.addError('message.required-for-scripts');
}
}

if (formData[targetProp][typeProp] === 'CONDITION_REF') {
const { [targetProp]: { value } } = formData;
if (!value[0]) {
errors[targetProp].value.addError('message.required-for-condition-ref');
}
}
}

return errors;
Expand Down

0 comments on commit 34b9b93

Please sign in to comment.