From d817a3bd6fdddee8d12751a8c0b51d3f4682c805 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:56:06 -0700 Subject: [PATCH] [wip] Implement PUT /groups/:groupName/overview --- src/app.js | 3 ++- src/endpoints/sources.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index dc1ccdc86..26946bbd6 100644 --- a/src/app.js +++ b/src/app.js @@ -31,6 +31,7 @@ const { putNarrative, deleteNarrative, getGroupOverview, + putGroupOverview, } = endpoints.sources; const { @@ -306,7 +307,7 @@ app.routeAsync("/groups/:groupName/narratives/*") app.routeAsync("/groups/:groupName/overview") .getAsync(getGroupOverview) - // .putAsync(putGroupOverview) + .putAsync(putGroupOverview) // .deleteAsync(deleteGroupOverview) ; diff --git a/src/endpoints/sources.js b/src/endpoints/sources.js index 2e15cfa38..5c653692c 100644 --- a/src/endpoints/sources.js +++ b/src/endpoints/sources.js @@ -285,6 +285,18 @@ const getGroupOverview = contentTypesProvided([ ]); +/* PUT + */ +const putGroupOverviewMarkdown = contentTypesProvided([ + ["text/markdown", receiveGroupOverview(req => req.context.source)], +]); + + +const putGroupOverview = contentTypesProvided([ + ["text/markdown", putGroupOverviewMarkdown], +]); + + /** * Split a dataset or narrative `path` into an array of parts. * @@ -391,6 +403,29 @@ async function sendAny(req, res, url, accept) { } +/** + * Generate an Express endpoint that receives a group overview + * determined by the request. + * + * @param {sourceExtractor} sourceExtractor - Function to provide the Source instance from the request + * @returns {expressEndpointAsync} + */ +function receiveGroupOverview(sourceExtractor) { + return async (req, res) => { + const groupSource = sourceExtractor(req); + + authz.assertAuthorized(req.user, authz.actions.Read, groupSource); + + urlCallback = async (method, headers) => await groupSource.urlFor("group-overview.md", method, headers) + + return await receiveAny(req, res, + urlCallback, + "text/markdown" // TODO: put this in a class? + ); + }; +} + + /** * Generate an Express endpoint that receives a dataset or narrative * Subresource determined by the request. @@ -765,4 +800,5 @@ module.exports = { sendNarrativeSubresource, getGroupOverview, + putGroupOverview, };