Skip to content

Commit 1d15a1c

Browse files
authored
Merge pull request #158 from nulib/deploy/staging
Deploy v2.1.2 to production
2 parents 9e8f85d + 0cf5397 commit 1d15a1c

20 files changed

+342
-93
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dc-api-build",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "NUL Digital Collections API Build Environment",
55
"repository": "https://github.com/nulib/dc-api-v2",
66
"author": "nulib",

src/api/request/pipeline.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ function filterFor(query, event) {
55
const beUnpublished = { term: { published: false } };
66
const beRestricted = { term: { visibility: "Private" } };
77

8-
const filter = event.userToken.isReadingRoom()
9-
? { must: [matchTheQuery], must_not: [beUnpublished] }
10-
: { must: [matchTheQuery], must_not: [beUnpublished, beRestricted] };
8+
let filter = { must: [matchTheQuery] };
9+
if (!event.userToken.isSuperUser()) {
10+
filter.must_not = event.userToken.isReadingRoom()
11+
? [beUnpublished]
12+
: [beUnpublished, beRestricted];
13+
}
1114

1215
return { bool: filter };
1316
}

src/handlers/get-collection-by-id.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ const getOpts = (event) => {
88
const id = event.pathParameters.id;
99

1010
const allowPrivate =
11-
event.userToken.isReadingRoom() || event.userToken.hasEntitlement(id);
12-
const allowUnpublished = event.userToken.hasEntitlement(id);
11+
event.userToken.isSuperUser() ||
12+
event.userToken.isReadingRoom() ||
13+
event.userToken.hasEntitlement(id);
14+
const allowUnpublished =
15+
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);
1316
return { allowPrivate, allowUnpublished };
1417
};
1518

src/handlers/get-file-set-by-id.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const opensearchResponse = require("../api/response/opensearch");
77
*/
88
exports.handler = wrap(async (event) => {
99
const id = event.pathParameters.id;
10-
const allowPrivate = event.userToken.isReadingRoom();
11-
const esResponse = await getFileSet(id, { allowPrivate });
10+
const allowPrivate =
11+
event.userToken.isSuperUser() || event.userToken.isReadingRoom();
12+
const allowUnpublished = event.userToken.isSuperUser();
13+
const esResponse = await getFileSet(id, { allowPrivate, allowUnpublished });
1214
return await opensearchResponse.transform(esResponse);
1315
});

src/handlers/get-thumbnail.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function validateRequest(event) {
3131
}
3232

3333
const getThumbnail = async (id, aspect, size, event) => {
34-
const allowUnpublished = event.userToken.hasEntitlement(id);
34+
const allowUnpublished =
35+
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);
3536
const allowPrivate = allowUnpublished || event.userToken.isReadingRoom();
3637

3738
let esResponse;

