ActivityPub-federated video streaming platform using P2P directly in your web browser
Introduce blocklist command
Chocobozzz5f8bd4cbb178
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.tsindex 124833cf60..a2bd07b124 100644--- a/server/tests/api/moderation/abuses.ts+++ b/server/tests/api/moderation/abuses.ts@@ -4,8 +4,6 @@ import 'mocha'import * as chai from 'chai'import {AbusesCommand,- addAccountToServerBlocklist,- addServerToServerBlocklist,addVideoCommentThread,cleanupTests,createUser,@@ -16,8 +14,6 @@ import {getVideoCommentThreads,getVideoIdFromUUID,getVideosList,- removeAccountFromServerBlocklist,- removeServerFromServerBlocklist,removeUser,removeVideo,ServerInfo,@@ -27,7 +23,7 @@ import {userLogin,waitJobs} from '@shared/extra-utils'-import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'+import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'const expect = chai.expect@@ -225,7 +221,7 @@ describe('Test abuses', function () {const accountToBlock = 'root@' + servers[1].host{- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)+ await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock })const body = await commands[0].getAdminList()expect(body.total).to.equal(2)@@ -235,7 +231,7 @@ describe('Test abuses', function () {}{- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock })const body = await commands[0].getAdminList()expect(body.total).to.equal(3)@@ -246,7 +242,7 @@ describe('Test abuses', function () {const serverToBlock = servers[1].host{- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)+ await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock })const body = await commands[0].getAdminList()expect(body.total).to.equal(2)@@ -256,7 +252,7 @@ describe('Test abuses', function () {}{- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)+ await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock })const body = await commands[0].getAdminList()expect(body.total).to.equal(3)diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.tsindex 4fb3c95f2e..99da64a2dd 100644--- a/server/tests/api/moderation/blocklist-notification.ts+++ b/server/tests/api/moderation/blocklist-notification.ts@@ -2,30 +2,23 @@import 'mocha'import * as chai from 'chai'-import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications'-import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions'-import { UserNotification, UserNotificationType } from '@shared/models'import {+ addUserSubscription,+ addVideoCommentThread,cleanupTests,createUser,doubleFollow,flushAndRunMultipleServers,+ getUserNotifications,+ markAsReadAllNotifications,+ removeUserSubscription,ServerInfo,+ setAccessTokensToServers,uploadVideo,- userLogin-} from '../../../../shared/extra-utils/index'-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'-import {- addAccountToAccountBlocklist,- addAccountToServerBlocklist,- addServerToAccountBlocklist,- addServerToServerBlocklist,- removeAccountFromAccountBlocklist,- removeAccountFromServerBlocklist,- removeServerFromAccountBlocklist-} from '../../../../shared/extra-utils/users/blocklist'-import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'-import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'+ userLogin,+ waitJobs+} from '@shared/extra-utils'+import { UserNotification, UserNotificationType } from '@shared/models'const expect = chai.expect@@ -134,7 +127,7 @@ describe('Test blocklist', function () {it('Should block an account', async function () {this.timeout(10000)- await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })await waitJobs(servers)})@@ -147,7 +140,7 @@ describe('Test blocklist', function () {await checkNotifications(servers[0].url, userToken2, notifs)- await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })})})@@ -167,7 +160,7 @@ describe('Test blocklist', function () {it('Should block an account', async function () {this.timeout(10000)- await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host)+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })await waitJobs(servers)})@@ -180,7 +173,7 @@ describe('Test blocklist', function () {await checkNotifications(servers[0].url, userToken2, notifs)- await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host)+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })})})@@ -207,7 +200,7 @@ describe('Test blocklist', function () {it('Should block an account', async function () {this.timeout(10000)- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)+ await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })await waitJobs(servers)})@@ -215,7 +208,7 @@ describe('Test blocklist', function () {await checkNotifications(servers[0].url, userToken1, [])await checkNotifications(servers[0].url, userToken2, [])- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })})})@@ -242,7 +235,7 @@ describe('Test blocklist', function () {it('Should block an account', async function () {this.timeout(10000)- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)+ await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })await waitJobs(servers)})diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.tsindex 9ca6324c2e..1b8860571e 100644--- a/server/tests/api/moderation/blocklist.ts+++ b/server/tests/api/moderation/blocklist.ts@@ -3,46 +3,27 @@import 'mocha'import * as chai from 'chai'import {- addAccountToAccountBlocklist,- addAccountToServerBlocklist,- addServerToAccountBlocklist,- addServerToServerBlocklist,addVideoCommentReply,addVideoCommentThread,+ BlocklistCommand,cleanupTests,createUser,deleteVideoComment,doubleFollow,findCommentId,flushAndRunMultipleServers,- getAccountBlocklistByAccount,- getAccountBlocklistByServer,- getServerBlocklistByAccount,- getServerBlocklistByServer,getUserNotifications,getVideoCommentThreads,getVideosList,getVideosListWithToken,getVideoThreadComments,- removeAccountFromAccountBlocklist,- removeAccountFromServerBlocklist,- removeServerFromAccountBlocklist,- removeServerFromServerBlocklist,ServerInfo,setAccessTokensToServers,uploadVideo,userLogin,waitJobs} from '@shared/extra-utils'-import {- AccountBlock,- ServerBlock,- UserNotification,- UserNotificationType,- Video,- VideoComment,- VideoCommentThreadTree-} from '@shared/models'+import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models'const expect = chai.expect@@ -108,6 +89,8 @@ describe('Test blocklist', function () {let userModeratorToken: stringlet userToken2: string+ let command: BlocklistCommand+before(async function () {this.timeout(120000)@@ -167,6 +150,8 @@ describe('Test blocklist', function () {}await waitJobs(servers)++ command = servers[0].blocklistCommand})describe('User blocklist', function () {@@ -181,7 +166,7 @@ describe('Test blocklist', function () {})it('Should block a remote account', async function () {- await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)+ await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })})it('Should hide its videos', async function () {@@ -195,7 +180,7 @@ describe('Test blocklist', function () {})it('Should block a local account', async function () {- await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')+ await command.addToMyBlocklist({ account: 'user1' })})it('Should hide its videos', async function () {@@ -251,12 +236,10 @@ describe('Test blocklist', function () {it('Should list blocked accounts', async function () {{- const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')- const blocks: AccountBlock[] = res.body.data+ const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })+ expect(body.total).to.equal(2)- expect(res.body.total).to.equal(2)-- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('root')expect(block.byAccount.name).to.equal('root')expect(block.blockedAccount.displayName).to.equal('user2')@@ -265,12 +248,10 @@ describe('Test blocklist', function () {}{- const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')- const blocks: AccountBlock[] = res.body.data-- expect(res.body.total).to.equal(2)+ const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })+ expect(body.total).to.equal(2)- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('root')expect(block.byAccount.name).to.equal('root')expect(block.blockedAccount.displayName).to.equal('user1')@@ -335,7 +316,7 @@ describe('Test blocklist', function () {})it('Should unblock the remote account', async function () {- await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)+ await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })})it('Should display its videos', async function () {@@ -374,7 +355,7 @@ describe('Test blocklist', function () {})it('Should unblock the local account', async function () {- await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')+ await command.removeFromMyBlocklist({ account: 'user1' })})it('Should display its comments', function () {@@ -402,6 +383,7 @@ describe('Test blocklist', function () {})describe('When managing server blocklist', function () {+it('Should list all videos', function () {return checkAllVideos(servers[0].url, servers[0].accessToken)})@@ -411,7 +393,7 @@ describe('Test blocklist', function () {})it('Should block a remote server', async function () {- await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })})it('Should hide its videos', async function () {@@ -464,19 +446,17 @@ describe('Test blocklist', function () {})it('Should list blocked servers', async function () {- const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')- const blocks: ServerBlock[] = res.body.data-- expect(res.body.total).to.equal(1)+ const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })+ expect(body.total).to.equal(1)- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('root')expect(block.byAccount.name).to.equal('root')expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)})it('Should unblock the remote server', async function () {- await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })})it('Should display its videos', function () {@@ -524,7 +504,7 @@ describe('Test blocklist', function () {})it('Should block a remote account', async function () {- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)+ await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })})it('Should hide its videos', async function () {@@ -540,7 +520,7 @@ describe('Test blocklist', function () {})it('Should block a local account', async function () {- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')+ await command.addToServerBlocklist({ account: 'user1' })})it('Should hide its videos', async function () {@@ -598,12 +578,10 @@ describe('Test blocklist', function () {it('Should list blocked accounts', async function () {{- const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')- const blocks: AccountBlock[] = res.body.data-- expect(res.body.total).to.equal(2)+ const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })+ expect(body.total).to.equal(2)- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('peertube')expect(block.byAccount.name).to.equal('peertube')expect(block.blockedAccount.displayName).to.equal('user2')@@ -612,12 +590,10 @@ describe('Test blocklist', function () {}{- const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')- const blocks: AccountBlock[] = res.body.data+ const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })+ expect(body.total).to.equal(2)- expect(res.body.total).to.equal(2)-- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('peertube')expect(block.byAccount.name).to.equal('peertube')expect(block.blockedAccount.displayName).to.equal('user1')@@ -627,7 +603,7 @@ describe('Test blocklist', function () {})it('Should unblock the remote account', async function () {- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)+ await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })})it('Should display its videos', async function () {@@ -643,7 +619,7 @@ describe('Test blocklist', function () {})it('Should unblock the local account', async function () {- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')+ await command.removeFromServerBlocklist({ account: 'user1' })})it('Should display its comments', async function () {@@ -686,7 +662,7 @@ describe('Test blocklist', function () {})it('Should block a remote server', async function () {- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })})it('Should hide its videos', async function () {@@ -758,19 +734,17 @@ describe('Test blocklist', function () {})it('Should list blocked servers', async function () {- const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')- const blocks: ServerBlock[] = res.body.data-- expect(res.body.total).to.equal(1)+ const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })+ expect(body.total).to.equal(1)- const block = blocks[0]+ const block = body.data[0]expect(block.byAccount.displayName).to.equal('peertube')expect(block.byAccount.name).to.equal('peertube')expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)})it('Should unblock the remote server', async function () {- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })})it('Should list all videos', async function () {diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.tsindex d2badf2374..13fcee8433 100644--- a/server/tests/api/notifications/comments-notifications.ts+++ b/server/tests/api/notifications/comments-notifications.ts@@ -3,7 +3,6 @@import 'mocha'import * as chai from 'chai'import {- addAccountToAccountBlocklist,addVideoCommentReply,addVideoCommentThread,checkCommentMention,@@ -14,7 +13,6 @@ import {getVideoThreadComments,MockSmtpServer,prepareNotificationsTest,- removeAccountFromAccountBlocklist,ServerInfo,updateMyUser,uploadVideo,@@ -86,7 +84,7 @@ describe('Test comments notifications', function () {it('Should not send a new comment notification if the account is muted', async function () {this.timeout(20000)- await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })const uuid = resVideo.body.video.uuid@@ -97,7 +95,7 @@ describe('Test comments notifications', function () {await waitJobs(servers)await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')- await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })})it('Should send a new comment notification after a local comment on my video', async function () {@@ -244,7 +242,7 @@ describe('Test comments notifications', function () {it('Should not send a new mention notification if the account is muted', async function () {this.timeout(10000)- await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })const uuid = resVideo.body.video.uuid@@ -255,7 +253,7 @@ describe('Test comments notifications', function () {await waitJobs(servers)await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')- await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })})it('Should not send a new mention notification if the remote account mention a local account', async function () {diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.tsindex 28f68dcfe6..90189721a6 100644--- a/server/tests/api/videos/video-playlists.ts+++ b/server/tests/api/videos/video-playlists.ts@@ -4,10 +4,6 @@ import 'mocha'import * as chai from 'chai'import { HttpStatusCode } from '@shared/core-utils'import {- addAccountToAccountBlocklist,- addAccountToServerBlocklist,- addServerToAccountBlocklist,- addServerToServerBlocklist,addVideoChannel,addVideoInPlaylist,addVideoToBlacklist,@@ -31,10 +27,6 @@ import {getVideoPlaylistPrivacies,getVideoPlaylistsList,getVideoPlaylistWithToken,- removeAccountFromAccountBlocklist,- removeAccountFromServerBlocklist,- removeServerFromAccountBlocklist,- removeServerFromServerBlocklist,removeUser,removeVideoFromBlacklist,removeVideoFromPlaylist,@@ -760,56 +752,58 @@ describe('Test video playlists', function () {it('Should update the element type if the account or server of the video is blocked', async function () {this.timeout(90000)+ const command = servers[0].blocklistCommand+const name = 'video 90'const position = 2{- await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)+ await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)- await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)+ await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)}{- await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)+ await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)- await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)+ await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)}{- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)+ await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)+ await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)}{- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })await waitJobs(servers)await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.tsindex b3ab9e070e..ccbc6f4a4f 100644--- a/server/tests/api/videos/videos-overview.ts+++ b/server/tests/api/videos/videos-overview.ts@@ -3,7 +3,6 @@import 'mocha'import * as chai from 'chai'import {- addAccountToAccountBlocklist,cleanupTests,flushAndRunServer,generateUserAccessToken,@@ -115,7 +114,7 @@ describe('Test a videos overview', function () {it('Should hide muted accounts', async function () {const token = await generateUserAccessToken(server, 'choco')- await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)+ await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }){const body = await server.overviewsCommand.getVideos({ page: 1 })diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.tsindex 8fcf94452f..f86c838089 100644--- a/server/tests/external-plugins/auto-mute.ts+++ b/server/tests/external-plugins/auto-mute.ts@@ -4,8 +4,6 @@ import 'mocha'import { expect } from 'chai'import { HttpStatusCode } from '@shared/core-utils'import {- addAccountToServerBlocklist,- addServerToAccountBlocklist,cleanupTests,doubleFollow,flushAndRunMultipleServers,@@ -13,7 +11,6 @@ import {killallServers,makeGetRequest,MockBlocklist,- removeAccountFromServerBlocklist,reRunServer,ServerInfo,setAccessTokensToServers,@@ -147,7 +144,7 @@ describe('Official plugin auto-mute', function () {expect(res.body.total).to.equal(1)}- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account }){const res = await getVideosList(servers[0].url)@@ -201,8 +198,8 @@ describe('Official plugin auto-mute', function () {}})- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)- await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)+ await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })+ await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })const res = await makeGetRequest({url: servers[0].url,diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.tsindex 4d29a2e391..17efc666d2 100644--- a/server/tests/feeds/feeds.ts+++ b/server/tests/feeds/feeds.ts@@ -3,16 +3,10 @@import 'mocha'import * as chai from 'chai'import * as xmlParser from 'fast-xml-parser'+import { HttpStatusCode } from '@shared/core-utils'import {- addAccountToAccountBlocklist,- addAccountToServerBlocklist,- removeAccountFromServerBlocklist-} from '@shared/extra-utils/users/blocklist'-import { addUserSubscription, listUserSubscriptionVideos } from '@shared/extra-utils/users/user-subscriptions'-import { VideoPrivacy } from '@shared/models'-import { ScopedToken } from '@shared/models/users/user-scoped-token'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'-import {+ addUserSubscription,+ addVideoCommentThread,cleanupTests,createUser,doubleFollow,@@ -20,16 +14,17 @@ import {flushAndRunServer,getMyUserInformation,getUserScopedTokens,+ listUserSubscriptionVideos,renewUserScopedTokens,ServerInfo,setAccessTokensToServers,uploadVideo,uploadVideoAndGetId,- userLogin-} from '../../../shared/extra-utils'-import { waitJobs } from '../../../shared/extra-utils/server/jobs'-import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'-import { User } from '../../../shared/models/users'+ userLogin,+ waitJobs+} from '@shared/extra-utils'+import { User, VideoPrivacy } from '@shared/models'+import { ScopedToken } from '@shared/models/users/user-scoped-token'chai.use(require('chai-xml'))chai.use(require('chai-json-schema'))@@ -271,7 +266,7 @@ describe('Test syndication feeds', () => {const remoteHandle = 'root@localhost:' + servers[0].port- await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)+ await servers[1].blocklistCommand.addToServerBlocklist({ account: remoteHandle }){const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 2 } })@@ -279,7 +274,7 @@ describe('Test syndication feeds', () => {expect(jsonObj.items.length).to.be.equal(0)}- await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)+ await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle }){const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid@@ -292,7 +287,7 @@ describe('Test syndication feeds', () => {expect(jsonObj.items.length).to.be.equal(3)}- await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)+ await servers[1].blocklistCommand.addToMyBlocklist({ account: remoteHandle }){const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 4 } })diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.tsindex c2cab98182..3c709666d2 100644--- a/shared/extra-utils/server/servers.ts+++ b/shared/extra-utils/server/servers.ts@@ -17,7 +17,7 @@ import { OverviewsCommand } from '../overviews'import { makeGetRequest } from '../requests/requests'import { SearchCommand } from '../search'import { SocketIOCommand } from '../socket'-import { AccountsCommand } from '../users'+import { AccountsCommand, BlocklistCommand } from '../users'import { ConfigCommand } from './config-command'import { ContactFormCommand } from './contact-form-command'import { DebugCommand } from './debug-command'@@ -97,6 +97,7 @@ interface ServerInfo {configCommand?: ConfigCommandsocketIOCommand?: SocketIOCommandaccountsCommand?: AccountsCommand+ blocklistCommand?: BlocklistCommand}function parallelTests () {@@ -320,6 +321,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []server.configCommand = new ConfigCommand(server)server.socketIOCommand = new SocketIOCommand(server)server.accountsCommand = new AccountsCommand(server)+ server.blocklistCommand = new BlocklistCommand(server)res(server)})diff --git a/shared/extra-utils/socket/socket-io-command.ts b/shared/extra-utils/socket/socket-io-command.tsindex 545561bed9..c277ead281 100644--- a/shared/extra-utils/socket/socket-io-command.ts+++ b/shared/extra-utils/socket/socket-io-command.ts@@ -5,7 +5,7 @@ export class SocketIOCommand extends AbstractCommand {getUserNotificationSocket (options: OverrideCommandOptions = {}) {return io(this.server.url + '/user-notifications', {- query: { accessToken: this.server.accessToken }+ query: { accessToken: options.token ?? this.server.accessToken }})}diff --git a/shared/extra-utils/users/blocklist-command.ts b/shared/extra-utils/users/blocklist-command.tsnew file mode 100644index 0000000000..96afdc3fd5--- /dev/null+++ b/shared/extra-utils/users/blocklist-command.ts@@ -0,0 +1,135 @@+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */++import { HttpStatusCode } from '@shared/core-utils'+import { AccountBlock, ResultList, ServerBlock } from '@shared/models'+import { AbstractCommand, OverrideCommandOptions } from '../shared'++type ListBlocklistOptions = OverrideCommandOptions & {+ start: number+ count: number+ sort: string // default -createdAt+}++export class BlocklistCommand extends AbstractCommand {++ listMyAccountBlocklist (options: ListBlocklistOptions) {+ const path = '/api/v1/users/me/blocklist/accounts'++ return this.listBlocklist<AccountBlock>(options, path)+ }++ listMyServerBlocklist (options: ListBlocklistOptions) {+ const path = '/api/v1/users/me/blocklist/servers'++ return this.listBlocklist<ServerBlock>(options, path)+ }++ listServerAccountBlocklist (options: ListBlocklistOptions) {+ const path = '/api/v1/server/blocklist/accounts'++ return this.listBlocklist<AccountBlock>(options, path)+ }++ listServerServerBlocklist (options: ListBlocklistOptions) {+ const path = '/api/v1/server/blocklist/servers'++ return this.listBlocklist<ServerBlock>(options, path)+ }++ // ---------------------------------------------------------------------------++ addToMyBlocklist (options: OverrideCommandOptions & {+ account?: string+ server?: string+ }) {+ const { account, server } = options++ const path = account+ ? '/api/v1/users/me/blocklist/accounts'+ : '/api/v1/users/me/blocklist/servers'++ return this.postBodyRequest({+ ...options,++ path,+ fields: {+ accountName: account,+ host: server+ },+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ addToServerBlocklist (options: OverrideCommandOptions & {+ account?: string+ server?: string+ }) {+ const { account, server } = options++ const path = account+ ? '/api/v1/server/blocklist/accounts'+ : '/api/v1/server/blocklist/servers'++ return this.postBodyRequest({+ ...options,++ path,+ fields: {+ accountName: account,+ host: server+ },+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ // ---------------------------------------------------------------------------++ removeFromMyBlocklist (options: OverrideCommandOptions & {+ account?: string+ server?: string+ }) {+ const { account, server } = options++ const path = account+ ? '/api/v1/users/me/blocklist/accounts/' + account+ : '/api/v1/users/me/blocklist/servers/' + server++ return this.deleteRequest({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ removeFromServerBlocklist (options: OverrideCommandOptions & {+ account?: string+ server?: string+ }) {+ const { account, server } = options++ const path = account+ ? '/api/v1/server/blocklist/accounts/' + account+ : '/api/v1/server/blocklist/servers/' + server++ return this.deleteRequest({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ private listBlocklist <T> (options: ListBlocklistOptions, path: string) {+ const { start, count, sort = '-createdAt' } = options++ return this.getRequestBody<ResultList<T>>({+ ...options,++ path,+ query: { start, count, sort },+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++}diff --git a/shared/extra-utils/users/blocklist.ts b/shared/extra-utils/users/blocklist.tsdeleted file mode 100644index bdf7ee58a2..0000000000--- a/shared/extra-utils/users/blocklist.ts+++ /dev/null@@ -1,238 +0,0 @@-/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */--import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'--function getAccountBlocklistByAccount (- url: string,- token: string,- start: number,- count: number,- sort = '-createdAt',- statusCodeExpected = HttpStatusCode.OK_200-) {- const path = '/api/v1/users/me/blocklist/accounts'-- return makeGetRequest({- url,- token,- query: { start, count, sort },- path,- statusCodeExpected- })-}--function addAccountToAccountBlocklist (- url: string,- token: string,- accountToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/users/me/blocklist/accounts'-- return makePostBodyRequest({- url,- path,- token,- fields: {- accountName: accountToBlock- },- statusCodeExpected- })-}--function removeAccountFromAccountBlocklist (- url: string,- token: string,- accountToUnblock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock-- return makeDeleteRequest({- url,- path,- token,- statusCodeExpected- })-}--function getServerBlocklistByAccount (- url: string,- token: string,- start: number,- count: number,- sort = '-createdAt',- statusCodeExpected = HttpStatusCode.OK_200-) {- const path = '/api/v1/users/me/blocklist/servers'-- return makeGetRequest({- url,- token,- query: { start, count, sort },- path,- statusCodeExpected- })-}--function addServerToAccountBlocklist (- url: string,- token: string,- serverToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/users/me/blocklist/servers'-- return makePostBodyRequest({- url,- path,- token,- fields: {- host: serverToBlock- },- statusCodeExpected- })-}--function removeServerFromAccountBlocklist (- url: string,- token: string,- serverToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock-- return makeDeleteRequest({- url,- path,- token,- statusCodeExpected- })-}--function getAccountBlocklistByServer (- url: string,- token: string,- start: number,- count: number,- sort = '-createdAt',- statusCodeExpected = HttpStatusCode.OK_200-) {- const path = '/api/v1/server/blocklist/accounts'-- return makeGetRequest({- url,- token,- query: { start, count, sort },- path,- statusCodeExpected- })-}--function addAccountToServerBlocklist (- url: string,- token: string,- accountToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/server/blocklist/accounts'-- return makePostBodyRequest({- url,- path,- token,- fields: {- accountName: accountToBlock- },- statusCodeExpected- })-}--function removeAccountFromServerBlocklist (- url: string,- token: string,- accountToUnblock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock-- return makeDeleteRequest({- url,- path,- token,- statusCodeExpected- })-}--function getServerBlocklistByServer (- url: string,- token: string,- start: number,- count: number,- sort = '-createdAt',- statusCodeExpected = HttpStatusCode.OK_200-) {- const path = '/api/v1/server/blocklist/servers'-- return makeGetRequest({- url,- token,- query: { start, count, sort },- path,- statusCodeExpected- })-}--function addServerToServerBlocklist (- url: string,- token: string,- serverToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/server/blocklist/servers'-- return makePostBodyRequest({- url,- path,- token,- fields: {- host: serverToBlock- },- statusCodeExpected- })-}--function removeServerFromServerBlocklist (- url: string,- token: string,- serverToBlock: string,- statusCodeExpected = HttpStatusCode.NO_CONTENT_204-) {- const path = '/api/v1/server/blocklist/servers/' + serverToBlock-- return makeDeleteRequest({- url,- path,- token,- statusCodeExpected- })-}--// -----------------------------------------------------------------------------export {- getAccountBlocklistByAccount,- addAccountToAccountBlocklist,- removeAccountFromAccountBlocklist,- getServerBlocklistByAccount,- addServerToAccountBlocklist,- removeServerFromAccountBlocklist,-- getAccountBlocklistByServer,- addAccountToServerBlocklist,- removeAccountFromServerBlocklist,- getServerBlocklistByServer,- addServerToServerBlocklist,- removeServerFromServerBlocklist-}diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.tsindex b3387ed8a3..ea5dbbf140 100644--- a/shared/extra-utils/users/index.ts+++ b/shared/extra-utils/users/index.ts@@ -1,7 +1,7 @@-export * from './accounts'export * from './accounts-command'+export * from './accounts'+export * from './blocklist-command'-export * from './blocklist'export * from './login'export * from './user-notifications'export * from './user-subscriptions'