diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-08 11:52:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-08 11:52:43 +0200 |
commit | 0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6 (patch) | |
tree | 6ec1d1c4262811066224eff8c4a55865fdaa9d08 /server/controllers/api | |
parent | ae9bbed46dbc8d9870c9feb66bbada484c1c7582 (diff) | |
download | PeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.tar.gz PeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.tar.zst PeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.zip |
Add ability to remove an instance follower in API
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/server/follows.ts | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 99d211bfc..c00069f93 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -3,18 +3,23 @@ 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 { sendUndoFollow } from '../../../lib/activitypub/send' | 6 | import { sendReject, sendUndoFollow } from '../../../lib/activitypub/send' |
7 | import { | 7 | import { |
8 | asyncMiddleware, | 8 | asyncMiddleware, |
9 | authenticate, | 9 | authenticate, |
10 | ensureUserHasRight, | 10 | ensureUserHasRight, |
11 | paginationValidator, | 11 | paginationValidator, |
12 | removeFollowingValidator, | ||
13 | setBodyHostsPort, | 12 | setBodyHostsPort, |
14 | setDefaultPagination, | 13 | setDefaultPagination, |
15 | setDefaultSort | 14 | setDefaultSort |
16 | } from '../../../middlewares' | 15 | } from '../../../middlewares' |
17 | import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' | 16 | import { |
17 | followersSortValidator, | ||
18 | followingSortValidator, | ||
19 | followValidator, | ||
20 | removeFollowerValidator, | ||
21 | removeFollowingValidator | ||
22 | } from '../../../middlewares/validators' | ||
18 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 23 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
19 | import { JobQueue } from '../../../lib/job-queue' | 24 | import { JobQueue } from '../../../lib/job-queue' |
20 | import { removeRedundancyOf } from '../../../lib/redundancy' | 25 | import { removeRedundancyOf } from '../../../lib/redundancy' |
@@ -40,7 +45,7 @@ serverFollowsRouter.delete('/following/:host', | |||
40 | authenticate, | 45 | authenticate, |
41 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 46 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
42 | asyncMiddleware(removeFollowingValidator), | 47 | asyncMiddleware(removeFollowingValidator), |
43 | asyncMiddleware(removeFollow) | 48 | asyncMiddleware(removeFollowing) |
44 | ) | 49 | ) |
45 | 50 | ||
46 | serverFollowsRouter.get('/followers', | 51 | serverFollowsRouter.get('/followers', |
@@ -51,6 +56,13 @@ serverFollowsRouter.get('/followers', | |||
51 | asyncMiddleware(listFollowers) | 56 | asyncMiddleware(listFollowers) |
52 | ) | 57 | ) |
53 | 58 | ||
59 | serverFollowsRouter.delete('/followers/:nameWithHost', | ||
60 | authenticate, | ||
61 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | ||
62 | asyncMiddleware(removeFollowerValidator), | ||
63 | asyncMiddleware(removeFollower) | ||
64 | ) | ||
65 | |||
54 | // --------------------------------------------------------------------------- | 66 | // --------------------------------------------------------------------------- |
55 | 67 | ||
56 | export { | 68 | export { |
@@ -103,7 +115,7 @@ async function followInstance (req: express.Request, res: express.Response) { | |||
103 | return res.status(204).end() | 115 | return res.status(204).end() |
104 | } | 116 | } |
105 | 117 | ||
106 | async function removeFollow (req: express.Request, res: express.Response) { | 118 | async function removeFollowing (req: express.Request, res: express.Response) { |
107 | const follow = res.locals.follow | 119 | const follow = res.locals.follow |
108 | 120 | ||
109 | await sequelizeTypescript.transaction(async t => { | 121 | await sequelizeTypescript.transaction(async t => { |
@@ -123,3 +135,13 @@ async function removeFollow (req: express.Request, res: express.Response) { | |||
123 | 135 | ||
124 | return res.status(204).end() | 136 | return res.status(204).end() |
125 | } | 137 | } |
138 | |||
139 | async function removeFollower (req: express.Request, res: express.Response) { | ||
140 | const follow = res.locals.follow | ||
141 | |||
142 | await sendReject(follow) | ||
143 | |||
144 | await follow.destroy() | ||
145 | |||
146 | return res.status(204).end() | ||
147 | } | ||