Skip to content

Commit

Permalink
Adding filter list
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Apr 28, 2021
1 parent 29b8ba5 commit 6f3ec2f
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 107 deletions.
5 changes: 5 additions & 0 deletions ui/src/app/App.constant.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export const API_BASE_PATH = 'api';

export const FILTER_PLUGIN_TYPES = ['RequiredValidUntil', 'SignatureValidation', 'EntityRoleWhiteList'];



export default API_BASE_PATH;
11 changes: 11 additions & 0 deletions ui/src/app/core/utility/is_valid_regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function isValidRegex(pattern) {
if (!pattern) {
return false;
}
try {
new RegExp(pattern);
} catch (err) {
return false;
}
return true;
};
23 changes: 23 additions & 0 deletions ui/src/app/core/utility/remove_null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function checkByType(value) {
switch (typeof value) {
case 'object': {
return Object.keys(value).filter(k => !!value[k]).length > 0;
}
default: {
return true;
}
}
}

export function removeNull(attribute, discardObjects = false) {
if (!attribute) { return {}; }
let removed = Object.keys(attribute).reduce((coll, val, index) => {
if (attribute[val] !== null) {
if (!discardObjects || checkByType(attribute[val])) {
coll[val] = attribute[val];
}
}
return coll;
}, {});
return removed;
}
10 changes: 3 additions & 7 deletions ui/src/app/dashboard/component/Ordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import last from 'lodash/last';
import API_BASE_PATH from '../../App.constant';
import { array_move } from '../../core/utility/array_move';

const orderPaths = {
provider: `/MetadataResolversPositionOrder`
};

export const getId = (entity) => {
return entity.resourceId ? entity.resourceId : entity.id;
};
Expand All @@ -24,7 +20,7 @@ export const mergeOrderFn = (entities, order) => {
return ordered;
};

