From 14893eb71cb2d4ca47e07589c81958863603aba4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Apr 2019 15:18:04 +0200 Subject: Add ability to manually approves instance followers in REST API --- server/middlewares/validators/config.ts | 3 +++ server/middlewares/validators/follows.ts | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 270ce66f6..d015fa6fe 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -44,6 +44,9 @@ const customConfigUpdateValidator = [ body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), + body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), + body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 38df39fda..b360cf95e 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -57,11 +57,11 @@ const removeFollowingValidator = [ } ] -const removeFollowerValidator = [ +const getFollowerValidator = [ param('nameWithHost').custom(isValidActorHandle).withMessage('Should have a valid nameWithHost'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking remove follower parameters', { parameters: req.params }) + logger.debug('Checking get follower parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return @@ -90,10 +90,24 @@ const removeFollowerValidator = [ } ] +const acceptOrRejectFollowerValidator = [ + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking accept/reject follower parameters', { parameters: req.params }) + + const follow = res.locals.follow + if (follow.state !== 'pending') { + return res.status(400).json({ error: 'Follow is not in pending state.' }).end() + } + + return next() + } +] + // --------------------------------------------------------------------------- export { followValidator, removeFollowingValidator, - removeFollowerValidator + getFollowerValidator, + acceptOrRejectFollowerValidator } -- cgit v1.2.3