X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Ffollows.ts;h=2e5a02307743d16ef3bef12dfadf48f7e4377b1b;hb=b4055e1c23eeefb0c8a85a77f312b2827d98f483;hp=38df39fdaae04d5b44892a8be301894f1125d1ff;hpb=5b9c965d5aa747f29b081289f930ee215fdc23c8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 38df39fda..2e5a02307 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -4,7 +4,7 @@ import { isTestInstance } from '../../helpers/core-utils' import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' import { logger } from '../../helpers/logger' import { getServerActor } from '../../helpers/utils' -import { CONFIG, SERVER_ACTOR_NAME } from '../../initializers' +import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { areValidationErrors } from './utils' import { ActorModel } from '../../models/activitypub/actor' @@ -16,7 +16,7 @@ const followValidator = [ (req: express.Request, res: express.Response, next: express.NextFunction) => { // Force https if the administrator wants to make friends - if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { + if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { return res.status(500) .json({ error: 'Cannot follow on a non HTTPS web server.' @@ -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 }