Skip to content

Commit 1dba04b

Browse files
committed
implement and wire up the repository
This commit introduces the ui-repository folder which contains the repository front end for Nyingarn. The repo uses the workspace API container as its backend mitigating the need to run a separate backend and / or duplicating lots of common code. commit d87139e Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 15:09:55 2023 +1000 fixing tests commit 6e0a473 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 13:40:53 2023 +1000 capitalise message code commit ec07a31 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:58:04 2023 +1000 bugfixing; working on load commit 8b48463 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:57:43 2023 +1000 refactor access denied message commit deb5b76 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:45:00 2023 +1000 put access control on resource route handler commit 9914cfd Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:31:09 2023 +1000 show reason if access denied commit 31d008f Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:30:36 2023 +1000 bugfix commit d37beee Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:30:14 2023 +1000 put access control on thumbnails route handler commit c7a2c72 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:29:52 2023 +1000 fix name commit 0cab2e9 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:29:22 2023 +1000 refactor; revise repo import to set item access meta in db commit 6e76efc Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 11:28:54 2023 +1000 implement method to check user is authenticated commit f151ed5 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 28 09:59:13 2023 +1000 store review date in the db for repoitems commit 04582bc Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 14:37:35 2023 +1000 cleanup and revise how language geo data handled commit 3e96825 Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 14:37:13 2023 +1000 make controls default size commit 9afa180 Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 14:36:41 2023 +1000 set item publication metadata in db on deposit commit 3ed9a2d Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 14:36:19 2023 +1000 add missing columns to table commit a0bad28 Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 14:36:06 2023 +1000 add/revise migrations commit 06780e7 Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 11:45:19 2023 +1000 bugfix commit 04e430b Author: Marco La Rosa <m@lr.id.au> Date: Tue Jun 27 11:44:45 2023 +1000 bugfix metadata updates on publish and register item in db on deposit commit 037496f Author: Marco La Rosa <m@lr.id.au> Date: Mon Jun 26 16:08:21 2023 +1000 writing tests commit 1911af7 Author: Marco La Rosa <m@lr.id.au> Date: Mon Jun 26 16:07:53 2023 +1000 revise method so we can get file links from the repo as well commit 677f09f Author: Marco La Rosa <m@lr.id.au> Date: Mon Jun 26 12:30:44 2023 +1000 set max width commit e8e69e2 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 12:15:01 2023 +1000 refactor - add note about what gets searched commit 8b72174 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 12:14:46 2023 +1000 search on language code also commit fe71a69 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 10:36:41 2023 +1000 fix styling commit 9158ee0 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 10:25:59 2023 +1000 disable scroll wheel zoom commit 964fbfc Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 10:22:13 2023 +1000 display language geo data commit be2f430 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 09:11:38 2023 +1000 refactor metadata into own component commit 4f2861f Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 15 09:11:24 2023 +1000 render page tab content when tab is selected commit a0395b5 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 16:30:00 2023 +1000 wire up describo override styles commit 9e4281c Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 16:24:02 2023 +1000 refactor load metadata method commit 064dbec Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 16:17:38 2023 +1000 set route if pageId set commit 9dc316d Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 16:17:26 2023 +1000 update dependencies commit 3446978 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 14:53:42 2023 +1000 start on thumbnail view; wire update on route change commit 3a47451 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 14:37:43 2023 +1000 implement and wire up metadata search capability commit 1c3cfe8 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 14:36:08 2023 +1000 implement endpoint to do basic metadata searches commit f26d2b9 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 14:35:54 2023 +1000 install elastic builder commit dc279d4 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 12:28:48 2023 +1000 add override styles for describo commit d5ab47c Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 12:28:37 2023 +1000 update dependencies commit 5d1a895 Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 11:56:16 2023 +1000 styling tweaks commit 8cb9a4b Author: Marco La Rosa <m@lr.id.au> Date: Wed Jun 14 11:51:04 2023 +1000 revise page view height commit fcdc148 Author: Marco La Rosa <m@lr.id.au> Date: Fri Jun 2 15:07:04 2023 +1000 implement data viewer commit b3b3211 Author: Marco La Rosa <m@lr.id.au> Date: Fri Jun 2 15:05:37 2023 +1000 implement handlers to get repo data commit 348080a Author: Marco La Rosa <m@lr.id.au> Date: Fri Jun 2 15:05:22 2023 +1000 add location prop so we can look up repo commit 600debd Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:34:49 2023 +1000 fix licensing commit 67eba84 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:31:19 2023 +1000 wire up describo metadata viewer commit 8554165 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:29:28 2023 +1000 remove commit b5e1e17 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:29:18 2023 +1000 refactor commit d64cb3d Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:28:58 2023 +1000 add route for describo metadata commit bcb6581 Author: Marco La Rosa <m@lr.id.au> Date: Thu Jun 1 10:28:46 2023 +1000 wire up describo commit 9df271d Author: Marco La Rosa <m@lr.id.au> Date: Wed May 31 09:13:57 2023 +1000 implementing UI components commit 2cdee6e Author: Marco La Rosa <m@lr.id.au> Date: Wed May 31 09:13:45 2023 +1000 add ro crate library commit 0404807 Author: Marco La Rosa <m@lr.id.au> Date: Wed May 31 09:13:16 2023 +1000 implement method to get item metadata commit 3a0fde9 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 14:12:54 2023 +1000 remove logo commit f263d06 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 14:12:45 2023 +1000 wire up navbar commit 5b42bf4 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 14:12:00 2023 +1000 add nyingarn site colours commit 7d46356 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 13:55:07 2023 +1000 refactor commit e5540d6 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 13:52:40 2023 +1000 add nyingarn logo; start of homepage commit cf4dfb4 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 13:52:18 2023 +1000 styling; convert to composition commit 64abaea Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 13:52:06 2023 +1000 don't install element-plus globally commit 3371652 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 13:51:33 2023 +1000 revise vite config to use unplugin commit 0a78844 Author: Marco La Rosa <m@lr.id.au> Date: Tue May 30 12:05:46 2023 +1000 wire up repository folder
1 parent 729134b commit 1dba04b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+15809
-1215
lines changed

