Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/SHIBUI-996
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Smith committed Dec 4, 2018
2 parents 03d3b24 + 46526ab commit 5024bc0
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 182 deletions.
104 changes: 35 additions & 69 deletions backend/src/main/resources/dynamic-http-metadata-provider.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"type": "object",
"required": [
"xmlId",
"metadataURL"
"metadataURL",
"metadataRequestURLConstructionScheme"
],
"properties": {
"enabled": {
Expand All @@ -20,6 +21,39 @@
},
"metadataRequestURLConstructionScheme": {
"type": "object",
"required": [
"@type",
"content"
],
"anyOf": [
{
"properties": {
"@type": {
"enum": [
"Regex"
]
}
},
"required": [
"@type",
"content",
"match"
]
},
{
"properties": {
"@type": {
"enum": [
"MetadataQueryProtocol"
]
}
},
"required": [
"@type",
"content"
]
}
],
"properties": {
"@type": {
"title": "label.md-request-type",
Expand All @@ -35,12 +69,6 @@
],
"description": "value.md-query-protocol"
},
{
"enum": [
"Template"
],
"description": "value.template"
},
{
"enum": [
"Regex"
Expand All @@ -54,67 +82,6 @@
"description": "tooltip.md-request-value",
"type": "string"
},
"transformRef": {
"title": "label.transform-ref",
"description": "tooltip.transform-ref",
"type": "string",
"visibleIf": {
"content": [
""
]
}
},
"encodingStyle": {
"title": "label.encoding-style",
"description": "tooltip.encoding-style",
"type": "string",
"widget": {
"id": "select"
},
"default": "FORM",
"oneOf": [
{
"enum": [
"NONE"
],
"description": "None"
},
{
"enum": [
"FORM"
],
"description": "Form"
},
{
"enum": [
"PATH"
],
"description": "Path"
},
{
"enum": [
"FRAGMENT"
],
"description": "Fragment"
}
],
"visibleIf": {
"@type": [
"Template"
]
}
},
"velocityEngine": {
"title": "label.velocity-engine",
"description": "tooltip.velocity-engine",
"type": "string",
"default": "shibboleth.VelocityEngine",
"visibleIf": {
"@type": [
"Template"
]
}
},
"match": {
"title": "label.match",
"description": "tooltip.match",
Expand Down Expand Up @@ -638,7 +605,6 @@
"title": "label.certificate-file",
"description": "tooltip.certificate-file",
"type": "string",
"widget": "textarea",
"default": ""
}
},
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/resources/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ message.uri-valid-format=URI must be valid format.
message.id-unique=ID must be unique.
message.array-items-must-be-unique=Items in list must be unique.

message.org-name-required=Organization Name is required.
message.org-displayName-required=Organization Name is required.
message.org-url-required=Organization Name is required.
message.org-incomplete=These three fields must all be entered if any single field has a value.

message.conflict=Conflict
message.data-version-contention=Data Version Contention
message.contention-new-version=A newer version of this metadata source has been saved. Below are a list of changes. You can use your changes or their changes.
Expand Down
30 changes: 18 additions & 12 deletions backend/src/main/resources/metadata-sources-ui-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,24 @@
}
},
"dependencies": {
"name": [
"displayName",
"url"
],
"displayName": [
"name",
"url"
],
"url": [
"name",
"displayName"
]
"name": {
"required": [
"displayName",
"url"
]
},
"displayName": {
"required": [
"name",
"url"
]
},
"url": {
"required": [
"name",
"displayName"
]
}
}
},
"contacts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ describe('Metadata Source Base class', () => {
it('should return a list of validators for the ngx-schema-form', () => {
expect(Object.keys(getValidators([]))).toEqual([
'/',
'/entityId'
'/entityId',
'/organization/name',
'/organization/displayName',
'/organization/url'
]);
});
});
Expand Down
19 changes: 17 additions & 2 deletions ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
}

