From 4f5452ce84d4a5e32714f7a617997894d20204d4 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 14 Jul 2022 12:13:39 -0700 Subject: [PATCH] [wip] Implement GET /groups/:groupName/overview GET --- src/app.js | 7 +++++++ src/endpoints/sources.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/app.js b/src/app.js index efc9c293b..dc1ccdc86 100644 --- a/src/app.js +++ b/src/app.js @@ -30,6 +30,7 @@ const { getNarrative, putNarrative, deleteNarrative, + getGroupOverview, } = endpoints.sources; const { @@ -303,6 +304,12 @@ app.routeAsync("/groups/:groupName/narratives/*") .deleteAsync(deleteNarrative) ; +app.routeAsync("/groups/:groupName/overview") + .getAsync(getGroupOverview) + // .putAsync(putGroupOverview) + // .deleteAsync(deleteGroupOverview) +; + app.routeAsync("/groups/:groupName/*") .all(setDataset(req => req.params[0])) .getAsync(getDataset) diff --git a/src/endpoints/sources.js b/src/endpoints/sources.js index a703948ed..20092bd63 100644 --- a/src/endpoints/sources.js +++ b/src/endpoints/sources.js @@ -254,6 +254,16 @@ const getNarrative = contentTypesProvided([ ]); +const getGroupOverviewMarkdown = contentTypesProvided([ + ["text/markdown", sendGroupOverview(req => req.context.source)], +]); + + +const getGroupOverview = contentTypesProvided([ + ["text/markdown", getGroupOverviewMarkdown], +]); + + /* PUT */ const receiveNarrativeSubresource = type => @@ -292,6 +302,27 @@ function pathParts(path = "") { } +/** + * Generate an Express endpoint that sends a group overview + * determined by the request. + * + * @param {sourceExtractor} sourceExtractor - Function to provide the Source instance from the request + * @returns {expressEndpointAsync} + */ +function sendGroupOverview(sourceExtractor) { + return async (req, res) => { + const groupSource = sourceExtractor(req); + + authz.assertAuthorized(req.user, authz.actions.Read, groupSource); + + return await sendAny(req, res, + await groupSource.urlFor("group-overview.md"), + "text/markdown" // TODO: put this in a class? + ); + }; +} + + /** * Generate an Express endpoint that sends a dataset or narrative Subresource * determined by the request. @@ -712,4 +743,6 @@ module.exports = { sendDatasetSubresource, sendNarrativeSubresource, + + getGroupOverview, };