Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570: Add RESTful API endpoints for Groups customi…
…zations
- Loading branch information
Showing
13 changed files
with
3,166 additions
and
3,888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import * as authz from "../authz/index.js"; | ||
import { Group } from "../groups.js"; | ||
import {contentTypesProvided, contentTypesConsumed} from "../negotiate.js"; | ||
import {deleteByUrls, proxyFromUpstream, proxyToUpstream} from "../upstream.js"; | ||
|
||
|
||
const setGroup = (nameExtractor) => (req, res, next) => { | ||
const group = new Group(nameExtractor(req)); | ||
|
||
authz.assertAuthorized(req.user, authz.actions.Read, group); | ||
|
||
req.context.group = group; | ||
return next(); | ||
}; | ||
|
||
|
||
/* Group customizations | ||
*/ | ||
|
||
|
||
/* Group logo | ||
*/ | ||
|
||
|
||
/* GET | ||
*/ | ||
const getGroupLogo = contentTypesProvided([ | ||
["image/png", sendGroupLogo], | ||
]); | ||
|
||
|
||
/* PUT | ||
*/ | ||
const putGroupLogo = contentTypesConsumed([ | ||
["image/png", receiveGroupLogo], | ||
]); | ||
|
||
|
||
/* DELETE | ||
*/ | ||
const deleteGroupLogo = async (req, res) => { | ||
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group); | ||
|
||
const method = "DELETE"; | ||
const url = await req.context.group.source.urlFor("group-logo.png", method); | ||
await deleteByUrls([url]); | ||
|
||
return res.status(204).end(); | ||
}; | ||
|
||
|
||
/* Group overview | ||
*/ | ||
|
||
|
||
/* GET | ||
*/ | ||
const getGroupOverview = contentTypesProvided([ | ||
["text/markdown", sendGroupOverview], | ||
["text/plain", sendGroupOverview], | ||
]); | ||
|
||
|
||
/* PUT | ||
*/ | ||
const putGroupOverview = contentTypesConsumed([ | ||
["text/markdown", receiveGroupOverview], | ||
]); | ||
|
||
|
||
/* DELETE | ||
*/ | ||
const deleteGroupOverview = async (req, res) => { | ||
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group); | ||
|
||
const method = "DELETE"; | ||
const url = await req.context.group.source.urlFor("group-overview.md", method); | ||
await deleteByUrls([url]); | ||
|
||
return res.status(204).end(); | ||
}; | ||
|
||
|
||
/** | ||
* An Express endpoint that sends a group overview determined by the request. | ||
* | ||
* @param {express.request} req - Express-style request instance | ||
* @param {express.response} res - Express-style response instance | ||
* @returns {expressEndpointAsync} | ||
*/ | ||
async function sendGroupOverview(req, res) { | ||
authz.assertAuthorized(req.user, authz.actions.Read, req.context.group); | ||
|
||
return await proxyFromUpstream(req, res, | ||
await req.context.group.source.urlFor("group-overview.md"), | ||
"text/markdown" | ||
); | ||
} | ||
|
||
|
||
/** | ||
* An Express endpoint that receives a group overview determined by the request. | ||
* | ||
* @param {express.request} req - Express-style request instance | ||
* @param {express.response} res - Express-style response instance | ||
* @returns {expressEndpointAsync} | ||
*/ | ||
async function receiveGroupOverview(req, res) { | ||
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group); | ||
|
||
return await proxyToUpstream(req, res, | ||
async (method, headers) => await req.context.group.source.urlFor("group-overview.md", method, headers), | ||
"text/markdown" | ||
); | ||
} | ||
|
||
|
||
/** | ||
* An Express endpoint that sends a group logo determined by the request. | ||
* | ||
* @param {express.request} req - Express-style request instance | ||
* @param {express.response} res - Express-style response instance | ||
* @returns {expressEndpointAsync} | ||
*/ | ||
async function sendGroupLogo(req, res) { | ||
authz.assertAuthorized(req.user, authz.actions.Read, req.context.group); | ||
|
||
return await proxyFromUpstream(req, res, | ||
await req.context.group.source.urlFor("group-logo.png"), | ||
"image/png" | ||
); | ||
} | ||
|
||
|
||
/** | ||
* An Express endpoint that receives a group logo determined by the request. | ||
* | ||
* @param {express.request} req - Express-style request instance | ||
* @param {express.response} res - Express-style response instance | ||
* @returns {expressEndpointAsync} | ||
*/ | ||
async function receiveGroupLogo(req, res) { | ||
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group); | ||
|
||
return await proxyToUpstream(req, res, | ||
async (method, headers) => await req.context.group.source.urlFor("group-logo.png", method, headers), | ||
"image/png" | ||
); | ||
} | ||
|
||
|
||
export { | ||
setGroup, | ||
getGroupLogo, | ||
putGroupLogo, | ||
deleteGroupLogo, | ||
getGroupOverview, | ||
putGroupOverview, | ||
deleteGroupOverview, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.