]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix searching in blocklist
authorChocobozzz <me@florianbigard.com>
Fri, 17 Jun 2022 14:06:58 +0000 (16:06 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 17 Jun 2022 14:06:58 +0000 (16:06 +0200)
server/models/account/account-blocklist.ts
server/tests/api/moderation/blocklist.ts
shared/server-commands/users/blocklist-command.ts

index a7b8db076cd178705df0b0658d45c654cba8247e..377249b38608ba565a9270c1a814cb202bf54899 100644 (file)
@@ -132,6 +132,20 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB
             as: 'BlockedAccount'
           }
         ]
+      } else if (search) { // We need some joins when counting with search
+        query.include = [
+          {
+            model: AccountModel.unscoped(),
+            required: true,
+            as: 'BlockedAccount',
+            include: [
+              {
+                model: ActorModel.unscoped(),
+                required: true
+              }
+            ]
+          }
+        ]
       }
 
       return query
index e1344a2452d5ec5167434dcefde431fce0e424ca..a5a92317dfea0971cb17fdddea9d8277d45aaaa9 100644 (file)
@@ -256,6 +256,13 @@ describe('Test blocklist', function () {
         }
       })
 
+      it('Should search blocked accounts', async function () {
+        const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
+        expect(body.total).to.equal(1)
+
+        expect(body.data[0].blockedAccount.name).to.equal('user2')
+      })
+
       it('Should get blocked status', async function () {
         const remoteHandle = 'user2@' + servers[1].host
         const localHandle = 'user1@' + servers[0].host
@@ -475,6 +482,13 @@ describe('Test blocklist', function () {
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      it('Should search blocked servers', async function () {
+        const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
+        expect(body.total).to.equal(1)
+
+        expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
+      })
+
       it('Should get blocklist status', async function () {
         const blockedServer = servers[1].host
         const notBlockedServer = 'example.com'
@@ -645,6 +659,13 @@ describe('Test blocklist', function () {
         }
       })
 
+      it('Should search blocked accounts', async function () {
+        const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
+        expect(body.total).to.equal(1)
+
+        expect(body.data[0].blockedAccount.name).to.equal('user2')
+      })
+
       it('Should get blocked status', async function () {
         const remoteHandle = 'user2@' + servers[1].host
         const localHandle = 'user1@' + servers[0].host
@@ -805,6 +826,13 @@ describe('Test blocklist', function () {
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      it('Should search blocked servers', async function () {
+        const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
+        expect(body.total).to.equal(1)
+
+        expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
+      })
+
       it('Should get blocklist status', async function () {
         const blockedServer = servers[1].host
         const notBlockedServer = 'example.com'
index 2e7ed074dc3f36df77d6d42df5238fc6d75eef67..862d8945ed7f91a7c730cc0a7dd093935158c76f 100644 (file)
@@ -6,7 +6,10 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared'
 type ListBlocklistOptions = OverrideCommandOptions & {
   start: number
   count: number
-  sort: string // default -createdAt
+
+  sort?: string // default -createdAt
+
+  search?: string
 }
 
 export class BlocklistCommand extends AbstractCommand {
@@ -147,13 +150,13 @@ export class BlocklistCommand extends AbstractCommand {
   }
 
   private listBlocklist <T> (options: ListBlocklistOptions, path: string) {
-    const { start, count, sort = '-createdAt' } = options
+    const { start, count, search, sort = '-createdAt' } = options
 
     return this.getRequestBody<ResultList<T>>({
       ...options,
 
       path,
-      query: { start, count, sort },
+      query: { start, count, sort, search },
       implicitToken: true,
       defaultExpectedStatus: HttpStatusCode.OK_200
     })