Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail requests account for reading room in Opensearch query #83

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/handlers/get-thumbnail.js
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ function validateRequest(event) {
}

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

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

6 changes: 5 additions & 1 deletion test/fixtures/mocks/private-work-1234.json
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
"id": "1234",
"api_model": "Work",
"published": true,
"visibility": "Private"
"visibility": "Private",
"representative_file_set": {
"fileSetId": "5678",
"url": "https://index.test.library.northwestern.edu/iiif/2/mbk-dev/5678"
}
}
}
16 changes: 16 additions & 0 deletions test/integration/get-thumbnail.test.js
Original file line number Diff line number Diff line change
@@ -178,6 +178,22 @@ describe("Thumbnail routes", () => {
expect(result.statusCode).to.eq(404);
});

it("returns 200 if the work is private and the user is in the reading room", async () => {
mock
.get("/dc-v2-work/_doc/1234")
.reply(200, helpers.testFixture("mocks/private-work-1234.json"));
mock
.get("/iiif/2/mbk-dev/5678/full/!300,300/0/default.jpg")
.reply(200, helpers.testFixture("mocks/thumbnail_full.jpg"), {
"Content-Type": "image/jpeg",
});
const renderedEvent = event.render();

process.env.READING_ROOM_IPS = renderedEvent.requestContext.http.sourceIp;
const result = await handler(renderedEvent);
expect(result.statusCode).to.eq(200);
});

it("returns 404 if the work is unpublished", async () => {
mock
.get("/dc-v2-work/_doc/1234")