Skip to content

Commit

Permalink
Merge pull request #158 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy v2.1.2 to production
  • Loading branch information
mbklein authored Aug 7, 2023
2 parents 9e8f85d + 0cf5397 commit 1d15a1c
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 93 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dc-api-build",
"version": "2.1.1",
"version": "2.1.2",
"description": "NUL Digital Collections API Build Environment",
"repository": "https://github.com/nulib/dc-api-v2",
"author": "nulib",
Expand Down
9 changes: 6 additions & 3 deletions src/api/request/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ function filterFor(query, event) {
const beUnpublished = { term: { published: false } };
const beRestricted = { term: { visibility: "Private" } };

const filter = event.userToken.isReadingRoom()
? { must: [matchTheQuery], must_not: [beUnpublished] }
: { must: [matchTheQuery], must_not: [beUnpublished, beRestricted] };
let filter = { must: [matchTheQuery] };
if (!event.userToken.isSuperUser()) {
filter.must_not = event.userToken.isReadingRoom()
? [beUnpublished]
: [beUnpublished, beRestricted];
}

return { bool: filter };
}
Expand Down
7 changes: 5 additions & 2 deletions src/handlers/get-collection-by-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const getOpts = (event) => {
const id = event.pathParameters.id;

const allowPrivate =
event.userToken.isReadingRoom() || event.userToken.hasEntitlement(id);
const allowUnpublished = event.userToken.hasEntitlement(id);
event.userToken.isSuperUser() ||
event.userToken.isReadingRoom() ||
event.userToken.hasEntitlement(id);
const allowUnpublished =
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);
return { allowPrivate, allowUnpublished };
};

Expand Down
6 changes: 4 additions & 2 deletions src/handlers/get-file-set-by-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const opensearchResponse = require("../api/response/opensearch");
*/
exports.handler = wrap(async (event) => {
const id = event.pathParameters.id;
const allowPrivate = event.userToken.isReadingRoom();
const esResponse = await getFileSet(id, { allowPrivate });
const allowPrivate =
event.userToken.isSuperUser() || event.userToken.isReadingRoom();
const allowUnpublished = event.userToken.isSuperUser();
const esResponse = await getFileSet(id, { allowPrivate, allowUnpublished });
return await opensearchResponse.transform(esResponse);
});
3 changes: 2 additions & 1 deletion src/handlers/get-thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function validateRequest(event) {
}

const getThumbnail = async (id, aspect, size, event) => {
const allowUnpublished = event.userToken.hasEntitlement(id);
const allowUnpublished =
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);
const allowPrivate = allowUnpublished || event.userToken.isReadingRoom();

