aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-17 16:06:58 +0200
committerChocobozzz <me@florianbigard.com>2022-06-17 16:06:58 +0200
commitd3976db269a0e5a3256867a7fc614d3c54c58720 (patch)
treec6cccee493ff773ef18195fba12c6843349f8b80
parentba73bedda6ad72b0accd51e594b1b3e193d50e87 (diff)
downloadPeerTube-d3976db269a0e5a3256867a7fc614d3c54c58720.tar.gz
PeerTube-d3976db269a0e5a3256867a7fc614d3c54c58720.tar.zst
PeerTube-d3976db269a0e5a3256867a7fc614d3c54c58720.zip
Fix searching in blocklist
-rw-r--r--server/models/account/account-blocklist.ts14
-rw-r--r--server/tests/api/moderation/blocklist.ts28
-rw-r--r--shared/server-commands/users/blocklist-command.ts9
3 files changed, 48 insertions, 3 deletions
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index a7b8db076..377249b38 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -132,6 +132,20 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB
132 as: 'BlockedAccount' 132 as: 'BlockedAccount'
133 } 133 }
134 ] 134 ]
135 } else if (search) { // We need some joins when counting with search
136 query.include = [
137 {
138 model: AccountModel.unscoped(),
139 required: true,
140 as: 'BlockedAccount',
141 include: [
142 {
143 model: ActorModel.unscoped(),
144 required: true
145 }
146 ]
147 }
148 ]
135 } 149 }
136 150
137 return query 151 return query
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index e1344a245..a5a92317d 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -256,6 +256,13 @@ describe('Test blocklist', function () {
256 } 256 }
257 }) 257 })
258 258
259 it('Should search blocked accounts', async function () {
260 const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
261 expect(body.total).to.equal(1)
262
263 expect(body.data[0].blockedAccount.name).to.equal('user2')
264 })
265
259 it('Should get blocked status', async function () { 266 it('Should get blocked status', async function () {
260 const remoteHandle = 'user2@' + servers[1].host 267 const remoteHandle = 'user2@' + servers[1].host
261 const localHandle = 'user1@' + servers[0].host 268 const localHandle = 'user1@' + servers[0].host
@@ -475,6 +482,13 @@ describe('Test blocklist', function () {
475 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 482 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
476 }) 483 })
477 484
485 it('Should search blocked servers', async function () {
486 const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
487 expect(body.total).to.equal(1)
488
489 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
490 })
491
478 it('Should get blocklist status', async function () { 492 it('Should get blocklist status', async function () {
479 const blockedServer = servers[1].host 493 const blockedServer = servers[1].host
480 const notBlockedServer = 'example.com' 494 const notBlockedServer = 'example.com'
@@ -645,6 +659,13 @@ describe('Test blocklist', function () {
645 } 659 }
646 }) 660 })
647 661
662 it('Should search blocked accounts', async function () {
663 const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
664 expect(body.total).to.equal(1)
665
666 expect(body.data[0].blockedAccount.name).to.equal('user2')
667 })
668
648 it('Should get blocked status', async function () { 669 it('Should get blocked status', async function () {
649 const remoteHandle = 'user2@' + servers[1].host 670 const remoteHandle = 'user2@' + servers[1].host
650 const localHandle = 'user1@' + servers[0].host 671 const localHandle = 'user1@' + servers[0].host
@@ -805,6 +826,13 @@ describe('Test blocklist', function () {
805 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 826 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
806 }) 827 })
807 828
829 it('Should search blocked servers', async function () {
830 const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
831 expect(body.total).to.equal(1)
832
833 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
834 })
835
808 it('Should get blocklist status', async function () { 836 it('Should get blocklist status', async function () {
809 const blockedServer = servers[1].host 837 const blockedServer = servers[1].host
810 const notBlockedServer = 'example.com' 838 const notBlockedServer = 'example.com'
diff --git a/shared/server-commands/users/blocklist-command.ts b/shared/server-commands/users/blocklist-command.ts
index 2e7ed074d..862d8945e 100644
--- a/shared/server-commands/users/blocklist-command.ts
+++ b/shared/server-commands/users/blocklist-command.ts
@@ -6,7 +6,10 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared'
6type ListBlocklistOptions = OverrideCommandOptions & { 6type ListBlocklistOptions = OverrideCommandOptions & {
7 start: number 7 start: number
8 count: number 8 count: number
9 sort: string // default -createdAt 9
10 sort?: string // default -createdAt
11
12 search?: string
10} 13}
11 14
12export class BlocklistCommand extends AbstractCommand { 15export class BlocklistCommand extends AbstractCommand {
@@ -147,13 +150,13 @@ export class BlocklistCommand extends AbstractCommand {
147 } 150 }
148 151
149 private listBlocklist <T> (options: ListBlocklistOptions, path: string) { 152 private listBlocklist <T> (options: ListBlocklistOptions, path: string) {
150 const { start, count, sort = '-createdAt' } = options 153 const { start, count, search, sort = '-createdAt' } = options
151 154
152 return this.getRequestBody<ResultList<T>>({ 155 return this.getRequestBody<ResultList<T>>({
153 ...options, 156 ...options,
154 157
155 path, 158 path,
156 query: { start, count, sort }, 159 query: { start, count, sort, search },
157 implicitToken: true, 160 implicitToken: true,
158 defaultExpectedStatus: HttpStatusCode.OK_200 161 defaultExpectedStatus: HttpStatusCode.OK_200
159 }) 162 })