src/handlers/get-work-by-id.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ exports.handler = wrap(async (event) => {
1010
const id = event.pathParameters.id;
1111

1212
const allowPrivate =
13-
event.userToken.isReadingRoom() || event.userToken.hasEntitlement(id);
14-
const allowUnpublished = event.userToken.hasEntitlement(id);
13+
event.userToken.isSuperUser() ||
14+
event.userToken.isReadingRoom() ||
15+
event.userToken.hasEntitlement(id);
16+
const allowUnpublished =
17+
event.userToken.isSuperUser() || event.userToken.hasEntitlement(id);
1518

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

src/handlers/oai.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function invalidDateParameters(verb, dates) {
2828
}
2929

3030
/**
31-
* A function to support the OAI-PMH harvesting specfication
31+
* A function to support the "OAI-PMH" harvesting specfication
3232
*/
3333
exports.handler = wrap(async (event) => {
3434
const url = `${baseUrl(event)}oai`;

src/handlers/oai/search.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ async function oaiSearch(dates, set, size = 250) {
4444
{ term: { visibility: "Public" } },
4545
range,
4646
],
47-
...(set && { must: [{ term: { "collection.id": set } }] }),
4847
},
4948
};
49+
if (set) query.bool.must.push({ term: { "collection.id": set } });
50+
5051
const body = {
5152
size,
5253
query,

src/handlers/oai/verbs.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const oaiAttributes = {
2323
xmlns: "http://www.openarchives.org/OAI/2.0/",
2424
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
2525
"xsi:schemaLocation":
26-
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI-PMH.xsd",
26+
"http://www.openarchives.org/OAI/2.0/\nhttp://www.openarchives.org/OAI/2.0/OAI_PMH.xsd",
2727
};
2828

2929
function header(work) {
@@ -32,11 +32,10 @@ function header(work) {
3232
datestamp: work.modified_date,
3333
};
3434

35-
if (Object.keys(work.collection).length > 0) {
35+
if (work?.collection && Object.keys(work.collection).length > 0) {
3636
fields = {
3737
...fields,
3838
setSpec: work.collection.id,
39-
setName: work.collection.title,
4039
};
4140
}
4241

@@ -80,7 +79,7 @@ const getRecord = async (url, id) => {
8079
const work = JSON.parse(esResponse.body)._source;
8180
const record = transform(work);
8281
const document = {
83-
OAI_PMH: {
82+
"OAI-PMH": {
8483
_attributes: oaiAttributes,
8584
responseDate: new Date().toISOString(),
8685
request: {
@@ -91,7 +90,7 @@ const getRecord = async (url, id) => {
9190
},
9291
_text: url,
9392
},
94-
GetRecord: { ...record },
93+
GetRecord: { record: record },
9594
},
9695
};
9796
return output(document);
@@ -107,7 +106,7 @@ const getRecord = async (url, id) => {
107106
const identify = async (url) => {
108107
let earliestDatestamp = await earliestRecord();
109108
const obj = {
110-
OAI_PMH: {
109+
"OAI-PMH": {
111110
_attributes: oaiAttributes,
112111
responseDate: new Date().toISOString(),
113112
request: {
@@ -120,9 +119,10 @@ const identify = async (url) => {
120119
repositoryName: "Northwestern University Libraries",
121120
baseURL: url,
122121
protocolVersion: "2.0",
122+
adminEmail: "[email protected]",
123123
earliestDatestamp: earliestDatestamp,
124124
deletedRecord: "no",
125-
granularity: "YYYY-MM-DDThh:mm:ss.ffffffZ",
125+
granularity: "YYYY-MM-DDThh:mm:ssZ",
126126
},
127127
},
128128
};
@@ -166,7 +166,7 @@ const listIdentifiers = async (
166166
_text: scrollId,
167167
};
168168
const obj = {
169-
OAI_PMH: {
169+
"OAI-PMH": {
170170
_attributes: oaiAttributes,
171171
responseDate: new Date().toISOString(),
172172
request: {
@@ -177,7 +177,7 @@ const listIdentifiers = async (
177177
_text: url,
178178
},
179179
ListIdentifiers: {
180-
headers: { header: headers },
180+
header: headers,
181181
resumptionToken: resumptionTokenElement,
182182
},
183183
},
@@ -203,7 +203,7 @@ const listIdentifiers = async (
203203

204204
const listMetadataFormats = (url) => {
205205
const obj = {
206-
OAI_PMH: {
206+
"OAI-PMH": {
207207
_attributes: oaiAttributes,
208208
responseDate: new Date().toISOString(),
209209
request: {
@@ -261,7 +261,7 @@ const listRecords = async (
261261
_text: scrollId,
262262
};
263263
const obj = {
264-
OAI_PMH: {
264+
"OAI-PMH": {
265265
_attributes: oaiAttributes,
266266
responseDate: new Date().toISOString(),
267267
request: {
@@ -303,11 +303,14 @@ const listSets = async (url) => {
303303

304304
const sets = hits.map((hit) => {
305305
const collection = hit._source;
306-
return { setSpec: collection.id, setName: collection.title };
306+
return {
307+
setSpec: collection.id,
308+
setName: collection.title,
309+
};
307310
});
308311

309312
const obj = {
310-
OAI_PMH: {
313+
"OAI-PMH": {
311314
_attributes: oaiAttributes,
312315
responseDate: new Date().toISOString(),
313316
request: {

0 commit comments

Comments
 (0)