let esResponse;
Expand Down
7 changes: 5 additions & 2 deletions src/handlers/get-work-by-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ exports.handler = wrap(async (event) => {
const id = event.pathParameters.id;

const allowPrivate =
event.userToken.isReadingRoom() || event.userToken.hasEntitlement(id);
const allowUnpublished = event.userToken.hasEntitlement(id);
event.userToken.isSuperUser() ||
event.userToken.isReadingRoom() ||
event.userToken.hasEntitlement(id);
const allowUnpublished =
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);

const esResponse = await getWork(id, { allowPrivate, allowUnpublished });

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/oai.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function invalidDateParameters(verb, dates) {
}

/**
* A function to support the OAI-PMH harvesting specfication
* A function to support the "OAI-PMH" harvesting specfication
*/
exports.handler = wrap(async (event) => {
const url = `${baseUrl(event)}oai`;
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/oai/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ async function oaiSearch(dates, set, size = 250) {
{ term: { visibility: "Public" } },
range,
],
...(set && { must: [{ term: { "collection.id": set } }] }),
},
};
if (set) query.bool.must.push({ term: { "collection.id": set } });

const body = {
size,
query,
Expand Down
29 changes: 16 additions & 13 deletions src/handlers/oai/verbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const oaiAttributes = {
xmlns: "http://www.openarchives.org/OAI/2.0/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation":
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI-PMH.xsd",
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI_PMH.xsd",
};

function header(work) {
Expand All @@ -32,11 +32,10 @@ function header(work) {
datestamp: work.modified_date,
};

if (Object.keys(work.collection).length > 0) {
if (work?.collection && Object.keys(work.collection).length > 0) {
fields = {
...fields,
setSpec: work.collection.id,
setName: work.collection.title,
};
}

Expand Down Expand Up @@ -80,7 +79,7 @@ const getRecord = async (url, id) => {
const work = JSON.parse(esResponse.body)._source;
const record = transform(work);
const document = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand All @@ -91,7 +90,7 @@ const getRecord = async (url, id) => {
},
_text: url,
},
GetRecord: { ...record },
GetRecord: { record: record },
},
};
return output(document);
Expand All @@ -107,7 +106,7 @@ const getRecord = async (url, id) => {
const identify = async (url) => {
let earliestDatestamp = await earliestRecord();
const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand All @@ -120,9 +119,10 @@ const identify = async (url) => {
repositoryName: "Northwestern University Libraries",
baseURL: url,
protocolVersion: "2.0",
adminEmail: "[email protected]",
earliestDatestamp: earliestDatestamp,
deletedRecord: "no",
granularity: "YYYY-MM-DDThh:mm:ss.ffffffZ",
granularity: "YYYY-MM-DDThh:mm:ssZ",
},
},
};
Expand Down Expand Up @@ -166,7 +166,7 @@ const listIdentifiers = async (
_text: scrollId,
};
const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand All @@ -177,7 +177,7 @@ const listIdentifiers = async (
_text: url,
},
ListIdentifiers: {
headers: { header: headers },
header: headers,
resumptionToken: resumptionTokenElement,
},
},
Expand All @@ -203,7 +203,7 @@ const listIdentifiers = async (

const listMetadataFormats = (url) => {
const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand Down Expand Up @@ -261,7 +261,7 @@ const listRecords = async (
_text: scrollId,
};
const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand Down Expand Up @@ -303,11 +303,14 @@ const listSets = async (url) => {

const sets = hits.map((hit) => {
const collection = hit._source;
return { setSpec: collection.id, setName: collection.title };
return {
setSpec: collection.id,
setName: collection.title,
};
});

const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: oaiAttributes,
responseDate: new Date().toISOString(),
request: {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/oai/xml-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const declaration = {

const invalidOaiRequest = (oaiCode, message, statusCode = 400) => {
const obj = {
OAI_PMH: {
"OAI-PMH": {
_attributes: {
xmlns: "http://www.openarchives.org/OAI/2.0/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation":
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI-PMH.xsd",
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI_PMH.xsd",
},
responseDate: new Date().toISOString(),
error: {
Expand Down
8 changes: 7 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ function decodeEventBody(event) {
return event;
}

function getEventToken(event) {
const bearerRe = /^Bearer (?<token>.+)$/;
const result = bearerRe.exec(event.headers.authorization);
return result?.groups?.token || event.cookieObject[apiTokenName()];
}

function decodeToken(event) {
const existingToken = event.cookieObject[apiTokenName()];
const existingToken = getEventToken(event);

try {
event.userToken = new ApiToken(existingToken);
Expand Down
4 changes: 2 additions & 2 deletions src/package-lock.json

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

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dc-api",
"version": "2.1.1",
"version": "2.1.2",
"description": "NUL Digital Collections API",
"repository": "https://github.com/nulib/dc-api-v2",
"author": "nulib",
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/mocks/unpublished-work-1234.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"id": "1234",
"api_model": "Work",
"published": false,
"visibility": "Public"
"visibility": "Public",
"representative_file_set": {
"fileSetId": "5678",
"url": "https://index.test.library.northwestern.edu/iiif/2/mbk-dev/5678"
}
}
}
Loading

0 comments on commit 1d15a1c

Please sign in to comment.