Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,27 @@

// The DOCiD account Openscholar Reports registers with (plans/identifier-services), beside Zenodo and Crossref in
// the publishing settings. DOCiD has no test service: every DOCiD is a real, permanent Handle, so there is only the
// real account. Its lists come from DOCiD when the account is verified and saved; until then the pickers say so.
// real account. What DOCiD files each report as is mapped from the report, by name, against the lists DOCiD gives the
// account when it is verified and saved.

import { useTranslations } from "next-intl";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";
import { Lock, TriangleAlert } from "@/components/icons";
import { docidResourceType } from "@opendeved/doi-sync-core/docid";
import { TriangleAlert } from "@/components/icons";
import type { PublicationSettings } from "@/convex/evidenceLibraries/publicationValidators";
import { Field } from "../section-card";
import { FieldGroup } from "../fields";

type Docid = NonNullable<PublicationSettings["docid"]>;
type Option = { id: number; name: string };
export const NO_DOCID: Docid = { mode: "off", email: "" };

function Pick({ label, hint, value, options, onChange }: { label: string; hint?: string; value: number | undefined; options: Option[] | undefined; onChange: (id: number) => void }) {
const t = useTranslations("publicationSettings");
return (
<Field label={label} hint={hint}>
{(id) =>
options ? (
<Select value={value === undefined ? undefined : String(value)} onValueChange={(picked) => onChange(Number(picked))}>
<SelectTrigger id={id} className="w-full">
<SelectValue placeholder={t("docidChoose")} />
</SelectTrigger>
<SelectContent>
{options.map((option) => (
<SelectItem key={option.id} value={String(option.id)}>
{option.name}
</SelectItem>
))}
</SelectContent>
</Select>
) : (
// No lists until the account is verified: drawn as the app draws what can't be used yet, saying why.
<TooltipHint label={t("docidListsFirst")}>
<span id={id} tabIndex={0} className="flex h-9 w-full cursor-default items-center gap-2 rounded-md border border-input px-3 text-sm text-muted-foreground opacity-50">
<Lock className="size-3.5 shrink-0" />
{t("docidChoose")}
</span>
</TooltipHint>
)
}
</Field>
);
}

