diff options
Diffstat (limited to 'server/middlewares/validators/follows.ts')
-rw-r--r-- | server/middlewares/validators/follows.ts | 30 |
1 files changed, 24 insertions, 6 deletions
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 = [ | |||
81 | const serverActor = await getServerActor() | 81 | const serverActor = await getServerActor() |
82 | 82 | ||
83 | const { name, host } = getRemoteNameAndHost(req.params.hostOrHandle) | 83 | const { name, host } = getRemoteNameAndHost(req.params.hostOrHandle) |
84 | const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, name, host) | 84 | const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({ |
85 | actorId: serverActor.id, | ||
86 | targetName: name, | ||
87 | targetHost: host | ||
88 | }) | ||
85 | 89 | ||
86 | if (!follow) { | 90 | if (!follow) { |
87 | return res.fail({ | 91 | return res.fail({ |
@@ -126,13 +130,26 @@ const getFollowerValidator = [ | |||
126 | } | 130 | } |
127 | ] | 131 | ] |
128 | 132 | ||
129 | const acceptOrRejectFollowerValidator = [ | 133 | const acceptFollowerValidator = [ |
130 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 134 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
131 | logger.debug('Checking accept/reject follower parameters', { parameters: req.params }) | 135 | logger.debug('Checking accept follower parameters', { parameters: req.params }) |
132 | 136 | ||
133 | const follow = res.locals.follow | 137 | const follow = res.locals.follow |
134 | if (follow.state !== 'pending') { | 138 | if (follow.state !== 'pending' && follow.state !== 'rejected') { |
135 | return res.fail({ message: 'Follow is not in pending state.' }) | 139 | return res.fail({ message: 'Follow is not in pending/rejected state.' }) |
140 | } | ||
141 | |||
142 | return next() | ||
143 | } | ||
144 | ] | ||
145 | |||
146 | const rejectFollowerValidator = [ | ||
147 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
148 | logger.debug('Checking reject follower parameters', { parameters: req.params }) | ||
149 | |||
150 | const follow = res.locals.follow | ||
151 | if (follow.state !== 'pending' && follow.state !== 'accepted') { | ||
152 | return res.fail({ message: 'Follow is not in pending/accepted state.' }) | ||
136 | } | 153 | } |
137 | 154 | ||
138 | return next() | 155 | return next() |
@@ -145,6 +162,7 @@ export { | |||
145 | followValidator, | 162 | followValidator, |
146 | removeFollowingValidator, | 163 | removeFollowingValidator, |
147 | getFollowerValidator, | 164 | getFollowerValidator, |
148 | acceptOrRejectFollowerValidator, | 165 | acceptFollowerValidator, |
166 | rejectFollowerValidator, | ||
149 | listFollowsValidator | 167 | listFollowsValidator |
150 | } | 168 | } |