Skip to content

Commit

Permalink
[ui/authorization] ux: adjust access request elements
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik committed Dec 4, 2023
1 parent 142683e commit 06b9a4b
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 118 deletions.
2 changes: 1 addition & 1 deletion examples/vuejectron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"roboto-fontface": "*",
"vue": "^3.3.4",
"vue-router": "^4.2.5",
"vuetify": "^3.3.21",
"vuetify": "^3.4.4",
"webfontloader": "^1.6.28"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/api-messages/src/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export interface SocialAgent extends UniqueId {
label: string;
note?: string;
accessNeedGroup?: IRI;
authorizationDate: string; // interop:registeredAt
accessRequested: boolean;
accessGrant?: IRI;
authorizationDate: string; // interop:registeredAt TODO: rename to not imply access
lastUpdateDate?: string; // interop:updatedAt
}

Expand Down
2 changes: 1 addition & 1 deletion packages/css-storage-fixture/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"css:config/util/index/default.json",
"css:config/util/logging/winston.json",
"css:config/util/representation-conversion/default.json",
"css:config/util/resource-locker/file.json",
"css:config/util/resource-locker/memory.json",
"css:config/util/variables/default.json"
],
"@graph": []
Expand Down
20 changes: 13 additions & 7 deletions packages/data-model/src/crud/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ export class CRUDContainer extends CRUDResource {
return containedIri;
}

