Skip to content

Commit 10a6c62

Browse files
committed
Update ODRL-evaluator dependency to v0.5.0
This allows us to correctly define collections
1 parent b14c4bc commit 10a6c62

File tree

5 files changed

+1119
-62
lines changed

5 files changed

+1119
-62
lines changed

packages/uma/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"jose": "^5.2.2",
7373
"logform": "^2.6.0",
7474
"n3": "^1.17.2",
75-
"odrl-evaluator": "^0.4.0",
75+
"odrl-evaluator": "^0.5.0",
7676
"rdf-vocabulary": "^1.0.1",
7777
"uri-template-lite": "^23.4.0",
7878
"winston": "^3.11.0"

packages/uma/src/policies/authorizers/OdrlAuthorizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BadRequestHttpError, DC, NotImplementedHttpError, RDF } from '@solid/community-server';
22
import { basicPolicy, ODRL, UCPPolicy, UCRulesStorage } from '@solidlab/ucp';
33
import { getLoggerFor } from 'global-logger-factory';
4-
import { DataFactory, Literal, NamedNode, Quad_Subject, Store } from 'n3';
4+
import { DataFactory, Literal, NamedNode, Quad_Subject, Store, Writer } from 'n3';
55
import { EyeReasoner, ODRLEngineMultipleSteps, ODRLEvaluator } from 'odrl-evaluator'
66
import { createVocabulary } from 'rdf-vocabulary';
77
import { WEBID } from '../../credentials/Claims';

packages/uma/src/routes/ResourceRegistration.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,9 @@ export class ResourceRegistrationRequestHandler extends HttpHandler {
352352
entry.source.value} while there is no matching collection.`);
353353
}
354354

355-
// for (const collectionId of collectionIds) {
356-
// quads.push(DF.quad(part, ODRL.terms.partOf, collectionId));
357-
// }
358-
// TODO: the above code is correct, but the code below is currently needed because of a bug in the ODRL evaluator
359-
// https://github.com/SolidLabResearch/ODRL-Evaluator/issues/8
360-
quads.push(DF.quad(part, ODRL.terms.partOf, entry.source));
355+
for (const collectionId of collectionIds) {
356+
quads.push(DF.quad(part, ODRL.terms.partOf, collectionId));
357+
}
361358
}
362359
return quads;
363360
}
@@ -371,10 +368,11 @@ export class ResourceRegistrationRequestHandler extends HttpHandler {
371368
protected findCollectionIds(entry: CollectionMetadata, data: Store): Quad_Subject[] {
372369
const sourceMatches = data.getSubjects(ODRL.terms.source, entry.source, null);
373370
if (entry.reverse) {
374-
const blanks = sourceMatches.flatMap((subject): Quad_Object[] =>
375-
data.getObjects(subject, ODRL_P.terms.relation, null)) as Quad_Subject[];
376-
return blanks.filter((subject): boolean =>
377-
data.has(DF.quad(subject, OWL.terms.inverseOf, entry.relation)));
371+
const blankQuads = sourceMatches.flatMap((subject): Quad[] =>
372+
data.getQuads(subject, ODRL_P.terms.relation, null, null));
373+
const matchedBlankQuads = blankQuads.filter((quad): boolean =>
374+
data.has(DF.quad(quad.object as Quad_Subject, OWL.terms.inverseOf, entry.relation)));
375+
return matchedBlankQuads.map((quad) => quad.subject);
378376
} else {
379377
return sourceMatches.filter((subject): boolean =>
380378
data.has(DF.quad(subject, ODRL_P.terms.relation, entry.relation)));

packages/uma/test/unit/routes/ResourceRegistration.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ describe('ResourceRegistration', (): void => {
153153
expect(policies.addRule).toHaveBeenCalledTimes(1);
154154
const newStore = policies.addRule.mock.calls[0][0];
155155
expect(newStore).toBeRdfIsomorphic([
156-
// TODO: because of issue in ODRL evaluator
157-
// DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:1')),
158-
// DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:2')),
159-
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('name')),
156+
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:1')),
157+
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:2')),
160158
]);
161159
});
162160
});
@@ -241,10 +239,8 @@ describe('ResourceRegistration', (): void => {
241239
expect(policies.addRule).toHaveBeenCalledTimes(1);
242240
const newStore = policies.addRule.mock.calls[0][0];
243241
expect(newStore).toBeRdfIsomorphic([
244-
// TODO: because of issue in ODRL evaluator
245-
// DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:1')),
246-
// DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:2')),
247-
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('name')),
242+
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:1')),
243+
DF.quad(DF.namedNode('entry'), ODRL.terms.partOf, DF.namedNode('collection:2')),
248244
]);
249245
});
250246
});

0 commit comments

Comments
 (0)