From 14893eb71cb2d4ca47e07589c81958863603aba4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Apr 2019 15:18:04 +0200 Subject: Add ability to manually approves instance followers in REST API --- shared/utils/server/config.ts | 3 ++- shared/utils/server/follows.ts | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'shared/utils') 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) { }, followers: { instance: { - enabled: true + enabled: true, + manualApproval: false } } } 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 @@ import * as request from 'supertest' import { ServerInfo } from './servers' import { waitJobs } from './jobs' +import { makeGetRequest, makePostBodyRequest } from '..' function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { const path = '/api/v1/server/followers' @@ -16,6 +17,28 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n .expect('Content-Type', /json/) } +function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { + const path = '/api/v1/server/followers/' + follower + '/accept' + + return makePostBodyRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { + const path = '/api/v1/server/followers/' + follower + '/reject' + + return makePostBodyRequest({ + url, + token, + path, + statusCodeExpected + }) +} + function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { const path = '/api/v1/server/following' @@ -30,18 +53,16 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n .expect('Content-Type', /json/) } -async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { +function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { const path = '/api/v1/server/following' const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) - const res = await request(follower) + return request(follower) .post(path) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) .send({ 'hosts': followingHosts }) .expect(expectedStatus) - - return res } async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { @@ -84,5 +105,7 @@ export { unfollow, removeFollower, follow, - doubleFollow + doubleFollow, + acceptFollower, + rejectFollower } -- cgit v1.2.3