Skip to content

Commit

Permalink
don't use mu-auth sudo queries
Browse files Browse the repository at this point in the history
  • Loading branch information
elpoelma committed Dec 10, 2024
1 parent af777b1 commit bc4f8ce
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 77 deletions.
3 changes: 1 addition & 2 deletions models/document-container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EditorDocument from "./editor-document";
import { sparqlEscapeUri, sparqlEscapeString } from "mu";
import { querySudo as query } from "@lblod/mu-auth-sudo";
import { sparqlEscapeUri, sparqlEscapeString, query } from "mu";

export default class DocumentContainer {
/** @type {string} */
Expand Down
3 changes: 2 additions & 1 deletion models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
sparqlEscapeDateTime,
// @ts-ignore
sparqlEscapeInt,
query,
update,
} from "mu";
import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo";

export const JOB_STATUSES = {
scheduled: "http://redpencil.data.gift/id/concept/JobStatus/scheduled",
Expand Down
49 changes: 23 additions & 26 deletions models/template-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
uuid as uuidv4,
sparqlEscapeDateTime,
sparqlEscapeString,
query,
update,
} from "mu";
import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo";
import fs from "fs";

export default class TemplateVersion {
Expand Down Expand Up @@ -57,29 +58,27 @@ export default class TemplateVersion {
PREFIX nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#>
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(uri)}
a gn:TemplateVersie;
a nfo:FileDataObject;
mu:uuid ${sparqlEscapeString(id)};
dct:title ${sparqlEscapeString(title)};
nfo:fileName ${sparqlEscapeString(fileName)};
dct:format ${sparqlEscapeString("application/html")};
nfo:fileSize ${fileSize};
dbpedia:extension ${sparqlEscapeString("html")};
nfo:fileCreated ${sparqlEscapeDateTime(now)};
prov:derivedFrom ${sparqlEscapeUri(derivedFrom)}.
${sparqlEscapeUri(uri)}
a gn:TemplateVersie;
a nfo:FileDataObject;
mu:uuid ${sparqlEscapeString(id)};
dct:title ${sparqlEscapeString(title)};
nfo:fileName ${sparqlEscapeString(fileName)};
dct:format ${sparqlEscapeString("application/html")};
nfo:fileSize ${fileSize};
dbpedia:extension ${sparqlEscapeString("html")};
nfo:fileCreated ${sparqlEscapeDateTime(now)};
prov:derivedFrom ${sparqlEscapeUri(derivedFrom)}.
${sparqlEscapeUri(physicalFileUri)}
a nfo:FileDataObject;
mu:uuid ${sparqlEscapeString(physicalFileUuid)};
nfo:fileName ${sparqlEscapeString(fileName)};
dct:format ${sparqlEscapeString("application/html")};
nfo:fileSize ${fileSize};
dbpedia:extension ${sparqlEscapeString("html")};
nfo:fileCreated ${sparqlEscapeDateTime(now)};
nie:dataSource ${sparqlEscapeUri(uri)}.
}
${sparqlEscapeUri(physicalFileUri)}
a nfo:FileDataObject;
mu:uuid ${sparqlEscapeString(physicalFileUuid)};
nfo:fileName ${sparqlEscapeString(fileName)};
dct:format ${sparqlEscapeString("application/html")};
nfo:fileSize ${fileSize};
dbpedia:extension ${sparqlEscapeString("html")};
nfo:fileCreated ${sparqlEscapeDateTime(now)};
nie:dataSource ${sparqlEscapeUri(uri)}.
}`;
await update(createTemplateQuery);
return new TemplateVersion({
Expand Down Expand Up @@ -144,9 +143,7 @@ export default class TemplateVersion {
PREFIX schema: <http://schema.org/>
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(this.uri)} schema:validThrough ${sparqlEscapeDateTime(now)}.
}
${sparqlEscapeUri(this.uri)} schema:validThrough ${sparqlEscapeDateTime(now)}.
}
`;
await update(myQuery);
Expand Down
29 changes: 14 additions & 15 deletions models/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { sparqlEscapeUri, uuid as uuidv4, sparqlEscapeString } from "mu";
import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo";
import {
sparqlEscapeUri,
uuid as uuidv4,
sparqlEscapeString,
query,
update,
} from "mu";
import TemplateVersion from "./template-version";

