From 927fa4b11f692174d6296aa096d7a74bacdeea8b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 26 Jul 2022 14:46:15 +0200 Subject: Add rejected state to follows Prevent reprocessing already rejected follows --- server/middlewares/validators/follows.ts | 30 +++++++++++++++++----- .../middlewares/validators/user-subscriptions.ts | 7 ++++- 2 files changed, 30 insertions(+), 7 deletions(-) (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 86d2d6228..023dba5b5 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -81,7 +81,11 @@ const removeFollowingValidator = [ const serverActor = await getServerActor() const { name, host } = getRemoteNameAndHost(req.params.hostOrHandle) - const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, name, host) + const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({ + actorId: serverActor.id, + targetName: name, + targetHost: host + }) if (!follow) { return res.fail({ @@ -126,13 +130,26 @@ const getFollowerValidator = [ } ] -const acceptOrRejectFollowerValidator = [ +const acceptFollowerValidator = [ (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking accept/reject follower parameters', { parameters: req.params }) + logger.debug('Checking accept follower parameters', { parameters: req.params }) const follow = res.locals.follow - if (follow.state !== 'pending') { - return res.fail({ message: 'Follow is not in pending state.' }) + if (follow.state !== 'pending' && follow.state !== 'rejected') { + return res.fail({ message: 'Follow is not in pending/rejected state.' }) + } + + return next() + } +] + +const rejectFollowerValidator = [ + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking reject follower parameters', { parameters: req.params }) + + const follow = res.locals.follow + if (follow.state !== 'pending' && follow.state !== 'accepted') { + return res.fail({ message: 'Follow is not in pending/accepted state.' }) } return next() @@ -145,6 +162,7 @@ export { followValidator, removeFollowingValidator, getFollowerValidator, - acceptOrRejectFollowerValidator, + acceptFollowerValidator, + rejectFollowerValidator, listFollowsValidator } diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index 48ce90d7b..73da3142a 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts @@ -58,7 +58,12 @@ const userSubscriptionGetValidator = [ if (host === WEBSERVER.HOST) host = null const user = res.locals.oauth.token.User - const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) + const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({ + actorId: user.Account.Actor.id, + targetName: name, + targetHost: host, + state: 'accepted' + }) if (!subscription || !subscription.ActorFollowing.VideoChannel) { return res.fail({ -- cgit v1.2.3