export function DocidAccount({ docid = NO_DOCID, onChange, password, onPassword, stored }: { docid: Docid | undefined; onChange: (next: Docid) => void; password: string; onPassword: (value: string) => void; /** A password is kept from an earlier save. */ stored: boolean }) {
const t = useTranslations("publicationSettings");
const on = docid.mode === "custom";
const update = (patch: Partial<Docid>) => onChange({ ...docid, ...patch });
const allowsNone = docid.options && !docid.options.resourceTypes.length;
// Verified, and DOCiD doesn't let the account file reports under the resource type they map to.
const cantFile = docid.options && !docidResourceType("Report", docid.options.resourceTypes);
return (
<FieldGroup
title={<img src="/brands/docid.png" alt="DOCiD" className="h-6 w-auto" />}
Expand All @@ -70,11 +38,8 @@ export function DocidAccount({ docid = NO_DOCID, onChange, password, onPassword,
<div className="grid gap-4 sm:grid-cols-2">
<Field label={t("email")}>{(id) => <Input id={id} type="email" autoComplete="off" value={docid.email} placeholder="name@example.org" onChange={(e) => update({ email: e.target.value })} />}</Field>
<Field label={t("password")}>{(id) => <Input id={id} type="password" autoComplete="new-password" value={password} placeholder={stored ? t("storedHint") : undefined} onChange={(e) => onPassword(e.target.value)} />}</Field>
<Pick label={t("docidResourceType")} hint={allowsNone ? undefined : t("docidResourceTypeHint")} value={docid.resourceTypeId} options={docid.options?.resourceTypes} onChange={(resourceTypeId) => update({ resourceTypeId })} />
<Pick label={t("docidFileType")} hint={t("docidFileTypeHint")} value={docid.publicationTypeId} options={docid.options?.publicationTypes} onChange={(publicationTypeId) => update({ publicationTypeId })} />
<Pick label={t("docidFunderType")} value={docid.funderTypeId} options={docid.options?.funderTypes} onChange={(funderTypeId) => update({ funderTypeId })} />
</div>
{allowsNone ? (
{cantFile ? (
<p role="status" className="flex items-start gap-2 rounded-xl bg-inset px-3 py-2.5 text-xs text-pretty ink-warning">
<TriangleAlert className="mt-px size-3.5 shrink-0" />
{t("docidNoResourceTypes")}
Expand Down
29 changes: 25 additions & 4 deletions components/reports/details-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Button } from "@/components/ui/button";
import { NextButton } from "@/components/reports/next-button";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { FUNDER_TYPES, type FunderType } from "@opendeved/doi-sync-core/docid";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { TooltipHint } from "@/components/ui/tooltip";
Expand Down Expand Up @@ -404,8 +405,8 @@ export function DetailsStep({
}: {
/** The report an abstract is written from, and the workspace its author asks from; none for a reviewer. Without it the form offers none. */
writing?: { key: string; workspaceId?: Id<"workspaces"> };
/** The registrars the report is sent to, so each part's "?" leaves out one that isn't used. */
registrars?: { crossref: boolean; zenodo: boolean };
/** The registrars the report is sent to, so each part's "?" leaves out one that isn't used, and DOCiD's funder types show where it is one. */
registrars?: { crossref: boolean; zenodo: boolean; docid?: boolean | undefined };
initial: Metadata;
/** Given the details, and the `version` the form opened on. */
onRun: (m: Metadata, version: number | undefined) => Promise<void>;
Expand Down Expand Up @@ -810,7 +811,12 @@ export function DetailsStep({
<CountrySelector label={t("places")} placeholder={t("addPlace")} selectedRegions={m.countries} onSelectionChange={(countries) => set("countries", countries)} bypassLimit />
</Section>

<Section title={t("funding")} help="funding">
<Section
title={t("funding")}
help="funding"
// Names the funder type each row ends with, where the report goes to DOCiD.
aside={registrars?.docid ? <span className="ms-auto flex items-center gap-0.5 text-xs font-medium text-muted-foreground">{t("funderType")}<FieldHelp field="funderType" /></span> : undefined}
>
<OpenAlexLookupFilter
selected={funderIds}
onChange={(next) => set("funding", m.funding.filter((f) => next.includes(funderChip(f.funder))))}
Expand All @@ -832,7 +838,7 @@ export function DetailsStep({
{funders.shown.map((f, at) => {
const i = funders.offset + at;
return (
<li key={funderChip(f.funder)} className="grid grid-cols-[minmax(0,1fr)] items-center gap-2 px-3 py-2.5 @2xl:grid-cols-[minmax(0,14rem)_minmax(0,1fr)]">
<li key={funderChip(f.funder)} className={cn("grid grid-cols-[minmax(0,1fr)] items-center gap-2 px-3 py-2.5", registrars?.docid ? "@2xl:grid-cols-[minmax(0,14rem)_minmax(0,1fr)_auto]" : "@2xl:grid-cols-[minmax(0,14rem)_minmax(0,1fr)]")}>
<span className="flex min-w-0 items-center gap-1">
{/* The full name shows on hover once the ROR mark beside it leaves too little room for it. */}
<TooltipHint label={f.funder.name} onlyWhenClipped>
Expand All @@ -849,6 +855,21 @@ export function DetailsStep({
label={t("addGrant", { name: f.funder.name })}
mono
/>
{/* Only DOCiD records what kind of funder it is: a grantor unless its author says otherwise. */}
{registrars?.docid ? (
<Select value={f.type ?? "grantor"} onValueChange={(type) => set("funding", m.funding.map((x, n) => (n === i ? { ...x, type: type as FunderType } : x)))}>
<SelectTrigger size="sm" className="w-full @2xl:w-36" aria-label={t("funderTypeOf", { name: f.funder.name })}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{FUNDER_TYPES.map((type) => (
<SelectItem key={type} value={type}>
{t(`funderTypes.${type}`)}
</SelectItem>
))}
</SelectContent>
</Select>
) : null}
</li>
);
})}
Expand Down
30 changes: 19 additions & 11 deletions components/reports/field-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,36 @@ type Help = {
filled?: keyof typeof FILLED;
entry?: keyof typeof ENTRY;
sources?: readonly SourceKey[];
/** Whether each registrar is sent it; a part that is never sent anywhere, such as a step, says neither. */
sent?: { crossref: boolean; zenodo: boolean };
/** Whether each registrar is sent it; a part that is never sent anywhere, such as a step, says neither. DOCiD is sent only what says so. */
sent?: { crossref: boolean; zenodo: boolean; docid?: true };
};
const BOTH = { crossref: true, zenodo: true } as const;
/** Sent to all three: DOCiD takes a report's title, abstract, authors (with their ORCID iDs and affiliations), kind and funders. */
const ALL = { crossref: true, zenodo: true, docid: true } as const;

/** Each part's facts. Its title, what it is and its note are in messages/ under publishReports.help.parts. */
const HELP = {
title: { filled: "pdf", entry: "typed", sent: BOTH },
title: { filled: "pdf", entry: "typed", sent: ALL },
subtitle: { note: true, filled: "pdf", entry: "typed", sent: BOTH },
type: { note: true, filled: "pdf", entry: "list", sources: ["openalexWorkTypes", "zenodoTypes", "crossrefReports"], sent: { crossref: false, zenodo: true } },
type: { note: true, filled: "pdf", entry: "list", sources: ["openalexWorkTypes", "zenodoTypes", "crossrefReports"], sent: { crossref: false, zenodo: true, docid: true } },
language: { filled: "pdf", entry: "list", sources: ["iso639"], sent: BOTH },
date: { note: true, filled: "pdf", entry: "typed", sent: BOTH },
licence: { sources: ["ccLicences"], sent: BOTH },
authors: { note: true, filled: "pdf", entry: "typed", sources: ["crossrefContributors"], sent: BOTH },
name: { note: true, filled: "pdf", entry: "typed", sent: BOTH },
authors: { note: true, filled: "pdf", entry: "typed", sources: ["crossrefContributors"], sent: ALL },
name: { note: true, filled: "pdf", entry: "typed", sent: ALL },
kind: { note: true, filled: "author", entry: "list", sources: ["crossrefRoles"], sent: BOTH },
orcid: { note: true, filled: "matched", entry: "either", sources: ["orcid", "orcidRegister"], sent: BOTH },
affiliations: { note: true, filled: "matched", entry: "either", sources: ["openalexInstitutions", "ror", "rorAdd"], sent: BOTH },
orcid: { note: true, filled: "matched", entry: "either", sources: ["orcid", "orcidRegister"], sent: ALL },
affiliations: { note: true, filled: "matched", entry: "either", sources: ["openalexInstitutions", "ror", "rorAdd"], sent: ALL },
contributions: { note: true, filled: "pdf", entry: "list", sources: ["credit"], sent: { crossref: true, zenodo: false } },
corresponding: { note: true, filled: "pdf", entry: "toggle", sources: ["crossrefRoles"], sent: BOTH },
abstract: { note: true, filled: "pdf", entry: "typed", sources: ["crossrefAbstracts"], sent: BOTH },
abstract: { note: true, filled: "pdf", entry: "typed", sources: ["crossrefAbstracts"], sent: ALL },
topics: { note: true, filled: "classified", entry: "list", sources: ["openalexTopics"], sent: { crossref: false, zenodo: true } },
keywords: { note: true, filled: "pdf", entry: "typed", sent: { crossref: false, zenodo: true } },
sdgs: { note: true, filled: "judged", entry: "list", sources: ["sdgs"], sent: { crossref: false, zenodo: true } },
design: { note: true, filled: "judged", entry: "list", sources: ["openalexDesigns"], sent: { crossref: false, zenodo: true } },
places: { filled: "judged", entry: "list", sources: ["iso3166"], sent: { crossref: false, zenodo: true } },
funding: { note: true, filled: "matched", entry: "either", sources: ["openalexFunders", "rorFunders", "funderRegistry", "rorAdd"], sent: BOTH },
funding: { note: true, filled: "matched", entry: "either", sources: ["openalexFunders", "rorFunders", "funderRegistry", "rorAdd"], sent: ALL },
funderType: { note: true, entry: "list", sent: { crossref: false, zenodo: false, docid: true } },
references: { note: true, filled: "pdf", entry: "pasted", sources: ["doi", "crossrefReferences"], sent: BOTH },
links: { note: true, filled: "pdf", entry: "either", sources: ["crossrefRelations"], sent: BOTH },
agreement: { note: true, sources: ["ccLicences"] },
Expand All @@ -100,7 +103,7 @@ const HELP = {
export type HelpKey = keyof typeof HELP;

/** The registrars a report is sent to, as its series has them set: a "?" leaves out the one that isn't used. */
const Registrars = createContext<{ crossref: boolean; zenodo: boolean }>(BOTH);
const Registrars = createContext<{ crossref: boolean; zenodo: boolean; docid?: boolean | undefined }>(BOTH);
export const RegistrarsProvider = Registrars.Provider;

const MARK: Record<Mark, ReactNode> = {
Expand Down Expand Up @@ -241,6 +244,11 @@ export function FieldHelp({
<FadeImage src="/brands/zenodo.svg" className="h-4 w-11" />
</Taker>
) : null}
{registrars.docid ? (
<Taker takes={help.sent.docid === true} name="DOCiD" does={t("does.docid")} href="https://docid.africapidalliance.org/">
<FadeImage src="/brands/docid.png" className="h-4 w-[58px]" />
</Taker>
) : null}
<Taker takes name="Openscholar" does={t("does.openscholar")}>
<LogoMark className="size-4" />
Openscholar
Expand Down
15 changes: 4 additions & 11 deletions convex/evidenceLibraries/publicationCredentialVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,12 @@ const DOCID_ENDPOINT = "https://docid.africapidalliance.org";
export const docidClient = () =>
new DocidApiClient({ endpoint: DOCID_ENDPOINT, fetch: (url, init) => fetch(url, { ...init, headers: { ...init.headers, "User-Agent": userAgent }, signal: AbortSignal.timeout(20_000) }) });

export type DocidOption = { id: number; name: string };
export type DocidLists = { resourceTypes: DocidOption[]; publicationTypes: DocidOption[]; funderTypes: DocidOption[] };

/**
* Signs in to DOCiD and reads the lists its deposits take ids from. The resource types are only the ones the account
* may use: DOCiD filters them by its category, and an account it hasn't allowed any gets none.
*/
export async function docidLists(email: string, password: string): Promise<DocidLists> {
export async function docidLists(email: string, password: string) {
const { token } = await docidClient().signIn({ email, password });
const read = async (list: string, name: string) => {
const response = await fetch(`${DOCID_ENDPOINT}/api/v1/publications/get-list-${list}`, { headers: { Authorization: `Bearer ${token}`, Accept: "application/json", "User-Agent": userAgent }, signal: AbortSignal.timeout(20_000) });
Expand Down Expand Up @@ -275,15 +273,10 @@ export async function verifiedPublication(
settings.crossref.mode === "sandbox",
);
if (settings.docid?.mode === "custom") {
const { email, resourceTypeId, publicationTypeId, funderTypeId } = settings.docid;
const { email } = settings.docid;
if (!email || !credentials.docidPassword) throw new Error("Give the email and password of the DOCiD account.");
// Signing in checks the account; each type picked must be one of DOCiD's own, and a resource type one it allows.
const lists = await docidLists(email, credentials.docidPassword);
const known = (id: number | undefined, options: DocidOption[]) => id === undefined || options.some((option) => option.id === id);
if (!known(resourceTypeId, lists.resourceTypes)) throw new Error("Your DOCiD account may not use this resource type. Pick one from the list.");
if (!known(publicationTypeId, lists.publicationTypes)) throw new Error("DOCiD has no such file type. Pick one from the list.");
if (!known(funderTypeId, lists.funderTypes)) throw new Error("DOCiD has no such funder type. Pick one from the list.");
settings.docid.options = lists;
// Signing in checks the account; its lists are kept, as each deposit finds its types in them.
settings.docid.options = await docidLists(email, credentials.docidPassword);
}
return { settings, credentials, custom };
}
Expand Down
7 changes: 2 additions & 5 deletions convex/evidenceLibraries/publicationValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ export const publicationSettingsValidator = v.object({
/**
* DOCiD, the Africa PID Alliance's Handles (plans/identifier-services): Openscholar Reports' account only, as
* communities show the DOCiDs their records come with and never register one. It has no test service, so it is
* off or a real account. The type ids are DOCiD's own, read from its lists with the account.
* off or a real account. Its types are mapped from each report, by name, against DOCiD's lists.
*/
docid: v.optional(
v.object({
mode: v.union(v.literal("off"), v.literal("custom")),
email: v.string(),
resourceTypeId: v.optional(v.number()),
publicationTypeId: v.optional(v.number()),
funderTypeId: v.optional(v.number()),
/** DOCiD's lists as the account saw them when last verified, for the pickers; written by the server only. */
/** DOCiD's lists as the account saw them when last verified, which deposits find their types in; written by the server only. */
options: v.optional(
v.object({
resourceTypes: capped(v.array(v.object({ id: v.number(), name: v.string() })), DOCID_OPTIONS_MAX),
Expand Down
2 changes: 1 addition & 1 deletion convex/reports/identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { refused, row, setup, type World } from "./reports.test-support";
async function withDocid(world: World, identifiers: Identifiers) {
await world.t.run(async (ctx) => {
const settings = (await ctx.db.query("reportSettings").first())!;
await ctx.db.patch("reportSettings", settings._id, { identifiers, publication: { ...settings.publication, docid: { mode: "custom", email: "docid@test.local", resourceTypeId: 18, publicationTypeId: 5, funderTypeId: 1 } } });
await ctx.db.patch("reportSettings", settings._id, { identifiers, publication: { ...settings.publication, docid: { mode: "custom", email: "docid@test.local", options: { resourceTypes: [{ id: 21, name: "Manuscripts" }], publicationTypes: [{ id: 5, name: "Monograph" }], funderTypes: [{ id: 1, name: "Grantor" }] } } } });
});
}

Expand Down
Loading
Loading