export function Ordered ({type = 'provider', entities, children}) {
export function Ordered ({path = '/MetadataResolvers', entities, children}) {

const orderEntities = (orderById, list) => {
setOrdered(mergeOrderFn(list, orderById));
Expand All @@ -41,7 +37,7 @@ export function Ordered ({type = 'provider', entities, children}) {
const [lastId, setLastId] = React.useState(null);

async function changeOrder(resourceIds) {
await post(`${orderPaths[type]}`, {
await post(path, {
resourceIds
});
if (response.ok) {
Expand All @@ -62,7 +58,7 @@ export function Ordered ({type = 'provider', entities, children}) {
};

async function loadOrder () {
const o = await get(`${orderPaths[type]}`);
const o = await get(path);
if (response.ok) {
const ids = o.resourceIds;
setOrder(ids);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/dashboard/container/ProvidersTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function ProvidersTab () {
</span>
</div>
<div className="p-3">
<Ordered type="provider" entities={providers}>
<Ordered entities={providers}>
{(ordered, first, last, onOrderUp, onOrderDown) =>
<Search entities={ordered} searchable={searchProps}>
{(searched) => <ProviderList
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/metadata/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export function Metadata () {

return (
<MetadataSelector>
{(entity) =>
<MetadataXmlLoader>
<MetadataSchema>
<MetadataSchema entity={ entity }>
<Switch>
<Route path={`${path}/configuration/options`} render={ () =>
<MetadataDetail>
Expand All @@ -37,6 +38,7 @@ export function Metadata () {
</Switch>
</MetadataSchema>
</MetadataXmlLoader>
}
</MetadataSelector>
);
}
11 changes: 6 additions & 5 deletions ui/src/app/metadata/component/MetadataOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { MetadataConfiguration } from './MetadataConfiguration';
import { useMetadataConfiguration } from '../hooks/configuration';
import { MetadataViewToggle } from './MetadataViewToggle';
import { DeleteSourceConfirmation } from '../domain/source/component/DeleteSourceConfirmation';
import { MetadataFilters } from '../domain/filter/component/MetadataFilters';
import { MetadataFilterConfigurationList } from '../domain/filter/component/MetadataFilterConfigurationList';
import { MetadataFilterTypes } from '../domain/filter';

export function MetadataOptions () {

Expand Down Expand Up @@ -87,11 +90,9 @@ export function MetadataOptions () {
</Link>
</div>
</div>
{/*<filter-configuration-list
(onUpdateOrderDown)="updateOrderDown($event)"
(onUpdateOrderUp)="updateOrderUp($event)"
(onRemove)="removeFilter($event)"
[filters]="filters$ | async"></filter-configuration-list>*/}
<MetadataFilters providerId={metadata.resourceId} types={MetadataFilterTypes}>
<MetadataFilterConfigurationList provider={metadata} />
</MetadataFilters>
</>
}
</div>
Expand Down
6 changes: 2 additions & 4 deletions ui/src/app/metadata/component/properties/ObjectProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { ArrayProperty } from './ArrayProperty';
import Translate from '../../../i18n/components/translate';

export function ObjectProperty ({ property, columns, onPreview }) {


const getProperty = (prop, idx) => {
switch(prop.type) {
case 'array':
return <ArrayProperty key={ `p-${idx}` } property={prop} columns={columns} />
case 'object':
return <React.Fragment key={`p-${idx}`}>
{prop.name && <h5 class="border-bottom py-2 mb-0 mt-3"><Translate value={ prop.name } /></h5>}
{prop.name && <h5 className="border-bottom py-2 mb-0 mt-3"><Translate value={ prop.name } /></h5>}
<ObjectProperty property={prop} columns={columns} onPreview={ onPreview } />
</React.Fragment>
default:
Expand All @@ -32,7 +30,7 @@ export function ObjectProperty ({ property, columns, onPreview }) {
<array-property *ngSwitchCase="'array'" [property]="prop" [columns]="columns"></array-property>
<ng-container *ngSwitchCase="'object'">
<ng-container *ngIf="!prop.widget || !prop.widget.id || prop.widget.id !=='filter-target'">
<h5 class="border-bottom py-2 mb-0 mt-3" *ngIf="prop.name">{{ prop.name | translate }}</h5>
<h5 className="border-bottom py-2 mb-0 mt-3" *ngIf="prop.name">{{ prop.name | translate }}</h5>
<object-property [property]="prop" [columns]="columns"></object-property>
</ng-container>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/component/properties/PropertyValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function PropertyValue ({ name, value, columns }) {

return (
<>
{ name && value && value !== false ?
{ name && value !== null && value !== undefined ?
<>
<span
id={`Popover-${id}`}
Expand Down
109 changes: 109 additions & 0 deletions ui/src/app/metadata/domain/filter/EntityAttributesFilterDefinition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import API_BASE_PATH from "../../../App.constant";

import {removeNull} from '../../../core/utility/remove_null';
import { isValidRegex } from '../../../core/utility/is_valid_regex';

export const EntityAttributesFilterWizard= {
label: 'EntityAttributes',
type: 'EntityAttributes',
schema: `${API_BASE_PATH}/ui/EntityAttributesFilters`,
//validatorParams: [getFilterNames],
getValidators(namesList) {
const validators = {
'/': (value, property, form_current) => {
let errors;
// iterate all customer
Object.keys(value).forEach((key) => {
const item = value[key];
const validatorKey = `/${key}`;
const validator = validators.hasOwnProperty(validatorKey) ? validators[validatorKey] : null;
const error = validator ? validator(item, { path: `/${key}` }, form_current) : null;
if (error && error.invalidate) {
errors = errors || [];
errors.push(error);
}
});
return errors;
},
'/name': (value, property, form) => {
const err = namesList.indexOf(value) > -1 ? {
code: 'INVALID_NAME',
path: `#${property.path}`,
message: 'message.name-must-be-unique',
params: [value],
invalidate: true
} : null;
return err;
},
'/relyingPartyOverrides': (value, property, form) => {
if (!value.signAssertion && value.dontSignResponse) {
return {
code: 'INVALID_SIGNING',
path: `#${property.path}`,
message: 'message.invalid-signing',
params: [value],
invalidate: false
};
}
return null;
},
'/entityAttributesFilterTarget': (value, property, form) => {
if (!form || !form.value || !form.value.entityAttributesFilterTarget ||
form.value.entityAttributesFilterTarget.entityAttributesFilterTargetType !== 'REGEX') {
return null;
}
return isValidRegex(value.value[0]) ? null : {
code: 'INVALID_REGEX',
path: `#${property.path}`,
message: 'message.invalid-regex-pattern',
params: [value.value[0]],
invalidate: true
};
},
};
return validators;
},
parser: (changes) => {
return {
...changes,
relyingPartyOverrides: removeNull(changes)
};
},
formatter: (changes) => changes
};


export const EntityAttributesFilterEditor= {
...EntityAttributesFilterWizard,
steps: [
{
id: 'common',
label: 'label.target',
index: 1,
fields: [
'name',
'@type',
'resourceId',
'filterEnabled',
'entityAttributesFilterTarget'
]
},
{
id: 'options',
label: 'label.options',
index: 2,
initialValues: [],
fields: [
'relyingPartyOverrides'
]
},
{
id: 'attributes',
label: 'label.attributes',
index: 3,
fields: [
'attributeRelease'
]
}
]
};
81 changes: 81 additions & 0 deletions ui/src/app/metadata/domain/filter/NameIdFilterDefinition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import API_BASE_PATH from "../../../App.constant";
import { isValidRegex } from "../../../core/utility/is_valid_regex";

export const NameIDFilterWizard = {
label: 'NameIDFormat',
type: 'NameIDFormat',
schema: `${API_BASE_PATH}/ui/NameIdFormatFilter`,
steps: [],
//validatorParams: [getFilterNames],
getValidators(namesList) {
const validators = {
'/': (value, property, form_current) => {
let errors;
// iterate all customer
Object.keys(value).forEach((key) => {
const item = value[key];
const validatorKey = `/${key}`;
const validator = validators.hasOwnProperty(validatorKey) ? validators[validatorKey] : null;
const error = validator ? validator(item, { path: `/${key}` }, form_current) : null;
if (error) {
errors = errors || [];
errors.push(error);
}
});
return errors;
},
'/name': (value, property, form) => {
const err = namesList.indexOf(value) > -1 ? {
code: 'INVALID_NAME',
path: `#${property.path}`,
message: 'message.name-must-be-unique',
params: [value]
} : null;
return err;
},
'/nameIdFormatFilterTarget': (value, property, form) => {
if (!form || !form.value || !form.value.nameIdFormatFilterTarget ||
form.value.nameIdFormatFilterTarget.nameIdFormatFilterTargetType !== 'REGEX') {
return null;
}
return isValidRegex(value.value[0]) ? null : {
code: 'INVALID_REGEX',
path: `#${property.path}`,
message: 'message.invalid-regex-pattern',
params: [value.value[0]]
};
}
};
return validators;
},
parser: (changes) => changes,
formatter: (changes) => changes
};

export const NameIDFilterEditor = {
...NameIDFilterWizard,
steps: [
{
id: 'common',
label: 'label.target',
index: 1,
fields: [
'name',
'filterEnabled',
'@type',
'resourceId',
'nameIdFormatFilterTarget'
]
},
{
id: 'options',
label: 'label.options',
index: 1,
initialValues: [],
fields: [
'removeExistingFormats',
'formats'
]
}
]
};
Empty file.
Loading

0 comments on commit 6f3ec2f

Please sign in to comment.