fix: CMS dois without custom paths - #3678
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CMS-mode communities with a canonical URL set are still depositing
*.pubpub.orgresource URLs to Crossref. Community which has CMS mode enabled and a canonical URL configured, produces this in its deposit XML:Redirecting deposits to the external site is one of the main points of CMS mode, so this makes the feature look broken for its first real user.
Root cause
#3671 wired the Crossref transforms up to the new canonical URL helpers (
utils/crossref/transform/pub.js→canonicalPubUrl, and likewise forcommunity.js/collection.js). Those helpers gate oncmsMode:But
findCommunityinserver/doi/queries.tsfetches the community with an explicit attribute allow-list, and #3671 added the two new URL columns without addingcmsMode:Sequelize returns
undefinedfor unselected columns rather than erroring, so in the deposit pathcommunity.cmsModeis always falsy. The failure is then silent:canonicalPubUrlfinds nocanonicalPubUrlTemplate, so it takes thecanonicalBaseUrlbranch;url.replace(communityUrl(community), canonicalCommunityUrl(community));canonicalCommunityUrlbails on the falsycmsModeand returnscommunityUrl(community)— so the replace is a no-op.Result: the pubpub.org URL, in both the preview XML and an actual submit.
Everything outside the deposit path works, which is why CMS mode looked fine: the pub page's
<link rel="canonical">, RSS, citations, and pub connections all get a fully-hydrated community model. And the unit tests inutils/__tests__/cms.test.tspass because they construct community objects by hand withcmsMode: true— nothing exercised the query layer.Fix
Add
'cmsMode'to thefindCommunityattribute list inserver/doi/queries.ts, with a comment explaining why it has to be there.getDoiData→findCommunityis the single choke point for every deposit path (POST /api/doi,GET /api/doiPreview,setDoiData, and the disconnected/connected relationship passes), so this one line covers pub, collection, and community deposits alike.Test
Added a regression test in
server/doi/__tests__/api.test.tsso a future edit tothat attribute list can't silently break this again. It adds a
cmsCommunityfixture (
cmsMode: true,canonicalBaseUrl: "https://cms.example.org") with anadmin and a released pub, previews its DOI, and asserts the deposit contains
https://cms.example.org/pub/<slug>and nopubpub.org. The negative assertionis safe here:
canonicalPubUrl/canonicalCommunityUrlare the only sources ofURLs in a deposit for a fixture with no external publications.
The suite was not run locally — vitest's global setup starts a test Postgres
server that doesn't come up in this environment, and the
testscript also needsthe
firebaseCLI. Relying on CI for verification.Follow-ups (not in this PR)
cmsModegating is inconsistent between the two helpers.canonicalCommunityUrlrequirescmsMode, butcanonicalPubUrl'scanonicalPubUrlTemplatebranch does not — so setting only the Pub URL template redirects pub URLs on a non-CMS community while collection and community URLs stay on pubpub.org. Worth deciding whethercmsModeshould gate canonical URLs at all, or whether the presence ofcanonicalBaseUrlshould be sufficient on its own.