diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/follows.ts | 30 | ||||
-rw-r--r-- | server/middlewares/validators/user-subscriptions.ts | 7 |
2 files changed, 30 insertions, 7 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 | } |
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 = [ | |||
58 | if (host === WEBSERVER.HOST) host = null | 58 | if (host === WEBSERVER.HOST) host = null |
59 | 59 | ||
60 | const user = res.locals.oauth.token.User | 60 | const user = res.locals.oauth.token.User |
61 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) | 61 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({ |
62 | actorId: user.Account.Actor.id, | ||
63 | targetName: name, | ||
64 | targetHost: host, | ||
65 | state: 'accepted' | ||
66 | }) | ||
62 | 67 | ||
63 | if (!subscription || !subscription.ActorFollowing.VideoChannel) { | 68 | if (!subscription || !subscription.ActorFollowing.VideoChannel) { |
64 | return res.fail({ | 69 | return res.fail({ |