diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-08 15:18:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-08 15:18:04 +0200 |
commit | 14893eb71cb2d4ca47e07589c81958863603aba4 (patch) | |
tree | a6a5c3130058ca57c10ef15b8b6ee00ef78166ea /server/controllers | |
parent | 5b9c965d5aa747f29b081289f930ee215fdc23c8 (diff) | |
download | PeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.tar.gz PeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.tar.zst PeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.zip |
Add ability to manually approves instance followers in REST API
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/config.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 38 |
2 files changed, 35 insertions, 6 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index f9bb0b947..5c4f455ee 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -282,7 +282,8 @@ function customConfig (): CustomConfig { | |||
282 | }, | 282 | }, |
283 | followers: { | 283 | followers: { |
284 | instance: { | 284 | instance: { |
285 | enabled: CONFIG.FOLLOWERS.INSTANCE.ENABLED | 285 | enabled: CONFIG.FOLLOWERS.INSTANCE.ENABLED, |
286 | manualApproval: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL | ||
286 | } | 287 | } |
287 | } | 288 | } |
288 | } | 289 | } |
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 87cf091cb..207a09a4c 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -3,7 +3,7 @@ import { UserRight } from '../../../../shared/models/users' | |||
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' | 4 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
5 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' | 5 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' |
6 | import { sendReject, sendUndoFollow } from '../../../lib/activitypub/send' | 6 | import { sendAccept, sendReject, sendUndoFollow } from '../../../lib/activitypub/send' |
7 | import { | 7 | import { |
8 | asyncMiddleware, | 8 | asyncMiddleware, |
9 | authenticate, | 9 | authenticate, |
@@ -14,10 +14,11 @@ import { | |||
14 | setDefaultSort | 14 | setDefaultSort |
15 | } from '../../../middlewares' | 15 | } from '../../../middlewares' |
16 | import { | 16 | import { |
17 | acceptOrRejectFollowerValidator, | ||
17 | followersSortValidator, | 18 | followersSortValidator, |
18 | followingSortValidator, | 19 | followingSortValidator, |
19 | followValidator, | 20 | followValidator, |
20 | removeFollowerValidator, | 21 | getFollowerValidator, |
21 | removeFollowingValidator | 22 | removeFollowingValidator |
22 | } from '../../../middlewares/validators' | 23 | } from '../../../middlewares/validators' |
23 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 24 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
@@ -59,8 +60,24 @@ serverFollowsRouter.get('/followers', | |||
59 | serverFollowsRouter.delete('/followers/:nameWithHost', | 60 | serverFollowsRouter.delete('/followers/:nameWithHost', |
60 | authenticate, | 61 | authenticate, |
61 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 62 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
62 | asyncMiddleware(removeFollowerValidator), | 63 | asyncMiddleware(getFollowerValidator), |
63 | asyncMiddleware(removeFollower) | 64 | asyncMiddleware(removeOrRejectFollower) |
65 | ) | ||
66 | |||
67 | serverFollowsRouter.post('/followers/:nameWithHost/reject', | ||
68 | authenticate, | ||
69 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | ||
70 | asyncMiddleware(getFollowerValidator), | ||
71 | acceptOrRejectFollowerValidator, | ||
72 | asyncMiddleware(removeOrRejectFollower) | ||
73 | ) | ||
74 | |||
75 | serverFollowsRouter.post('/followers/:nameWithHost/accept', | ||
76 | authenticate, | ||
77 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | ||
78 | asyncMiddleware(getFollowerValidator), | ||
79 | acceptOrRejectFollowerValidator, | ||
80 | asyncMiddleware(acceptFollower) | ||
64 | ) | 81 | ) |
65 | 82 | ||
66 | // --------------------------------------------------------------------------- | 83 | // --------------------------------------------------------------------------- |
@@ -136,7 +153,7 @@ async function removeFollowing (req: express.Request, res: express.Response) { | |||
136 | return res.status(204).end() | 153 | return res.status(204).end() |
137 | } | 154 | } |
138 | 155 | ||
139 | async function removeFollower (req: express.Request, res: express.Response) { | 156 | async function removeOrRejectFollower (req: express.Request, res: express.Response) { |
140 | const follow = res.locals.follow | 157 | const follow = res.locals.follow |
141 | 158 | ||
142 | await sendReject(follow.ActorFollower, follow.ActorFollowing) | 159 | await sendReject(follow.ActorFollower, follow.ActorFollowing) |
@@ -145,3 +162,14 @@ async function removeFollower (req: express.Request, res: express.Response) { | |||
145 | 162 | ||
146 | return res.status(204).end() | 163 | return res.status(204).end() |
147 | } | 164 | } |
165 | |||
166 | async function acceptFollower (req: express.Request, res: express.Response) { | ||
167 | const follow = res.locals.follow | ||
168 | |||
169 | await sendAccept(follow) | ||
170 | |||
171 | follow.state = 'accepted' | ||
172 | await follow.save() | ||
173 | |||
174 | return res.status(204).end() | ||
175 | } | ||