aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-08 15:18:04 +0200
committerChocobozzz <me@florianbigard.com>2019-04-08 15:18:04 +0200
commit14893eb71cb2d4ca47e07589c81958863603aba4 (patch)
treea6a5c3130058ca57c10ef15b8b6ee00ef78166ea /shared
parent5b9c965d5aa747f29b081289f930ee215fdc23c8 (diff)
downloadPeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.tar.gz
PeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.tar.zst
PeerTube-14893eb71cb2d4ca47e07589c81958863603aba4.zip
Add ability to manually approves instance followers in REST API
Diffstat (limited to 'shared')
-rw-r--r--shared/models/server/custom-config.model.ts3
-rw-r--r--shared/utils/server/config.ts3
-rw-r--r--shared/utils/server/follows.ts33
3 files changed, 32 insertions, 7 deletions
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts
index 642ffea39..ca52eff4b 100644
--- a/shared/models/server/custom-config.model.ts
+++ b/shared/models/server/custom-config.model.ts
@@ -88,7 +88,8 @@ export interface CustomConfig {
88 88
89 followers: { 89 followers: {
90 instance: { 90 instance: {
91 enabled: boolean 91 enabled: boolean,
92 manualApproval: boolean
92 } 93 }
93 } 94 }
94 95
diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts
index 21c689714..deb77e9c0 100644
--- a/shared/utils/server/config.ts
+++ b/shared/utils/server/config.ts
@@ -122,7 +122,8 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) {
122 }, 122 },
123 followers: { 123 followers: {
124 instance: { 124 instance: {
125 enabled: true 125 enabled: true,
126 manualApproval: false
126 } 127 }
127 } 128 }
128 } 129 }
diff --git a/shared/utils/server/follows.ts b/shared/utils/server/follows.ts
index 949fd8109..1505804de 100644
--- a/shared/utils/server/follows.ts
+++ b/shared/utils/server/follows.ts
@@ -1,6 +1,7 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { ServerInfo } from './servers' 2import { ServerInfo } from './servers'
3import { waitJobs } from './jobs' 3import { waitJobs } from './jobs'
4import { makeGetRequest, makePostBodyRequest } from '..'
4 5
5function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { 6function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
6 const path = '/api/v1/server/followers' 7 const path = '/api/v1/server/followers'
@@ -16,6 +17,28 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n
16 .expect('Content-Type', /json/) 17 .expect('Content-Type', /json/)
17} 18}
18 19
20function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
21 const path = '/api/v1/server/followers/' + follower + '/accept'
22
23 return makePostBodyRequest({
24 url,
25 token,
26 path,
27 statusCodeExpected
28 })
29}
30
31function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) {
32 const path = '/api/v1/server/followers/' + follower + '/reject'
33
34 return makePostBodyRequest({
35 url,
36 token,
37 path,
38 statusCodeExpected
39 })
40}
41
19function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { 42function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) {
20 const path = '/api/v1/server/following' 43 const path = '/api/v1/server/following'
21 44
@@ -30,18 +53,16 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n
30 .expect('Content-Type', /json/) 53 .expect('Content-Type', /json/)
31} 54}
32 55
33async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { 56function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
34 const path = '/api/v1/server/following' 57 const path = '/api/v1/server/following'
35 58
36 const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) 59 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
37 const res = await request(follower) 60 return request(follower)
38 .post(path) 61 .post(path)
39 .set('Accept', 'application/json') 62 .set('Accept', 'application/json')
40 .set('Authorization', 'Bearer ' + accessToken) 63 .set('Authorization', 'Bearer ' + accessToken)
41 .send({ 'hosts': followingHosts }) 64 .send({ 'hosts': followingHosts })
42 .expect(expectedStatus) 65 .expect(expectedStatus)
43
44 return res
45} 66}
46 67
47async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { 68async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) {
@@ -84,5 +105,7 @@ export {
84 unfollow, 105 unfollow,
85 removeFollower, 106 removeFollower,
86 follow, 107 follow,
87 doubleFollow 108 doubleFollow,
109 acceptFollower,
110 rejectFollower
88} 111}