public async applyPatch(sparqlUpdate: string): Promise<void> {
public async applyPatch(sparqlUpdate: string, create = false): Promise<void> {
await this.discoverDescriptionResource();
// update the Description Resource
const { ok } = await this.fetch(this.descriptionResourceIri, {
const headers: { [key: string]: string } = {
'Content-Type': 'application/sparql-update'
};
if (create) {
headers['If-None-Match'] = '*';
} else {
headers['If-Match'] = '*';
}
const response = await this.fetch(this.descriptionResourceIri, {
method: 'PATCH',
body: sparqlUpdate,
headers: {
'Content-Type': 'application/sparql-update'
}
headers
});
if (!ok) {
if (!response.ok) {
throw new Error(`failed to patch ${this.descriptionResourceIri}`);
}
}
Expand Down Expand Up @@ -69,6 +75,6 @@ export class CRUDContainer extends CRUDResource {

await this.discoverDescriptionResource();
const sparqlUpdate = await insertPatch(this.dataset);
await this.applyPatch(sparqlUpdate);
await this.applyPatch(sparqlUpdate, true);
}
}
2 changes: 1 addition & 1 deletion packages/interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@inrupt/solid-client-authn-node": "^1.17.4",
"@inrupt/solid-client-authn-node": "^1.17.5",
"@janeirodigital/interop-authorization-agent": "^1.0.0-rc.22"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@digita-ai/handlersjs-core": "^0.19.3",
"@digita-ai/handlersjs-http": "^0.19.3",
"@digita-ai/handlersjs-logging": "^0.19.3",
"@inrupt/solid-client-authn-node": "^1.17.4",
"@inrupt/solid-client-authn-node": "^1.17.5",
"@janeirodigital/interop-authorization-agent": "^1.0.0-rc.22",
"@janeirodigital/interop-data-model": "^1.0.0-rc.22",
"@janeirodigital/interop-utils": "^1.0.0-rc.22",
Expand Down
2 changes: 1 addition & 1 deletion packages/service/src/services/data-registries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getDataRegistries = async (agentId: string, descriptionsLang: strin
throw new Error(`missing social agent registration: ${agentId}`);
}
if (!socialAgentRegistration.accessGrant) {
throw new Error(`missing access grant for social agent: ${agentId}`);
return [];
}
const dataGrantIndex = socialAgentRegistration.accessGrant.hasDataGrant.reduce(
(acc, dataGrant) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/service/src/services/social-agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const buildSocialAgentProfile = (registration: CRUDSocialAgentRegistration): Soc
note: registration.note,
authorizationDate: registration.registeredAt!.toISOString(),
lastUpdateDate: registration.updatedAt?.toISOString(),
accessGrant: registration.accessGrant?.iri,
accessRequested: !!registration.hasAccessNeedGroup,
accessNeedGroup: registration.reciprocalRegistration?.hasAccessNeedGroup
});
export const getSocialAgents = async (saiSession: AuthorizationAgent) => {
Expand Down
9 changes: 7 additions & 2 deletions packages/service/test/unit/services/social-agents-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { jest } from '@jest/globals';
import { AuthorizationAgent } from '@janeirodigital/interop-authorization-agent';
import { addSocialAgent, getSocialAgents } from '../../../src/services/social-agents';
Expand Down Expand Up @@ -33,11 +34,13 @@ describe('getSocialAgents', () => {
id: 'https://alice.example',
label: 'Alice',
note: 'A friend from a football team',
accessRequested: false,
authorizationDate: '2020-04-04T20:15:47.000Z'
},
{
id: 'https://bob.example',
label: 'Bob',
accessRequested: false,
authorizationDate: '2021-07-02T10:12:21.000Z',
lastUpdateDate: '2021-09-24T11:12:21.000Z'
}
Expand Down Expand Up @@ -65,7 +68,8 @@ describe('addSocialAgent', () => {
expect(result).toEqual({
id: existing.registeredAgent,
label: existing.label,
authorizationDate: existing.registeredAt.toISOString()
authorizationDate: existing.registeredAt.toISOString(),
accessRequested: false
});
expect(addSocialAgentRegistration).not.toBeCalled();
});
Expand All @@ -83,7 +87,8 @@ describe('addSocialAgent', () => {
id: bobWebId,
label,
note,
authorizationDate: expect.any(String)
authorizationDate: expect.any(String),
accessRequested: false
});
expect(addSocialAgentRegistration).toBeCalledWith(bobWebId, label, note);
});
Expand Down
12 changes: 2 additions & 10 deletions packages/utils/src/sparql-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ import { DatasetCore } from '@rdfjs/types';
import { serializeTurtle } from './turtle-serializer';

export async function insertPatch(dataset: DatasetCore): Promise<string> {
return `
INSERT DATA {
${await serializeTurtle(dataset)}
}
`;
return `INSERT DATA { ${await serializeTurtle(dataset)} }`;
}

export async function deletePatch(dataset: DatasetCore): Promise<string> {
return `
DELETE DATA {
${await serializeTurtle(dataset)}
}
`;
return `DELETE DATA { ${await serializeTurtle(dataset)} }`;
}
12 changes: 2 additions & 10 deletions packages/utils/test/sparql-update-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ const snippet = `
test('insertPatch', async () => {
const dataset = await parseTurtle(snippet);
const patch = await insertPatch(dataset);
const expected = `
INSERT DATA {
${await serializeTurtle(dataset)}
}
`;
const expected = `INSERT DATA { ${await serializeTurtle(dataset)} }`;
expect(patch).toBe(expected);
});

test('deletePatch', async () => {
const dataset = await parseTurtle(snippet);
const patch = await deletePatch(dataset);
const expected = `
DELETE DATA {
${await serializeTurtle(dataset)}
}
`;
const expected = `DELETE DATA { ${await serializeTurtle(dataset)} }`;
expect(patch).toBe(expected);
});
64 changes: 38 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/authorization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"roboto-fontface": "*",
"vue": "^3.3.4",
"vue-router": "^4.2.5",
"vuetify": "^3.3.21",
"vuetify": "^3.4.4",
"webfontloader": "^1.6.28"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion ui/authorization/src/components/AuthorizeApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ span.label {
{{ dataInstance.label }}
</v-list-item-title>
<template v-slot:append>
<v-list-item-action>
<v-list-item-action v-if="dataInstancesIndex[dataInstance.id]">
<v-checkbox-btn
v-model="dataInstancesIndex[dataInstance.id].selected"
:disabled="registrationsIndex[registration.id].scope !== 'some'"
Expand Down
Loading

0 comments on commit 06b9a4b

Please sign in to comment.