diff --git a/apps/studio/src/i18n/de.json b/apps/studio/src/i18n/de.json index 3e61c5ce..978e7945 100644 --- a/apps/studio/src/i18n/de.json +++ b/apps/studio/src/i18n/de.json @@ -1238,6 +1238,7 @@ "missingTheme": "Themen: {theme} fehlt.", "missingContact": "Kontakt: Der der Bibliothek, {contact}, ist nicht angegeben. Eine Veröffentlichung für die Bibliothek nennt ihn, keine E-Mail-Adresse.", "emailNamed": "Nennt eine E-Mail-Adresse: Eine Veröffentlichung für die Bibliothek nennt keine E-Mail-Adresse, nur den Kontakt der Bibliothek.", + "contactAmbiguous": "Kontakt: Nennt mehr als einen Kontakt oder einen Kontakt mit mehr als einer Webseite, sodass Lernende keinen haben, an den sie einen Fehler melden können. Gib den Kontakt erneut ein, um einen zu behalten.", "required": "{field}: noch nicht angegeben.", "previousUnread": "Die Ausgabe, auf die sie folgt, {previous}, konnte nicht gelesen werden, daher wird nichts mit ihr verglichen. Prüfe später noch einmal.", "libraryUnread": "Der Index der Bibliothek konnte nicht gelesen werden, daher wird der Platz des Entwurfs in der Bibliothek nicht geprüft. Prüfe später noch einmal.", diff --git a/apps/studio/src/i18n/en.json b/apps/studio/src/i18n/en.json index 2925fa4c..bbda1e74 100644 --- a/apps/studio/src/i18n/en.json +++ b/apps/studio/src/i18n/en.json @@ -1238,6 +1238,7 @@ "missingTheme": "Themes: {theme} is missing.", "missingContact": "Contact: the library's, {contact}, is not stated. A release for the library names it, not an email.", "emailNamed": "Names an email: a release for the library names no one's email, only the library's contact.", + "contactAmbiguous": "Contact: names more than one contact, or a contact with more than one web page, so learners get none to report a mistake to. Enter the contact again to keep one.", "required": "{field}: not stated yet.", "previousUnread": "The release it follows, {previous}, could not be read, so nothing is checked against it. Check again later.", "libraryUnread": "The library's index could not be read, so the draft's place in the library is not checked. Check again later.", diff --git a/apps/studio/src/i18n/es.json b/apps/studio/src/i18n/es.json index f7814a15..afed6a7b 100644 --- a/apps/studio/src/i18n/es.json +++ b/apps/studio/src/i18n/es.json @@ -1308,6 +1308,7 @@ "missingTheme": "Temas: falta {theme}.", "missingContact": "Contacto: no se indica el de la biblioteca, {contact}. Una publicación para la biblioteca lo indica, no un correo electrónico.", "emailNamed": "Indica un correo electrónico: una publicación para la biblioteca no indica el correo de nadie, solo el contacto de la biblioteca.", + "contactAmbiguous": "Contacto: indica más de un contacto, o un contacto con más de una página web, así que los estudiantes no tienen ninguno al que informar de un error. Vuelve a escribir el contacto para quedarte con uno.", "required": "{field}: aún no se ha indicado.", "previousUnread": "No se pudo leer la publicación a la que sigue, {previous}, así que no se comprueba nada con ella. Vuelve a comprobarlo más tarde.", "libraryUnread": "No se pudo leer el índice de la biblioteca, así que no se comprueba la ubicación del borrador en la biblioteca. Vuelve a comprobarlo más tarde.", diff --git a/apps/studio/src/i18n/fr.json b/apps/studio/src/i18n/fr.json index 78c19a2f..749ba238 100644 --- a/apps/studio/src/i18n/fr.json +++ b/apps/studio/src/i18n/fr.json @@ -1308,6 +1308,7 @@ "missingTheme": "Thèmes : {theme} est manquant.", "missingContact": "Contact : celui de la bibliothèque, {contact}, n'est pas indiqué. Une publication pour la bibliothèque l'indique, pas une adresse e-mail.", "emailNamed": "Indique une adresse e-mail : une publication pour la bibliothèque n'indique l'adresse e-mail de personne, seulement le contact de la bibliothèque.", + "contactAmbiguous": "Contact : indique plus d’un contact, ou un contact avec plus d’une page web, si bien que les apprenants n’en ont aucun à qui signaler une erreur. Saisissez de nouveau le contact pour n’en garder qu’un.", "required": "{field} : à renseigner.", "previousUnread": "Impossible de lire la publication qu’elle suit, {previous} : rien n’est donc vérifié par rapport à elle. Vérifiez à nouveau plus tard.", "libraryUnread": "Impossible de lire l’index de la bibliothèque : la place du brouillon dans la bibliothèque n’est donc pas vérifiée. Vérifiez à nouveau plus tard.", diff --git a/apps/studio/src/i18n/ko.json b/apps/studio/src/i18n/ko.json index 2ab63a15..403b2baa 100644 --- a/apps/studio/src/i18n/ko.json +++ b/apps/studio/src/i18n/ko.json @@ -1168,6 +1168,7 @@ "missingTheme": "주제: {theme}이(가) 없어요.", "missingContact": "연락처: 라이브러리 연락처 {contact}이(가) 없어요. 라이브러리용 릴리스는 이메일이 아니라 이 연락처를 적어요.", "emailNamed": "이메일이 있어요: 라이브러리용 릴리스에는 누구의 이메일도 넣지 않고 라이브러리 연락처만 적어요.", + "contactAmbiguous": "연락처: 연락처가 둘 이상이거나 웹 페이지가 둘 이상인 연락처가 있어서, 학습자에게는 실수를 알릴 연락처가 없어요. 하나만 남기려면 연락처를 다시 입력하세요.", "required": "{field}: 아직 지정되지 않았어요.", "previousUnread": "이어받는 이전 릴리스 {previous}을(를) 읽을 수 없어서, 그에 대해서는 아무것도 검사하지 않았어요. 나중에 다시 검사해 주세요.", "libraryUnread": "덱 라이브러리 색인을 읽을 수 없어서, 덱 라이브러리에서 초안의 위치는 검사하지 않았어요. 나중에 다시 검사해 주세요.", diff --git a/apps/studio/src/i18n/sv.json b/apps/studio/src/i18n/sv.json index 617472be..9dcc40a9 100644 --- a/apps/studio/src/i18n/sv.json +++ b/apps/studio/src/i18n/sv.json @@ -1238,6 +1238,7 @@ "missingTheme": "Teman: saknar {theme}.", "missingContact": "Kontakt: bibliotekets, {contact}, anges inte. En utgåva för biblioteket anger den, inte en e-postadress.", "emailNamed": "Anger en e-postadress: en utgåva för biblioteket anger ingens e-postadress, bara bibliotekets kontakt.", + "contactAmbiguous": "Kontakt: anger mer än en kontakt, eller en kontakt med mer än en webbsida, så elever får ingen att rapportera ett fel till. Ange kontakten igen för att behålla en.", "required": "{field}: inte angivet än.", "previousUnread": "Utgåvan den följer, {previous}, kunde inte läsas, så inget kontrolleras mot den. Kontrollera igen senare.", "libraryUnread": "Bibliotekets index kunde inte läsas, så utkastets plats i biblioteket kontrolleras inte. Kontrollera igen senare.", diff --git a/apps/studio/src/ui/problemText.test.ts b/apps/studio/src/ui/problemText.test.ts index 968d5605..063863c7 100644 --- a/apps/studio/src/ui/problemText.test.ts +++ b/apps/studio/src/ui/problemText.test.ts @@ -232,6 +232,9 @@ describe("problemMessage", () => { expect(say({ code: "emailNamed", params: {} })).toBe( "Names an email: a release for the library names no one's email, only the library's contact.", ); + expect(say({ code: "contactAmbiguous", params: {} })).toBe( + "Contact: names more than one contact, or a contact with more than one web page, so learners get none to report a mistake to. Enter the contact again to keep one.", + ); expect(say({ code: "required", params: {} }, `${DCTERMS}publisher`)).toBe( "Publisher: not stated yet.", ); diff --git a/apps/studio/src/ui/problemText.ts b/apps/studio/src/ui/problemText.ts index e1c88adb..564c6441 100644 --- a/apps/studio/src/ui/problemText.ts +++ b/apps/studio/src/ui/problemText.ts @@ -266,6 +266,7 @@ export function problemMessage( case "missingContact": return t(key, { contact: problem.params.contact }); case "emailNamed": + case "contactAmbiguous": return t(key); case "required": return t(key, { field }); diff --git a/docs/deck-library.md b/docs/deck-library.md index 2aa638e2..0f03d662 100644 --- a/docs/deck-library.md +++ b/docs/deck-library.md @@ -1340,11 +1340,15 @@ reported (`ReportPlace`): no dropdown from the query, so "What is it" is left to the learner. - **A release from a link** leads to the web page its contact names (`dcat:contactPoint`'s `vcard:hasURL`, read with the release as - `LibraryDeckContent.contact`), unfilled. The release names this page + `LibraryDeckContent.contact`), unfilled. That's the one contact + point, named or blank, with one web page, as the Studio reads it + ([studio.md](studio.md#the-releases-metadata-and-provenance)); a + release with more than one point, or a point with more than one web + page, names no contact. The release names this page itself, so the link follows it as a release's other links are followed (`DataLink`, [Safety](markdown.md#safety)): http(s) with no `user@` before the host, and the host shown beside the link. With - none, only an email, or an address that rule refuses, there's no link + no contact, only an email, or an address that rule refuses, there's no link (never the library's tracker). - **A deck the learner wrote**, with no release, has no link, nor has a Studio [trial](studio.md#the-trial) (`createTrialUseCases`). diff --git a/docs/studio.md b/docs/studio.md index 8b2e9b84..9fd4a47f 100644 --- a/docs/studio.md +++ b/docs/studio.md @@ -2069,6 +2069,11 @@ becomes: the rules `npm run library:check` runs on `decks/` a series, a distribution, the theme EDUC, and each chapter's and step's fields the draft shapes relax; - the policy's curation (`curationProblems`); + - its one contact, in either policy (`contactPointProblems`): a + warning of more than one contact point, or a point with more than + one web page (`contactAmbiguous`). Learners read such a release as + naming no contact, so **Report a mistake** has no page to lead to + ([deck-library.md](deck-library.md#reporting-a-mistake)); - how the release says it was made (`provenanceProblems`, [below](#what-the-check-asks-of-a-releases-provenance)); - the draft's series (the pod policy only; `ownSeriesProblems` in @@ -2360,7 +2365,12 @@ the library's releases are the release's one `dcat:contactPoint`, `#contact`, a `vcard:Kind` with that `vcard:hasURL` ([deck-library.md](deck-library.md#contact)). It's saved once it's an http(s) address, and the contact it - replaces goes with what it stated. **Use the library's contact** + replaces goes with what it stated, every contact point the release + named. The field reads the contact as learners do (`contactOf`): + the one contact point, named or blank, with one web page. A release + that names more than one contact point, or a point with more than + one web page, names no contact, and the field is empty; the release + check warns of it (`contactAmbiguous`). **Use the library's contact** fills in `LIBRARY_CONTACT` ([curationRules.ts](../packages/domain/src/release/curationRules.ts)). The app reads it to say where a mistake is reported diff --git a/packages/domain/src/release/curationRules.test.ts b/packages/domain/src/release/curationRules.test.ts index 62813758..8171e86a 100644 --- a/packages/domain/src/release/curationRules.test.ts +++ b/packages/domain/src/release/curationRules.test.ts @@ -6,7 +6,13 @@ import { expect, it } from "vitest"; import { LOCALES } from "../locale"; import { growth } from "../testing/growth"; import { at, card, iri, model, RELEASE, text } from "../testing/releaseModel"; -import { curationProblems, LIBRARY_CONTACT, podPolicy, repoPolicy } from "./curationRules"; +import { + contactPointProblems, + curationProblems, + LIBRARY_CONTACT, + podPolicy, + repoPolicy, +} from "./curationRules"; const SM = "https://solid-memo.com/ns/vocab/v1.ttl#"; const EDUC = "http://publications.europa.eu/resource/authority/data-theme/EDUC"; @@ -112,6 +118,38 @@ it("asks the library's contact, a vcard:Kind, and no one's email", () => { expect(found({ emails })).toHaveLength(emails.length); }); +it("warns of more than one contact point, or a point with more than one web page (GHSA-g8xv-c484-62vx)", () => { + const found = (contacts: ReturnType["contacts"]) => + contactPointProblems(model({ contacts })).map(({ code, subject, field, severity }) => ({ + code, + subject, + field, + severity, + })); + const ambiguous = [ + { + code: "contactAmbiguous", + subject: RELEASE, + field: "http://www.w3.org/ns/dcat#contactPoint", + severity: "warning", + }, + ]; + expect(found([])).toEqual([]); + expect(found([contact(LIBRARY_CONTACT)])).toEqual([]); + // A page that is text is no page learners follow. + expect( + found([{ ...contact(LIBRARY_CONTACT), urls: [iri(LIBRARY_CONTACT), text("x", "")] }]), + ).toEqual([]); + expect(found([contact("https://example.com/other"), contact(LIBRARY_CONTACT)])).toEqual( + ambiguous, + ); + expect( + found([ + { ...contact(LIBRARY_CONTACT), urls: [iri(LIBRARY_CONTACT), iri("https://x.example/")] }, + ]), + ).toEqual(ambiguous); +}); + it("asks a description of each picture in English and every language its card's text is in", () => { const picture = "https://example.com/flag.svg"; const pictured = { diff --git a/packages/domain/src/release/curationRules.ts b/packages/domain/src/release/curationRules.ts index cede5be5..3d4684a9 100644 --- a/packages/domain/src/release/curationRules.ts +++ b/packages/domain/src/release/curationRules.ts @@ -192,6 +192,27 @@ function pictureProblems(card: ReleaseCard): ReleaseProblem[] { ]; } +/** + * A release that names more than one contact point, or a point that + * names more than one web page, whatever the policy: the Studio and + * learners read it as naming no contact (`contactOf`), so "Report a + * mistake" has no page to lead to, and the creator is told, as the + * Contact field shows none. A warning: setting the contact again keeps + * one (GHSA-g8xv-c484-62vx). + */ +export function contactPointProblems(model: ReleaseModel): ReleaseProblem[] { + const pages = model.contacts[0]?.urls.filter((url) => url.kind === "iri") ?? []; + return model.contacts.length > 1 || pages.length > 1 + ? [ + problem( + model.url, + { code: "contactAmbiguous", params: {} }, + { field: `${DCAT_NS}contactPoint`, severity: "warning" }, + ), + ] + : []; +} + /** A release's contact, unless it names `contact`, and each email it names. */ function contactProblems(model: ReleaseModel, contact: string): ReleaseProblem[] { const named = model.contacts.some( diff --git a/packages/domain/src/release/problems.ts b/packages/domain/src/release/problems.ts index b3bd97f0..5ac3580f 100644 --- a/packages/domain/src/release/problems.ts +++ b/packages/domain/src/release/problems.ts @@ -140,6 +140,8 @@ export type CurationProblem = | { code: "missingContact"; params: { contact: string } } /** An email (foaf:mbox) of the subject, which the policy asks no release to name. */ | { code: "emailNamed"; params: Record } + /** More than one contact point (dcat:contactPoint), or a point with more than one web page (vcard:hasURL): learners read it as no contact (contactPointProblems). */ + | { code: "contactAmbiguous"; params: Record } /** A source that does not say what it is, whose it is, or on what terms it was used. */ | { code: "sourceUndescribed"; params: { missing: SourceDetail[] } } /** A source with more than one title, or a title or creator that is not plain text, which learners would read otherwise than the Studio shows it. */ diff --git a/packages/domain/src/release/releaseCheck.test.ts b/packages/domain/src/release/releaseCheck.test.ts index 4a4a89a9..29baf3b1 100644 --- a/packages/domain/src/release/releaseCheck.test.ts +++ b/packages/domain/src/release/releaseCheck.test.ts @@ -72,6 +72,30 @@ describe("ruleProblems", () => { }); }); +describe("ruleProblems' contact", () => { + it("names, in a pod and the library, a release whose contact learners would read as none", () => { + const model = draftReleaseModel(courseDraft()); + const point = (url: string) => ({ + point: { kind: "iri" as const, value: `${model.url}#contact` }, + types: [], + urls: [{ kind: "iri" as const, value: url }], + }); + const two = { ...model, contacts: [point("https://a.example/"), point("https://b.example/")] }; + for (const policy of ["pod", "library"] as const) { + expect(ruleProblems(two, policy).filter((p) => p.code === "contactAmbiguous")).toEqual([ + { + code: "contactAmbiguous", + params: {}, + subject: model.url, + field: `${DCAT}contactPoint`, + severity: "warning", + }, + ]); + } + expect(ruleProblems(model, "pod").map((p) => p.code)).not.toContain("contactAmbiguous"); + }); +}); + describe("ruleProblems' growth", () => { it("names a problem of each of many cards, each as long as a term may be, once, in time linear in them", () => { // V8 hashes a string longer than 16,383 characters by its length @@ -388,6 +412,10 @@ describe("problemTarget", () => { screen: "release", field: "contact", }); + expect(target(DRAFT, { field: `${DCAT}contactPoint`, code: "contactAmbiguous" })).toEqual({ + screen: "release", + field: "contact", + }); expect(target(DRAFT, { field: `${DCTERMS}language` })).toEqual({ screen: "release", field: "languages", diff --git a/packages/domain/src/release/releaseCheck.ts b/packages/domain/src/release/releaseCheck.ts index da549b95..2d334153 100644 --- a/packages/domain/src/release/releaseCheck.ts +++ b/packages/domain/src/release/releaseCheck.ts @@ -7,7 +7,13 @@ import type { CardTextPart } from "../deck.ts"; import { jsonPath, PathMap } from "../pathKeys.ts"; import { ownSeriesProblems } from "./continuityRules.ts"; import { courseProblems, readinessProblems } from "./courseRules.ts"; -import { curationProblems, podPolicy, repoPolicy, type LibraryPolicy } from "./curationRules.ts"; +import { + contactPointProblems, + curationProblems, + podPolicy, + repoPolicy, + type LibraryPolicy, +} from "./curationRules.ts"; import { metadataProblems, pathProblems, @@ -80,14 +86,16 @@ function distinct(problems: readonly ReleaseProblem[]): ReleaseProblem[] { /** * The rules of a release read from its data alone: its course's, its - * readiness, the policy's curation, its provenance's, and in a pod its - * series, its own when it follows no release (ownSeriesProblems). + * readiness, the policy's curation, its one contact, its provenance's, + * and in a pod its series, its own when it follows no release + * (ownSeriesProblems). */ export function ruleProblems(model: ReleaseModel, policy: CheckPolicy): ReleaseProblem[] { return distinct([ ...courseProblems(model), ...readinessProblems(model), ...curationProblems(model, curationOf(policy)), + ...contactPointProblems(model), ...provenanceProblems(model), ...(policy === "pod" ? ownSeriesProblems(model) : []), ]); diff --git a/packages/domain/src/release/releaseDraft.test.ts b/packages/domain/src/release/releaseDraft.test.ts index 156d61d5..3f6dd425 100644 --- a/packages/domain/src/release/releaseDraft.test.ts +++ b/packages/domain/src/release/releaseDraft.test.ts @@ -44,6 +44,7 @@ import { unsupportedIdOf, type CheckActivity, type DraftChange, + type DraftTriple, type ReleaseDraft, } from "./releaseDraft.ts"; import { rebaseDraft } from "./releaseToDraft.ts"; @@ -1170,6 +1171,7 @@ describe("applyDraftChange", () => { describe("the contact", () => { const VCARD = "http://www.w3.org/2006/vcard/ns#"; const POINT = "http://www.w3.org/ns/dcat#contactPoint"; + const XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; const contact = (id: string, url: string) => [ link(DRAFT, POINT, of(id)), link(of(id), RDF_TYPE, `${VCARD}Kind`), @@ -1227,26 +1229,108 @@ describe("the contact", () => { expect(set.triples.slice(-3)).toEqual(contact("contact-3", "https://a.example/")); }); - it("is the page of the first contact point that names one", () => { + it("is the page of its one contact point, named or blank, that names one page", () => { const draft = courseDraft(); - const named = { + const blank = { kind: "blank" as const, value: "b1" }; + const with_ = (...triples: DraftTriple[]) => ({ ...draft, - triples: [ - ...draft.triples, - link(DRAFT, POINT, of("first")), - link(of("first"), `${VCARD}hasEmail`, "mailto:a@example.org"), - ...contact("second", "https://b.example/"), - ...contact("third", "https://c.example/"), - ], - }; - expect(contactOf(named)).toBe("https://b.example/"); + triples: [...draft.triples, ...triples], + }); + expect(contactOf(with_(...contact("contact", "https://a.example/")))).toBe( + "https://a.example/", + ); + expect( + contactOf( + with_( + { subject: DRAFT, predicate: POINT, object: blank }, + { + subject: "_:b1", + predicate: `${VCARD}hasURL`, + object: { kind: "iri", value: "https://a.example/" }, + }, + ), + ), + ).toBe("https://a.example/"); + // A page that is no address, beside the one that is, is not a page learners follow. + expect( + contactOf( + with_(...contact("contact", "https://a.example/"), { + subject: of("contact"), + predicate: `${VCARD}hasURL`, + object: { + kind: "literal", + value: "https://b.example/", + language: "", + datatype: XSD_STRING, + }, + }), + ), + ).toBe("https://a.example/"); + }); + + it("is none for more than one contact point or page, or a point that is text, as learners read it", () => { + const draft = courseDraft(); + const with_ = (...triples: DraftTriple[]) => ({ + ...draft, + triples: [...draft.triples, ...triples], + }); + // A blank point with one page, and a named one with another (GHSA-g8xv-c484-62vx). + expect( + contactOf( + with_( + { subject: DRAFT, predicate: POINT, object: { kind: "blank", value: "b1" } }, + { + subject: "_:b1", + predicate: `${VCARD}hasURL`, + object: { kind: "iri", value: "https://a.example/" }, + }, + ...contact("contact", "https://b.example/"), + ), + ), + ).toBeNull(); + expect( + contactOf( + with_( + ...contact("first", "https://a.example/"), + ...contact("second", "https://b.example/"), + ), + ), + ).toBeNull(); + expect( + contactOf( + with_( + ...contact("contact", "https://a.example/"), + link(of("contact"), `${VCARD}hasURL`, "https://b.example/"), + ), + ), + ).toBeNull(); + expect( + contactOf( + with_( + link(DRAFT, POINT, of("first")), + link(of("first"), `${VCARD}hasEmail`, "mailto:a@example.org"), + ), + ), + ).toBeNull(); + expect( + contactOf( + with_( + { + subject: DRAFT, + predicate: POINT, + object: { kind: "literal", value: of("contact"), language: "", datatype: XSD_STRING }, + }, + link(of("contact"), `${VCARD}hasURL`, "https://a.example/"), + ), + ), + ).toBeNull(); }); it("is found in time that grows with the contact points, not their square", () => { - // Eight times the contact points, none naming a page, must take less - // than four times as long as an eighth of them done eight times over - // (testing.md): looking through every statement for each point would - // take about eight times as long. + // Eight times the contact points must take less than four times as + // long as an eighth of them done eight times over (testing.md): + // looking through every statement for each point would take about + // eight times as long. const points = (count: number): ReleaseDraft => { const draft = courseDraft(); return { diff --git a/packages/domain/src/release/releaseDraft.ts b/packages/domain/src/release/releaseDraft.ts index a228561b..a45bcd5a 100644 --- a/packages/domain/src/release/releaseDraft.ts +++ b/packages/domain/src/release/releaseDraft.ts @@ -1587,17 +1587,30 @@ function contactPointsOf(draft: ReleaseDraft): string[] { ); } -/** The web page the release's contact names (its first contact point's vcard:hasURL); null when it names none. */ +/** + * The web page the release's contact names: the vcard:hasURL of its one + * dcat:contactPoint, named or blank, when that point names one page. + * Null when it names none, or more than one point or page, which + * learners read as no contact too (`contactOf` in the solid package's + * libraryMapper.ts), so the Studio never shows a contact other than the + * one "Report a mistake" leads to; the release check says so + * (`contactAmbiguous`). + */ export function contactOf(draft: ReleaseDraft): string | null { - const points = contactPointsOf(draft); - const of = triplesBySubject(draft.triples, new Set(points)); - for (const point of points) { - const url = of - .get(point) - ?.find((triple) => triple.predicate === `${VCARD}hasURL` && triple.object.kind === "iri"); - if (url !== undefined) return url.object.value; - } - return null; + const points = draft.triples.filter( + (triple) => triple.subject === draft.url && triple.predicate === DCAT_CONTACT_POINT, + ); + if (points.length !== 1) return null; + const { object } = points[0]!; + if (object.kind === "literal") return null; + const subject = object.kind === "blank" ? `_:${object.value}` : object.value; + const urls = draft.triples.filter( + (triple) => + triple.subject === subject && + triple.predicate === `${VCARD}hasURL` && + triple.object.kind === "iri", + ); + return urls.length === 1 ? urls[0]!.object.value : null; } /** diff --git a/packages/solid/src/mappers/libraryMapper.test.ts b/packages/solid/src/mappers/libraryMapper.test.ts index a46e7507..5f9662fe 100644 --- a/packages/solid/src/mappers/libraryMapper.test.ts +++ b/packages/solid/src/mappers/libraryMapper.test.ts @@ -481,6 +481,33 @@ ${base === DOC ? "" : ' a sm:Deck ; dcterms ).not.toHaveProperty("contact"); }); + it("reads a contact from its one point, named or blank, with one web page, and none from more (GHSA-g8xv-c484-62vx)", async () => { + const url = "https://alice.example/solid-memo/main/releases/capitals/v2.ttl"; + const turtle = await readFile( + `${VOCAB_ROOT}fixtures/library-deck/v6/valid/library-standalone-release.ttl`, + "utf8", + ); + const VCARD = "http://www.w3.org/2006/vcard/ns#"; + const contactOf = async (statements: string) => + toLibraryDeckContent(url, await datasetOf(`${turtle}\n${statements}\n`, url)).contact; + const good = "https://good.example/issues"; + const other = "https://other.example/report"; + expect(await contactOf(`<> dcat:contactPoint [ <${VCARD}hasURL> <${good}> ] .`)).toBe(good); + expect( + await contactOf( + `<> dcat:contactPoint [ <${VCARD}hasURL> <${good}> ] , <#contact> .\n<#contact> <${VCARD}hasURL> <${other}> .`, + ), + ).toBeUndefined(); + expect( + await contactOf( + `<> dcat:contactPoint <#contact> .\n<#contact> <${VCARD}hasURL> <${good}> , <${other}> .`, + ), + ).toBeUndefined(); + expect( + await contactOf(`<> dcat:contactPoint "${good}" .\n<${good}> <${VCARD}hasURL> <${good}> .`), + ).toBeUndefined(); + }); + it("refuses a release at the guest's pod, or that links to it by an address in it (GHSA-hc3p-fpwj-fvjp)", async () => { const url = "https://alice.example/solid-memo/main/releases/capitals/v2.ttl"; const turtle = await readFile( diff --git a/packages/solid/src/mappers/libraryMapper.ts b/packages/solid/src/mappers/libraryMapper.ts index 087562e5..1d026078 100644 --- a/packages/solid/src/mappers/libraryMapper.ts +++ b/packages/solid/src/mappers/libraryMapper.ts @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: MIT +import type { Quad_Object } from "@rdfjs/types"; import { type Dataset, type Subject, @@ -9,6 +10,7 @@ import { getInteger, getStringNoLocale, getStringNoLocaleAll, + getTermAll, getThing, getThingAll, getUrl, @@ -135,15 +137,26 @@ function courseOf(release: Subject): { isCourse?: true } { /** * The web page a release's contact names (docs/deck-library.md, - * Contact): its dcat:contactPoint's vcard:hasURL, read from the - * release's own document. None when it names no contact, or a contact - * with no web page, such as the email the library's older versions name. + * Contact): the vcard:hasURL of its one dcat:contactPoint, named or + * blank, read from the release's own document. None when it names no + * contact, a contact with no web page, such as the email the library's + * older versions name, or more than one contact point or page: the + * Studio reads it the same way (`contactOf` in the domain's + * releaseDraft.ts), so "Report a mistake" never leads elsewhere than + * the contact the release's creator saw. */ function contactOf(release: Subject, dataset: Dataset): { contact?: string } { - const point = getUrl(release, DCAT.contactPoint); - const thing = point === null ? null : getThing(dataset, point); - const url = thing === null ? null : getUrl(thing, VCARD.hasURL); - return url === null ? {} : { contact: url }; + const points = getTermAll(release, DCAT.contactPoint); + if (points.length !== 1) return {}; + const thing = subjectAt(dataset, points[0]!); + const urls = thing === null ? [] : getUrlAll(thing, VCARD.hasURL); + return urls.length === 1 ? { contact: urls[0]! } : {}; +} + +/** The subject a term names in the dataset: an IRI's or a blank node's; null for a literal. */ +function subjectAt(dataset: Dataset, term: Quad_Object): Subject | null { + if (term.termType === "BlankNode") return getThing(dataset, `_:${term.value}`); + return term.termType === "NamedNode" ? getThing(dataset, term.value) : null; } /** A release by URL, with what the index says about it (maybe nothing). */ diff --git a/packages/solid/src/solidReleaseDraftRepository.test.ts b/packages/solid/src/solidReleaseDraftRepository.test.ts index 1fedb93e..93173348 100644 --- a/packages/solid/src/solidReleaseDraftRepository.test.ts +++ b/packages/solid/src/solidReleaseDraftRepository.test.ts @@ -16,6 +16,7 @@ import { ruleProblems } from "@solid-memo/domain/release/releaseCheck"; import { applyDraftChanges, blankDraft, + contactOf, iriIn, isRefusal, type DraftChange, @@ -34,7 +35,11 @@ import { MAX_CATALOG_LINKS } from "./catalogLinks"; import { RELEASE_LIMITS } from "./client/readLimits"; import { datasetFromQuads } from "./client/rdf"; import { turtleAt } from "./testing/contract/rdf"; -import { toLibraryCards, toStandaloneLibraryDeck } from "./mappers/libraryMapper"; +import { + toLibraryCards, + toLibraryDeckContent, + toStandaloneLibraryDeck, +} from "./mappers/libraryMapper"; import { draftQuads } from "./mappers/releaseDraftMapper"; import { DECKS, @@ -2074,6 +2079,50 @@ describe("a release with a card outside it (GHSA-67w8-qjpm-jhwp)", () => { }); }); +describe("a release with a contact point for the Studio and another for learners (GHSA-g8xv-c484-62vx)", () => { + // A blank point with one page before the release's own, which names another. + const text = readFileSync(join(DECKS_ROOT, "arabic-adjectives/v1.ttl"), "utf8") + .replace( + "dcat:contactPoint <#contact> ;", + "dcat:contactPoint [ a vcard:Kind ; vcard:hasURL ] , <#contact> ;", + ) + .replace( + "vcard:hasURL ", + "vcard:hasURL ", + ); + + it("is read as naming no contact by the Studio and by learners alike, and the check warns of it", async () => { + const pod = await draftPod(); + const summary = await pod.repository.create( + INSTANCE, + releaseToDraft( + await pod.repository.parseRelease(text, "turtle"), + draftUrlOf(INSTANCE, "arabic-adjectives", 1), + ), + ); + const { draft } = await pod.repository.read(summary.url); + expect(contactOf(draft)).toBeNull(); + expect( + ruleProblems(draftReleaseModel(draft), "pod").filter((p) => p.code === "contactAmbiguous"), + ).toMatchObject([{ subject: draft.url, severity: "warning" }]); + // What it would publish, as a learner reads it: no contact either. + const published = "https://creator.example/memo/releases/arabic/v1.ttl"; + const read = (one: ReleaseDraft) => + toLibraryDeckContent( + published, + datasetFromQuads(releaseQuadsOf(draftQuads(rebaseDraft(one, published)), published, NOW)), + ).contact; + expect(read(draft)).toBeUndefined(); + // Setting the contact keeps one, which both then read. + const set = applyDraftChanges(draft, [ + { kind: "setContact", url: "https://good.example/issues" }, + ]); + if (isRefusal(set)) throw new Error("refused"); + expect(contactOf(set)).toBe("https://good.example/issues"); + expect(read(set)).toBe("https://good.example/issues"); + }); +}); + describe("a class another app gives a draft's subject (GHSA-8hh7-p2ww-mpjf)", () => { const PALETTE = `${SM}Palette`; const OTHER = "http://example.org/Other";