getValidators(entityIdList: string[]): { [key: string]: any } {
const checkOrg = (value, property, form) => {
const org = property.parent;
const orgValue = org.value || {};
const err = Object.keys(orgValue) && !value ? {
code: 'ORG_INCOMPLETE',
path: `#${property.path}`,
message: `message.org-incomplete`,
params: [value]
} : null;
return err;
};
const validators = {
'/': (value, property, form_current) => {
let errors;
Expand All @@ -68,12 +79,13 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
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;
const error = validator ? validator(item, form_current.getProperty(key), form_current) : null;
if (error) {
errors = errors || [];
errors.push(error);
}
});
console.log(errors, form_current);
return errors;
},
'/entityId': (value, property, form) => {
Expand All @@ -84,7 +96,10 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
params: [value]
} : null;
return err;
}
},
'/organization/name': checkOrg,
'/organization/displayName': checkOrg,
'/organization/url': checkOrg
};
return validators;
}
Expand Down
16 changes: 1 addition & 15 deletions ui/src/app/metadata/provider/model/dynamic-http.provider.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@ export const DynamicHttpMetadataProviderWizard: Wizard<DynamicHttpMetadataProvid
...BaseMetadataProviderEditor,
label: 'DynamicHttpMetadataProvider',
type: 'DynamicHttpMetadataResolver',
bindings: {
'/metadataRequestURLConstructionScheme/@type': [
{
'input': (event, property: FormProperty) => {
let transform = property.parent.getProperty('transformRef');
let content = property.parent.getProperty('content');
if (!content.value && property.value !== 'Regex') {
transform.setVisible(true);
} else {
transform.setVisible(false);
}
}
}
]
},
bindings: {},
getValidators(namesList: string[] = [], xmlIdList: string[] = []): any {
const validators = BaseMetadataProviderEditor.getValidators(namesList);
validators['/xmlId'] = (value, property, form) => {
Expand Down
92 changes: 89 additions & 3 deletions ui/src/app/schema-form/service/schema.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed, async, inject } from '@angular/core/testing';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClientModule, HttpRequest } from '@angular/common/http';
import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClientModule } from '@angular/common/http';
import { SchemaService } from './schema.service';

describe(`Schema Service`, () => {
Expand Down Expand Up @@ -171,5 +171,91 @@ describe(`Schema Service`, () => {
})).toBe(true);
})
);

it(`should return true if dependency is active`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' },
baz: { type: 'string' }
},
dependencies: {
foo: { required: ['bar', 'baz'] },
bar: { required: ['foo', 'baz'] },
baz: { required: ['foo', 'bar'] }
}
},
value: {
foo: 'abcdef'
}
},
path: '/bar'
})).toBe(true);
})
);

it(`should return true if the property has an active dependency`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' },
baz: { type: 'string' }
},
dependencies: {
foo: { required: ['bar', 'baz'] },
bar: { required: ['foo', 'baz'] },
baz: { required: ['foo', 'bar'] }
}
},
value: {
foo: 'abc',
bar: '123'
}
},
path: '/foo'
})).toBe(true);
})
);

it(`should return false if no dependencies are defined`,
inject([SchemaService], (service: SchemaService) => {
expect(service.isRequired({
parent: {
schema: {
properties: {
foo: { type: 'string' },
bar: { type: 'string' },
baz: { type: 'string' }
}
},
value: {
foo: true,
baz: true
}
},
path: '/bar'
})).toBe(false);
})
);
});

describe('getRequiredDependencies method', () => {
it('should return the provided result if an array', inject([SchemaService], (service: SchemaService) => {
expect(service.getRequiredDependencies(['foo', 'bar'])).toEqual(['foo', 'bar']);
}));

it('should return the content of the required attribute if provided', inject([SchemaService], (service: SchemaService) => {
expect(service.getRequiredDependencies({required: ['foo', 'bar'] })).toEqual(['foo', 'bar']);
}));

it('should return an empty array if not provided with required property', inject([SchemaService], (service: SchemaService) => {
expect(service.getRequiredDependencies({ foo: 'bar' })).toEqual([]);
}));
});
});
Loading

0 comments on commit 5024bc0

Please sign in to comment.