Skip to content

Commit

Permalink
Support per-service config item alwaysShowForm (#64)
Browse files Browse the repository at this point in the history
Forces the full form to be displayed once, even if all necessary
metadata is present, requiring the user to confirm.

Update docs.

Fixes PR-2060.
  • Loading branch information
MikeTaylor authored Dec 11, 2024
1 parent e0e9e69 commit c4b93a5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Do not assume that mod-rs's successful-POST response has a `serviceType` field. That assumption could cause an NPE under some circumstances. No Jira issue.
* Make robust against old version of mod-rs (e.g. 2.15.5) that do not return lists of copyright types. Fixes PR-1841.
* Support per-service config item `allowAnyDate` to disable date validation in forms. Update docs, add tests. Fixes PR-2059.
* Support per-service config item `alwaysShowForm` to specify that the full form always should be displayed once for confirmation even when the submitted OpenURL has complete basic metadata. Update docs. Fixes PR-2059.

## [1.6.0](https://github.com/openlibraryenvironment/listener-openurl/tree/v1.6.0) (2024-03-04)

Expand Down Expand Up @@ -67,7 +68,7 @@
* When `svc_id` is `json`, post the patron request as usual but return a JSON summary instead of an HTML page. Fixes PR-461.
* When prompting for pickup location, offer a dropdown of valid values obtained from ReShare. Fixes PR-572. Available from v1.3.1.
* Consolidate OpenURL resolver configuration files. Fixes PR-681.
* Add service entries for EAST and WEST unviersities to the configuration file. Fixes PR-677.
* Add service entries for EAST and WEST universities to the configuration file. Fixes PR-677.
* When a baseURL is invoked with no parameters (or insufficient to attempt a resolution), the enter-metadata form is presented. Fixes PR-651.
* Support the `rft.edition` key. This is not mentioned in the standards, but appears in some example v1.0 OpenURLs.
* Apply styles to the Request Accepted page. Fixes PR-686.
Expand Down
3 changes: 2 additions & 1 deletion config/openurl.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"tenant": "reshare_north",
"username": "north_admin",
"password": "north5231",
"allowAnyDate": true
"allowAnyDate": true,
"alwaysShowForm": true
}
}
}
2 changes: 2 additions & 0 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ To specify several different back-ends, provide a directory under the `services`

If the `allowAnyDate` configuration item is set for a service, then forms that require a publication date to be entered do not insist that it consist of four digits, allowing "fuzzy" dates such as "1950s", "c1935" or "17th Century".

If the `alwaysShowForm` configuration item is set for a service, then the full form is always displayed once for confirmation even when the submitted OpenURL has complete basic metadata.


### Templates

Expand Down
2 changes: 1 addition & 1 deletion src/ContextObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ContextObject {
hasBasicData() {
const rft = (this.metadata || {}).rft || {};
let st = this.admindata.svc?.id;
if (st === 'contextObject') st = 'loan';
if (st === 'contextObject' || !st) st = 'loan';

if (this.admindata.rft?.id) return true;
if (st === 'loan' && rft.title && rft.au) return true;
Expand Down
17 changes: 9 additions & 8 deletions src/OpenURLServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ function makeFormData(ctx, query, service, valuesNotShownInForm, firstTry, npl)


async function maybeRenderForm(ctx, next) {
const { co, metadata, service, npl } = ctx.state;
const { co, metadata, service, npl, svcCfg } = ctx.state;

ctx.cfg.log('flow', 'Check metadata to determine if we should render form');
// The form is good if it has no pickup location is required OR one is supplied OR it's a copy request
if (co.hasBasicData() &&
(npl ||
get(metadata, ['svc', 'pickupLocation']) ||
co.admindata.svc?.id === 'copy'
)) {
const pickupLocationRequirementSatisfied = (npl ||
!!get(metadata, ['svc', 'pickupLocation']) ||
co.admindata.svc?.id === 'copy'
);
const firstTime = !co.getQuery()['svc.ntries'];
const insistOnForm = svcCfg.alwaysShowForm && firstTime;
if (co.hasBasicData() && pickupLocationRequirementSatisfied && !insistOnForm) {
return await next();
}

Expand Down Expand Up @@ -202,7 +203,7 @@ async function maybeRenderForm(ctx, next) {
query['svc.longForm'] = '1';
}

const ntries = query['svc.ntries'] || '0';
const ntries = query['svc.ntries'] || '0'; // Always a string, though the value is numeric
query['svc.ntries'] = (parseInt(ntries) + 1).toString();

if (!query['rft.title']) {
Expand Down

0 comments on commit c4b93a5

Please sign in to comment.