diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-26 14:46:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-27 13:52:13 +0200 |
commit | 927fa4b11f692174d6296aa096d7a74bacdeea8b (patch) | |
tree | 20866dda219bbb5504d5645a980565fbbc25398a /server/controllers/api | |
parent | 0f58b11f5cace6e57cab5b4a18380eb297b43fe4 (diff) | |
download | PeerTube-927fa4b11f692174d6296aa096d7a74bacdeea8b.tar.gz PeerTube-927fa4b11f692174d6296aa096d7a74bacdeea8b.tar.zst PeerTube-927fa4b11f692174d6296aa096d7a74bacdeea8b.zip |
Add rejected state to follows
Prevent reprocessing already rejected follows
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/server/follows.ts | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 37e8d88f7..60d36ed59 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { getServerActor } from '@server/models/application/application' | 2 | import { getServerActor } from '@server/models/application/application' |
3 | import { ServerFollowCreate } from '@shared/models' | ||
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | 4 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
4 | import { UserRight } from '../../../../shared/models/users' | 5 | import { UserRight } from '../../../../shared/models/users' |
5 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
@@ -20,16 +21,16 @@ import { | |||
20 | setDefaultSort | 21 | setDefaultSort |
21 | } from '../../../middlewares' | 22 | } from '../../../middlewares' |
22 | import { | 23 | import { |
23 | acceptOrRejectFollowerValidator, | 24 | acceptFollowerValidator, |
24 | instanceFollowersSortValidator, | ||
25 | instanceFollowingSortValidator, | ||
26 | followValidator, | 25 | followValidator, |
27 | getFollowerValidator, | 26 | getFollowerValidator, |
27 | instanceFollowersSortValidator, | ||
28 | instanceFollowingSortValidator, | ||
28 | listFollowsValidator, | 29 | listFollowsValidator, |
30 | rejectFollowerValidator, | ||
29 | removeFollowingValidator | 31 | removeFollowingValidator |
30 | } from '../../../middlewares/validators' | 32 | } from '../../../middlewares/validators' |
31 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 33 | import { ActorFollowModel } from '../../../models/actor/actor-follow' |
32 | import { ServerFollowCreate } from '@shared/models' | ||
33 | 34 | ||
34 | const serverFollowsRouter = express.Router() | 35 | const serverFollowsRouter = express.Router() |
35 | serverFollowsRouter.get('/following', | 36 | serverFollowsRouter.get('/following', |
@@ -69,22 +70,22 @@ serverFollowsRouter.delete('/followers/:nameWithHost', | |||
69 | authenticate, | 70 | authenticate, |
70 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 71 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
71 | asyncMiddleware(getFollowerValidator), | 72 | asyncMiddleware(getFollowerValidator), |
72 | asyncMiddleware(removeOrRejectFollower) | 73 | asyncMiddleware(removeFollower) |
73 | ) | 74 | ) |
74 | 75 | ||
75 | serverFollowsRouter.post('/followers/:nameWithHost/reject', | 76 | serverFollowsRouter.post('/followers/:nameWithHost/reject', |
76 | authenticate, | 77 | authenticate, |
77 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 78 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
78 | asyncMiddleware(getFollowerValidator), | 79 | asyncMiddleware(getFollowerValidator), |
79 | acceptOrRejectFollowerValidator, | 80 | rejectFollowerValidator, |
80 | asyncMiddleware(removeOrRejectFollower) | 81 | asyncMiddleware(rejectFollower) |
81 | ) | 82 | ) |
82 | 83 | ||
83 | serverFollowsRouter.post('/followers/:nameWithHost/accept', | 84 | serverFollowsRouter.post('/followers/:nameWithHost/accept', |
84 | authenticate, | 85 | authenticate, |
85 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 86 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
86 | asyncMiddleware(getFollowerValidator), | 87 | asyncMiddleware(getFollowerValidator), |
87 | acceptOrRejectFollowerValidator, | 88 | acceptFollowerValidator, |
88 | asyncMiddleware(acceptFollower) | 89 | asyncMiddleware(acceptFollower) |
89 | ) | 90 | ) |
90 | 91 | ||
@@ -176,10 +177,23 @@ async function removeFollowing (req: express.Request, res: express.Response) { | |||
176 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 177 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
177 | } | 178 | } |
178 | 179 | ||
179 | async function removeOrRejectFollower (req: express.Request, res: express.Response) { | 180 | async function rejectFollower (req: express.Request, res: express.Response) { |
180 | const follow = res.locals.follow | 181 | const follow = res.locals.follow |
181 | 182 | ||
182 | await sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing) | 183 | follow.state = 'rejected' |
184 | await follow.save() | ||
185 | |||
186 | sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing) | ||
187 | |||
188 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | ||
189 | } | ||
190 | |||
191 | async function removeFollower (req: express.Request, res: express.Response) { | ||
192 | const follow = res.locals.follow | ||
193 | |||
194 | if (follow.state === 'accepted' || follow.state === 'pending') { | ||
195 | sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing) | ||
196 | } | ||
183 | 197 | ||
184 | await follow.destroy() | 198 | await follow.destroy() |
185 | 199 | ||