/**
Expand Down Expand Up @@ -44,12 +49,10 @@ export default class Template {
PREFIX prov: <http://www.w3.org/ns/prov#>
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(templateUri)} a gn:Template;
a ${sparqlEscapeUri(typeUri)};
prov:derivedFrom ${sparqlEscapeUri(derivedFrom)};
mu:uuid ${sparqlEscapeString(templateId)}.
}
${sparqlEscapeUri(templateUri)} a gn:Template;
a ${sparqlEscapeUri(typeUri)};
prov:derivedFrom ${sparqlEscapeUri(derivedFrom)};
mu:uuid ${sparqlEscapeString(templateId)}.
}
`;
await update(createTemplateQuery);
Expand Down Expand Up @@ -154,16 +157,12 @@ export default class Template {
PREFIX pav: <http://purl.org/pav/>
DELETE WHERE {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(this.uri)} pav:hasCurrentVersion ?v.
}
${sparqlEscapeUri(this.uri)} pav:hasCurrentVersion ?v.
};
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(this.uri)} pav:hasCurrentVersion ${sparqlEscapeUri(templateVersion.uri)};
pav:hasVersion ${sparqlEscapeUri(templateVersion.uri)}.
}
${sparqlEscapeUri(this.uri)} pav:hasCurrentVersion ${sparqlEscapeUri(templateVersion.uri)};
pav:hasVersion ${sparqlEscapeUri(templateVersion.uri)}.
}
`;
await update(myQuery);
Expand Down
7 changes: 2 additions & 5 deletions util/common-sparql.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { sparqlEscapeUri, sparqlEscapeString } from "mu";
import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo";
import { sparqlEscapeUri, sparqlEscapeString, query, update } from "mu";

export const getPublishedVersion = async (documentContainerUri) => {
const publishedVersionQuery = `
Expand Down Expand Up @@ -30,9 +29,7 @@ export const deletePublishedVersion = async (publishedVersionResults) => {
PREFIX pav: <http://purl.org/pav/>
DELETE WHERE {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(templateUri)} pav:hasCurrentVersion ?currentVersion.
}
${sparqlEscapeUri(templateUri)} pav:hasCurrentVersion ?currentVersion.
}
`;

Expand Down
52 changes: 24 additions & 28 deletions util/snippet-sparql.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ export const insertPublishedSnippetContainer = async ({
PREFIX prov: <http://www.w3.org/ns/prov#>
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(publishingTaskUri)} ext:publishedVersion ${sparqlEscapeUri(publishedSnippetUri)}.
${sparqlEscapeUri(snippetContainerUri)} a ext:PublishedSnippetContainer;
mu:uuid ${sparqlEscapeString(snippetContainerUuid)};
pav:hasCurrentVersion ${sparqlEscapeUri(publishedSnippetUri)};
pav:hasVersion ${sparqlEscapeUri(publishedSnippetUri)};
ext:fromSnippetList ${sparqlEscapeUri(snippetList.value)};
prov:derivedFrom ${sparqlEscapeUri(documentContainer.value)}.
${sparqlEscapeUri(publishedSnippetUri)} a ext:PublishedSnippet;
mu:uuid ${sparqlEscapeString(snippetUuid)};
dct:title ${sparqlEscapeString(title.value)};
ext:editorDocumentContent ${sparqlEscapeString(content.value)};
pav:createdOn ${sparqlEscapeDateTime(now)};
prov:derivedFrom ${sparqlEscapeUri(editorDocument.value)}.
}
${sparqlEscapeUri(publishingTaskUri)} ext:publishedVersion ${sparqlEscapeUri(publishedSnippetUri)}.
${sparqlEscapeUri(snippetContainerUri)} a ext:PublishedSnippetContainer;
mu:uuid ${sparqlEscapeString(snippetContainerUuid)};
pav:hasCurrentVersion ${sparqlEscapeUri(publishedSnippetUri)};
pav:hasVersion ${sparqlEscapeUri(publishedSnippetUri)};
ext:fromSnippetList ${sparqlEscapeUri(snippetList.value)};
prov:derivedFrom ${sparqlEscapeUri(documentContainer.value)}.
${sparqlEscapeUri(publishedSnippetUri)} a ext:PublishedSnippet;
mu:uuid ${sparqlEscapeString(snippetUuid)};
dct:title ${sparqlEscapeString(title.value)};
ext:editorDocumentContent ${sparqlEscapeString(content.value)};
pav:createdOn ${sparqlEscapeDateTime(now)};
prov:derivedFrom ${sparqlEscapeUri(editorDocument.value)}.
}
`;

Expand Down Expand Up @@ -79,21 +77,19 @@ export const updatePublishedSnippetContainer = async ({
PREFIX prov: <http://www.w3.org/ns/prov#>
INSERT DATA {
GRAPH <http://mu.semte.ch/graphs/public> {
${sparqlEscapeUri(publishingTaskUri)} ext:publishedVersion ${sparqlEscapeUri(publishedSnippetUri)}.
${sparqlEscapeUri(publishingTaskUri)} ext:publishedVersion ${sparqlEscapeUri(publishedSnippetUri)}.
${sparqlEscapeUri(templateUri)} pav:hasCurrentVersion ${sparqlEscapeUri(publishedSnippetUri)};
pav:hasVersion ${sparqlEscapeUri(publishedSnippetUri)};
ext:fromSnippetList ${sparqlEscapeUri(snippetList.value)}.
${sparqlEscapeUri(templateUri)} pav:hasCurrentVersion ${sparqlEscapeUri(publishedSnippetUri)};
pav:hasVersion ${sparqlEscapeUri(publishedSnippetUri)};
ext:fromSnippetList ${sparqlEscapeUri(snippetList.value)}.
${sparqlEscapeUri(publishedSnippetUri)} a ext:PublishedSnippet;
mu:uuid ${sparqlEscapeString(snippetUuid)};
dct:title ${sparqlEscapeString(title.value)};
ext:editorDocumentContent ${sparqlEscapeString(content.value)};
pav:createdOn ${sparqlEscapeDateTime(now)};
pav:previousVersion ${sparqlEscapeUri(previousVersionUri)};
prov:derivedFrom ${sparqlEscapeUri(editorDocument.value)}.
}
${sparqlEscapeUri(publishedSnippetUri)} a ext:PublishedSnippet;
mu:uuid ${sparqlEscapeString(snippetUuid)};
dct:title ${sparqlEscapeString(title.value)};
ext:editorDocumentContent ${sparqlEscapeString(content.value)};
pav:createdOn ${sparqlEscapeDateTime(now)};
pav:previousVersion ${sparqlEscapeUri(previousVersionUri)};
prov:derivedFrom ${sparqlEscapeUri(editorDocument.value)}.
}
`;

Expand Down

0 comments on commit bc4f8ce

Please sign in to comment.