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

Initial deploy to production #52

Merged
merged 107 commits into from
Nov 29, 2022
Merged
Changes from 1 commit
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
60250a5
Update to aws-sdk v3 and create first mocked tests
mbklein Aug 4, 2022
0e7e542
Merge pull request #2 from nulib/3071-aws-sdk-v3-and-mocks
bmquinn Aug 8, 2022
78ff0a6
Adds opensearch tests and fixtures for search()
bmquinn Aug 8, 2022
1c864c6
Merge pull request #6 from nulib/3086-search-test
bmquinn Aug 9, 2022
3f067db
Add a test example for calling getWork() on a missing document return…
bmquinn Aug 9, 2022
9f56079
Merge pull request #7 from nulib/test-coverage
bmquinn Aug 9, 2022
4638c8e
Use an API Gateway v2 HTTP API instead of a v1 REST API
mbklein Aug 10, 2022
b522ae8
Merge pull request #8 from nulib/convert-to-http-api
mbklein Aug 10, 2022
33e87b8
Change RestApiId to ApiId in template
mbklein Aug 10, 2022
b6cd7e8
Enable CORS on API
kdid Aug 12, 2022
744f887
Merge pull request #9 from nulib/fix-cors
kdid Aug 15, 2022
c1b375b
Factor model checking out of handler and add tests
mbklein Aug 15, 2022
688af71
Merge pull request #10 from nulib/test-coverage
mbklein Aug 15, 2022
7b1e480
Add pagination to search
mbklein Aug 15, 2022
be52fed
Merge pull request #11 from nulib/3083-paginate-search
kdid Aug 15, 2022
9df7f99
Add integration tests and improve mocha config
mbklein Aug 16, 2022
cb8de00
Merge pull request #12 from nulib/integration-tests
mbklein Aug 16, 2022
d0de36c
Create API custom domain and mappings
mbklein Aug 19, 2022
fece771
Merge pull request #13 from nulib/3061-api-domain-config
mbklein Aug 22, 2022
af7654c
Normalize headers to lowercase in middleware
mbklein Aug 22, 2022
87aba31
Merge pull request #14 from nulib/improve-middleware
mbklein Aug 22, 2022
ad921c4
Add /works/{id}/thumbnail route
mbklein Aug 24, 2022
0a458de
Merge pull request #15 from nulib/3113-get-work-thumbnail
bmquinn Aug 25, 2022
c5bd14e
Add size and aspect parameters to thumbnail request
mbklein Aug 29, 2022
99fb66b
Merge pull request #16 from nulib/3113-get-work-thumbnail
mbklein Aug 29, 2022
22931df
Forgot to short-circuit the queryParameters reference
mbklein Aug 29, 2022
05ded52
Adds a GET '/collections' endpoint that paginates results
bmquinn Aug 29, 2022
4e0fba9
Merge pull request #17 from nulib/3116-collections
bmquinn Aug 30, 2022
4f739e9
Add documentation
mbklein Aug 29, 2022
8503177
Merge pull request #18 from nulib/3062-initial-documentation
mbklein Sep 2, 2022
8ea2a3d
Update README with instructions on running in dev mode
mbklein Sep 2, 2022
0a9c753
IIIF Collection search handler
kdid Aug 10, 2022
0645bd3
Merge pull request #19 from nulib/BAK-3066-collection-manifests
kdid Sep 6, 2022
7d16c1f
Add root redirect to /docs/v2
mbklein Sep 7, 2022
09ee2b2
Return correct content type header for JSON responses
mbklein Sep 7, 2022
b98536f
Merge pull request #20 from nulib/docs-with-redirect
mbklein Sep 7, 2022
076d59f
Merge pull request #21 from nulib/3164-correct-content-types
mbklein Sep 7, 2022
9388068
Default to full aspect thumbnail
mbklein Sep 26, 2022
42357bf
Merge pull request #22 from nulib/3210-full-thumbnail
mbklein Sep 26, 2022
907d969
Implement /collections/{id}/thumbnail route
mbklein Oct 5, 2022
1fcd63a
Merge pull request #23 from nulib/3217-collection-thumbnail
mbklein Oct 7, 2022
3942a73
Remove searchToken from /collections route
mbklein Oct 7, 2022
0f3a4e9
Merge pull request #24 from nulib/3137-remove-collections-token
mbklein Oct 10, 2022
83b080f
Allow paginator to take additional params for the base url
mbklein Oct 10, 2022
7bf3734
Implement API auth route handlers, tests, and configuration
kdid Oct 5, 2022
af9690b
Merge pull request #25 from nulib/3228-page-size-bug
bmquinn Oct 10, 2022
79f9f8b
Merge pull request #26 from nulib/2836-auth-routes
mbklein Oct 10, 2022
ad16b4c
Fix ApiSecret reference in deploy template
mbklein Oct 10, 2022
3acb5da
Use middleware to fix discrepancies between SAM and API Gateway
mbklein Oct 10, 2022
164f3fd
Shared links API implementation
kdid Oct 12, 2022
1a9ebdf
Merge pull request #27 from nulib/2883-shared-links
mbklein Oct 12, 2022
b44e1df
Add automatic deploy on push to deployable branch
mbklein Oct 13, 2022
d0214dc
Merge pull request #28 from nulib/3087-auto-deploy
mbklein Oct 13, 2022
7cad80d
Return a collection as IIIF collection
kdid Oct 14, 2022
4356af2
Merge pull request #29 from nulib/3103-rdc-collections-iiif
kdid Oct 14, 2022
0b0512c
Allow certain IPs to receive private results
mbklein Oct 14, 2022
0c70a0c
Use repo deploy key instead of personal access token
mbklein Oct 17, 2022
02a2cae
Merge pull request #30 from nulib/3182-reading-room
mbklein Oct 19, 2022
becf561
Adds getSimilar handler function
bmquinn Oct 14, 2022
cae0060
Refactor search handler to use more flexible doSearch
mbklein Oct 17, 2022
3e76809
Allow GET /search to include a models path param
mbklein Oct 19, 2022
f7a9b60
Merge pull request #31 from nulib/3184-more-like-this
kdid Oct 20, 2022
b61e18f
Fix template & add template validation to CI build
mbklein Oct 20, 2022
f838c37
Merge pull request #32 from nulib/fix-template
mbklein Oct 20, 2022
21d2786
Ensure event object has expected members
mbklein Oct 20, 2022
8bbb684
Merge pull request #33 from nulib/BUGFIX-missing-event-members
kdid Oct 20, 2022
9955cfd
Fix 500 error in GET /collections
mbklein Oct 20, 2022
7f6b377
Merge pull request #34 from nulib/BUGFIX-api-gateway-compatibility
bmquinn Oct 20, 2022
4556070
Fix errors in OpenAPI spec document
mbklein Oct 20, 2022
0cec72d
Merge pull request #35 from nulib/fix-docs-build
mbklein Oct 20, 2022
1247989
Add default charset if missing from content-type header
mbklein Oct 20, 2022
43dcf75
Fix missing parameters in swagger docs
mbklein Oct 20, 2022
0ae2d7f
Merge pull request #36 from nulib/3270-character-encoding
mbklein Oct 20, 2022
0c369a0
Replace accidentally deleted GET /search route
mbklein Oct 20, 2022
ac002c5
Calculate the effective path better
mbklein Oct 21, 2022
7791adf
Modifies the /shared-links/{id} handler to parse a shared links
bmquinn Oct 20, 2022
8aeed3e
Merge pull request #38 from nulib/3251-shared-links
bmquinn Oct 21, 2022
76d84f9
Added as-iiif to Work response giving manifest shape
adamjarling Oct 20, 2022
7661733
Merge pull request #37 from nulib/3261-as-iiif
kdid Oct 26, 2022
0066016
Adds thumbnail to IIIF collection if it's an RDC Collection
kdid Oct 27, 2022
df1dbf2
Address PR comments
kdid Oct 27, 2022
05bca03
Merge pull request #39 from nulib/3249-collection-thumbnail-in-iiif-c…
kdid Oct 28, 2022
c99d1c1
Update README
kdid Oct 28, 2022
03e6eae
Adds /auth/logout handler
bmquinn Oct 28, 2022
65526b8
Merge pull request #40 from nulib/3227-auth-logout
bmquinn Oct 28, 2022
6603eb8
Fix shared links allow published logic
kdid Oct 31, 2022
250c27e
Merge pull request #41 from nulib/shared-link-fix
bmquinn Oct 31, 2022
a662190
Workaround for NUSSO missing directory attribute issue
mbklein Oct 31, 2022
a41ab21
Merge pull request #42 from nulib/3305-auth-callback-fix
kdid Oct 31, 2022
4b9b906
Make stubbed user match shape of actual user
mbklein Oct 31, 2022
f03b099
Merge pull request #43 from nulib/3305-fix-stub-user
mbklein Oct 31, 2022
03e4b4f
Add support for the 'sort' query string parameter in GET searches
bmquinn Oct 31, 2022
86e8308
Merge pull request #44 from nulib/3161-search-sort
mbklein Nov 3, 2022
a6a9da3
Don't return unpublished file sets
kdid Nov 3, 2022
90053c4
Merge pull request #45 from nulib/3332-file-set-published-access
bmquinn Nov 3, 2022
1bb3d24
Add file set authorization routes
kdid Oct 28, 2022
a710ac5
Merge pull request #46 from nulib/3166-file-set-auth
mbklein Nov 7, 2022
f137027
Authorize fake “FileSet” requests when id matches 00000000-0000-0000-…
mbklein Nov 8, 2022
5c1471a
Make sure both types of token (directory / stub) include netid
mbklein Nov 9, 2022
4a7b71b
Merge pull request #47 from nulib/3348-add-missing-netid-to-token
mbklein Nov 9, 2022
874c626
Net ID file set authorization for reading room
kdid Nov 11, 2022
f520242
Merge pull request #48 from nulib/3352-reading-room-netid
kdid Nov 11, 2022
acb5516
Prefer the search context's size over the default
mbklein Nov 28, 2022
148cc3a
Merge pull request #50 from nulib/3374-pagination-bug
bmquinn Nov 28, 2022
50ea75d
Update HTTPS documentation
mbklein Nov 29, 2022
95e6db4
Merge pull request #51 from nulib/3279-https-docs
mbklein Nov 29, 2022
e0374ce
API mappings need to depend on API
mbklein Nov 29, 2022
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
Prev Previous commit
Next Next commit
Fix shared links allow published logic
kdid committed Oct 31, 2022
commit 6603eb899719ad16ed232f652858e548f2f6eb3e
19 changes: 10 additions & 9 deletions src/api/opensearch.js
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ async function getSharedLink(id, opts) {
return getDocument("shared_links", id, opts);
}

