aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-08 11:52:29 +0200
committerChocobozzz <me@florianbigard.com>2019-04-08 11:52:43 +0200
commit0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6 (patch)
tree6ec1d1c4262811066224eff8c4a55865fdaa9d08 /server/controllers
parentae9bbed46dbc8d9870c9feb66bbada484c1c7582 (diff)
downloadPeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.tar.gz
PeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.tar.zst
PeerTube-0e9c48c2edbb3871b0ca3ccd6718f2c99f9760b6.zip
Add ability to remove an instance follower in API
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/server/follows.ts32
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'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { getFormattedObjects, getServerActor } from '../../../helpers/utils' 4import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
5import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' 5import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers'
6import { sendUndoFollow } from '../../../lib/activitypub/send' 6import { sendReject, sendUndoFollow } from '../../../lib/activitypub/send'
7import { 7import {
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'
17import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' 16import {
17 followersSortValidator,
18 followingSortValidator,
19 followValidator,
20 removeFollowerValidator,
21 removeFollowingValidator
22} from '../../../middlewares/validators'
18import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 23import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
19import { JobQueue } from '../../../lib/job-queue' 24import { JobQueue } from '../../../lib/job-queue'
20import { removeRedundancyOf } from '../../../lib/redundancy' 25import { 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
46serverFollowsRouter.get('/followers', 51serverFollowsRouter.get('/followers',
@@ -51,6 +56,13 @@ serverFollowsRouter.get('/followers',
51 asyncMiddleware(listFollowers) 56 asyncMiddleware(listFollowers)
52) 57)
53 58
59serverFollowsRouter.delete('/followers/:nameWithHost',
60 authenticate,
61 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
62 asyncMiddleware(removeFollowerValidator),
63 asyncMiddleware(removeFollower)
64)
65
54// --------------------------------------------------------------------------- 66// ---------------------------------------------------------------------------
55 67
56export { 68export {
@@ -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
106async function removeFollow (req: express.Request, res: express.Response) { 118async 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
139async 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}