api/package-lock.json

+111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@paradisec-platform/fastify-tus-s3-plugin": "^1.0.0",
4040
"cross-fetch": "^3.1.6",
4141
"date-fns": "^2.30.0",
42+
"elastic-builder": "^2.19.0",
4243
"fastify": "^4.17.0",
4344
"fastify-socket.io": "^4.0.0",
4445
"foo-foo-mq": "^8.0.1",

api/src/common/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { getS3Handle, getStoreHandle } from "./getS3Handle.js";
55
export {
66
demandAuthenticatedUser,
77
demandAdministrator,
8+
isUserAuthenticated,
89
requireCollectionAccess,
910
requireItemAccess,
1011
} from "./middleware.js";

api/src/common/middleware.js

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ export async function demandAuthenticatedUser(req, res) {
2424
}
2525
}
2626

27+
export async function isUserAuthenticated(req) {
28+
if (!req.headers.authorization) return false;
29+
try {
30+
let user = await verifyToken({
31+
token: req.headers.authorization.split("Bearer ")[1],
32+
configuration: req.session.configuration,
33+
});
34+
user = await getUser({ userId: user.id });
35+
if (!user) {
36+
return false;
37+
}
38+
return user;
39+
} catch (error) {
40+
return false;
41+
}
42+
}
43+
2744
export async function demandAdministrator(req, res) {
2845
if (!req.session.user.administrator) {
2946
return res.forbidden();

api/src/lib/admin.js

+67-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getS3Handle,
55
authorisedUsersFile,
66
indexItem,
7+
getLogger,
78
} from "../common/index.js";
89
import { lookupItemByIdentifier, linkItemToUser, getItems } from "../lib/item.js";
910
import {
@@ -17,6 +18,7 @@ const { groupBy } = lodashPkg;
1718
import { ROCrate } from "ro-crate";
1819
import { getContext } from "../lib/crate-tools.js";
1920
import path from "path";
21+
const log = getLogger();
2022

2123
export async function getAdminItems({ user, prefix, offset = 0 }) {
2224
if (!user.administrator) {
@@ -180,6 +182,11 @@ export async function publishObject({ user, type, identifier, configuration }) {
180182
console.log(error);
181183
throw new Error(`Error getting / handling RO Crate file`);
182184
}
185+
// cleanup the crate file
186+
crate.deleteEntity("http://purl.archive.org/language-data-commons/terms#OpenAccess");
187+
crate.deleteEntity("http://purl.archive.org/language-data-commons/terms#AgreeToTerms");
188+
crate.deleteEntity("http://purl.archive.org/language-data-commons/terms#AuthorizedAccess");
189+
crate.deleteEntity("http://purl.archive.org/language-data-commons/terms#AccessControlList");
183190

184191
// try indexing the content and fail early if the metadata is bad
185192
try {
@@ -200,7 +207,7 @@ export async function publishObject({ user, type, identifier, configuration }) {
200207
licence = {
201208
"@id": configuration.api.licence,
202209
"@type": ["File", "DataReuselicence"],
203-
name: "Open (subject to agreeing to PDSC access conditions)",
210+
name: "Open (subject to agreeing to Nyingarn access conditions)",
204211
access: {
205212
"@id": "http://purl.archive.org/language-data-commons/terms#OpenAccess",
206213
},
@@ -216,17 +223,18 @@ export async function publishObject({ user, type, identifier, configuration }) {
216223
licence = {
217224
"@id": configuration.api.licence,
218225
"@type": ["File", "DataReuselicence"],
219-
name: "Open (subject to agreeing to PDSC access conditions)",
226+
name: "Open (subject to agreeing to Nyingarn access conditions)",
220227
access: {
221228
"@id": "http://purl.archive.org/language-data-commons/terms#OpenAccess",
222229
},
223230
authorizationWorkflow: [
224231
{ "@id": "http://purl.archive.org/language-data-commons/terms#AgreeToTerms" },
225232
],
226233
};
227-
if (item.accessType === "restricted") {
228-
licence.description = item.accessNarrative.text;
229-
licence.reviewDate = item.accessNarrative?.reviewDate;
234+
if (item.publicationMetadata.accessType === "restricted") {
235+
licence.name = "Restricted";
236+
licence.description = item.publicationMetadata.accessNarrative.text;
237+
licence.reviewDate = item.publicationMetadata.accessNarrative?.reviewDate;
230238
licence.access = {
231239
"@id": "http://purl.archive.org/language-data-commons/terms#AuthorizedAccess",
232240
};
@@ -243,6 +251,7 @@ export async function publishObject({ user, type, identifier, configuration }) {
243251
crate.rootDataset.identifier = identifier;
244252
crate = crate.toJSON();
245253
crate["@context"] = getContext();
254+
246255
await store.put({ target: "ro-crate-metadata.json", json: crate });
247256
await store.put({
248257
target: configuration.api.licence,
@@ -334,9 +343,15 @@ export async function depositObjectIntoRepository({
334343
});
335344
await objectWorkspace.removeObject();
336345

337-
// index the item in data in the repository
338-
let crate = await objectRepository.getJSON({ target: "ro-crate-metadata.json" });
339-
await indexItem({ item: { identifier, type }, crate });
346+
// register the repository item in the database
347+
let item = await models.repoitem.findOrCreate({
348+
where: { identifier, type },
349+
default: { identifier, type },
350+
});
351+
item = item[0];
352+
353+
// setup the metadata in the db
354+
await setRepositoryItemMetadata({ item, store: objectRepository });
340355
}
341356

342357
export async function restoreObjectIntoWorkspace({ type, identifier, io = { emit: () => {} } }) {
@@ -389,3 +404,47 @@ export async function restoreObjectIntoWorkspace({ type, identifier, io = { emit
389404
});
390405
await objectWorkspace.copy({ batch: resources });
391406
}
407+
408+
export async function setRepositoryItemMetadata({ item, store }) {
409+
const { identifier, type } = item;
410+
411+
let crate;
412+
try {
413+
crate = await store.getJSON({ target: "ro-crate-metadata.json" });
414+
crate = new ROCrate(crate, { array: true });
415+
} catch (error) {
416+
console.log(error);
417+
throw new Error(`Error getting / handling RO Crate file`);
418+
}
419+
420+
try {
421+
let licence = crate.getEntity("LICENCE.md");
422+
if (!licence) throw new Error(`no licence found - setting to closed`);
423+
let openAccess = false;
424+
let accessControlList = null;
425+
let accessNarrative = null;
426+
let reviewDate = null;
427+
if (licence?.access?.[0]?.["@id"]?.match(/OpenAccess/)) {
428+
openAccess = true;
429+
} else {
430+
accessNarrative = licence.description.join("\n");
431+
reviewDate = licence?.reviewDate?.[0];
432+
accessControlList = await store.getJSON({ target: authorisedUsersFile });
433+
}
434+
435+
item.openAccess = openAccess;
436+
item.accessNarrative = accessNarrative ?? null;
437+
item.reviewDate = reviewDate ?? null;
438+
item.accessControlList = accessControlList ?? null;
439+
await item.save();
440+
441+
// index the item data in the repository
442+
await indexItem({ item: { identifier, type }, crate: crate.toJSON() });
443+
} catch (error) {
444+
log.error(`There was an issue depositing '${type}:${identifier}: ${error.message}`);
445+
item.openAccess = false;
446+
item.accessNarrative = "Error depositing item. Automatically set to restricted.";
447+
item.accessControlList = [];
448+
await item.save();
449+
}
450+
}

0 commit comments

Comments
 (0)