async function getDocument(index, id, opts) {
async function getDocument(index, id, opts = {}) {
const request = initRequest(`/${prefix(index)}/_doc/${id}`);
let response = await awsFetch(request);
if (response.statusCode === 200) {
const body = JSON.parse(response.body);
if (index != "shared_links" && !isVisible(body, opts?.allowPrivate)) {
if (index != "shared_links" && !isVisible(body, opts)) {
let responseBody = {
_index: prefix(index),
_type: "_doc",
@@ -40,14 +40,15 @@ async function getDocument(index, id, opts) {
return response;
}

function isVisible(doc, allowPrivate) {
function isVisible(doc, { allowPrivate, allowUnpublished }) {
if (!doc?.found) return false;
const isAllowed = allowPrivate || doc?._source?.visibility !== "Private";
if (doc?._source.api_model == "FileSet") {
return isAllowed;
} else {
return doc?._source?.published && isAllowed;
}
const isAllowedVisibility =
allowPrivate || doc?._source.visibility !== "Private";
const isAllowedPublished =
allowUnpublished ||
doc?._source.published ||
doc?._source.api_model == "FileSet";
return isAllowedVisibility && isAllowedPublished;
}

function initRequest(path) {
5 changes: 4 additions & 1 deletion src/handlers/get-shared-link-by-id.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,10 @@ exports.handler = async (event) => {
if (linkExpired(expirationDate) || !workId)
return invalidRequest("Not Found");

const workResponse = await getWork(workId, { allowPrivate: true });
const workResponse = await getWork(workId, {
allowPrivate: true,
allowUnpublished: true,
});
if (workResponse.statusCode !== 200) return invalidRequest("Not Found");
const response = opensearchResponse.transform(workResponse);
return processResponse(event, response);
13 changes: 13 additions & 0 deletions test/fixtures/mocks/private-unpublished-work-1234.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_index": "dev-dc-v2-work",
"_type": "_doc",
"_id": "1234",
"_version": 1,
"found": true,
"_source": {
"id": "1234",
"api_model": "Work",
"published": false,
"visibility": "Private"
}
}
40 changes: 40 additions & 0 deletions test/integration/get-shared-link-by-id.test.js
Original file line number Diff line number Diff line change
@@ -59,5 +59,45 @@ describe("Retrieve shared link by id", () => {
const result = await handler(event);
expect(result.statusCode).to.eq(404);
});

it("retrieves an unpublished single shared link document", async () => {
mock
.get("/shared_links/_doc/1234")
.reply(200, helpers.testFixture("mocks/shared-link-1234.json"));

mock
.get("/dc-v2-work/_doc/1234")
.reply(
200,
helpers.testFixture("mocks/private-unpublished-work-1234.json")
);

const event = helpers
.mockEvent("GET", "/shared-links/{id}")
.pathParams({ id: 1234 })
.render();
const result = await handler(event);
expect(result.statusCode).to.eq(200);
const resultBody = JSON.parse(result.body);
expect(resultBody.data.api_model).to.eq("Work");
expect(resultBody.data.visibility).to.eq("Private");
});

it("returns a 404 when the link exists but the work doesn't", async () => {
mock
.get("/shared_links/_doc/1234")
.reply(200, helpers.testFixture("mocks/shared-link-1234.json"));

mock
.get("/dc-v2-work/_doc/1234")
.reply(200, helpers.testFixture("mocks/missing-work-1234.json"));

const event = helpers
.mockEvent("GET", "/shared-links/{id}")
.pathParams({ id: 1234 })
.render();
const result = await handler(event);
expect(result.statusCode).to.eq(404);
});
});
});