Change video abuse API response
authorChocobozzz <me@florianbigard.com>
Mon, 12 Mar 2018 10:29:46 +0000 (11:29 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 12 Mar 2018 10:44:28 +0000 (11:44 +0100)
CHANGELOG.md
client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html
client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
server/models/video/video-abuse.ts
server/tests/api/videos/video-abuse.ts
server/tests/utils/videos/videos.ts
shared/models/videos/video-abuse.model.ts
support/doc/api/openapi.yaml

index 5393edbddea8c228de1dbdad681cf11641fae498..d845d2f3eaac8a9ba6e7ef273c2dac19a9f734dc 100644 (file)
@@ -1,5 +1,30 @@
 # Changelog
 
+## v1.0.0-alpha.7
+
+### BREAKING CHANGES
+
+ * Update videos list/search API response:
+   * Removed `accountName` field
+   * Removed `serverHost` field
+   * Added `account.name` field
+   * Added `account.displayName` field
+   * Added `account.host` field
+   * Added `account.url` field
+   * Added `account.avatar` field
+ * Update video abuses API response:
+   * Removed `reporterUsername` field
+   * Removed `reporterServerHost` field
+   * Removed `videoId` field
+   * Removed `videoUUID` field
+   * Removed `videoName` field
+   * Added `reporterAccount` field
+   * Added `video.id` field
+   * Added `video.name` field
+   * Added `video.uuid` field
+   * Added `video.url` field
+
+
 ## v1.0.0-alpha.4
 
 ### Features
index 88a1641cf4895e727f0a17eb86d501ba5f643b0f..fcbdc614753ae760ba1562067073b57166770178 100644 (file)
   <ng-template pTemplate="body" let-videoAbuse>
     <tr>
       <td>{{ videoAbuse.reason }}</td>
-      <td>{{ videoAbuse.reporterUsername + '@' + videoAbuse.reporterServerHost }}</td>
+      <td>
+        <a [href]="videoAbuse.reporterAccount.url" title="Go to the account" target="_blank">
+          {{ createByString(videoAbuse.reporterAccount) }}
+        </a>
+      </td>
       <td>{{ videoAbuse.createdAt }}</td>
       <td>
-        <a [routerLink]="getRouterVideoLink(videoAbuse.videoUUID)" title="Go to the video">{{ videoAbuse.videoName }}</a>
+        <a [href]="videoAbuse.video.url" title="Go to the video" target="_blank">
+          {{ videoAbuse.video.name }}
+        </a>
       </td>
     </tr>
   </ng-template>
index bf9483f34bde012a9b5cb6af162bb037e7751e7e..b650194b76bae3cbba951b9a057cf1dba6b60f20 100644 (file)
@@ -1,11 +1,11 @@
 import { Component, OnInit } from '@angular/core'
-
+import { Account } from '@app/shared/account/account.model'
 import { NotificationsService } from 'angular2-notifications'
 import { SortMeta } from 'primeng/components/common/sortmeta'
-
-import { RestTable, RestPagination, VideoAbuseService } from '../../../shared'
 import { VideoAbuse } from '../../../../../../shared'
 
+import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
+
 @Component({
   selector: 'my-video-abuse-list',
   templateUrl: './video-abuse-list.component.html',
@@ -29,8 +29,8 @@ export class VideoAbuseListComponent extends RestTable implements OnInit {
     this.loadSort()
   }
 
-  getRouterVideoLink (videoUUID: string) {
-    return [ '/videos', videoUUID ]
+  createByString (account: Account) {
+    return Account.CREATE_BY_STRING(account.name, account.host)
   }
 
   protected loadData () {
index 65b734442564c667940dd8686b39ad4dd5860c1e..a6319bb79186314d8304fb416b88aae2079b412f 100644 (file)
@@ -1,7 +1,7 @@
 import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
 import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
+import { VideoAbuse } from '../../../shared/models/videos'
 import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
-import { CONFIG } from '../../initializers'
 import { Emailer } from '../../lib/emailer'
 import { AccountModel } from '../account/account'
 import { getSort, throwIfNotValid } from '../utils'
@@ -83,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
       })
   }
 
-  toFormattedJSON () {
-    let reporterServerHost
-
-    if (this.Account.Actor.Server) {
-      reporterServerHost = this.Account.Actor.Server.host
-    } else {
-      // It means it's our video
-      reporterServerHost = CONFIG.WEBSERVER.HOST
-    }
-
+  toFormattedJSON (): VideoAbuse {
     return {
       id: this.id,
       reason: this.reason,
-      reporterUsername: this.Account.name,
-      reporterServerHost,
-      videoId: this.Video.id,
-      videoUUID: this.Video.uuid,
-      videoName: this.Video.name,
+      reporterAccount: this.Account.toFormattedJSON(),
+      video: {
+        id: this.Video.id,
+        uuid: this.Video.uuid,
+        url: this.Video.url,
+        name: this.Video.name
+      },
       createdAt: this.createdAt
     }
   }
index 3fcf5d8c7990b9cb2309d27f5822aa3426aa06cf..f1c4ef0ceb45d2bba609154cd96959559a1d345d 100644 (file)
@@ -2,6 +2,7 @@
 
 import * as chai from 'chai'
 import 'mocha'
+import { VideoAbuse } from '../../../../shared/models/videos'
 import {
   flushAndRunMultipleServers,
   flushTests,
@@ -83,11 +84,11 @@ describe('Test video abuses', function () {
     expect(res1.body.data).to.be.an('array')
     expect(res1.body.data.length).to.equal(1)
 
-    const abuse = res1.body.data[0]
+    const abuse: VideoAbuse = res1.body.data[0]
     expect(abuse.reason).to.equal('my super bad reason')
-    expect(abuse.reporterUsername).to.equal('root')
-    expect(abuse.reporterServerHost).to.equal('localhost:9001')
-    expect(abuse.videoId).to.equal(servers[0].video.id)
+    expect(abuse.reporterAccount.name).to.equal('root')
+    expect(abuse.reporterAccount.host).to.equal('localhost:9001')
+    expect(abuse.video.id).to.equal(servers[0].video.id)
 
     const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
     expect(res2.body.total).to.equal(0)
@@ -111,27 +112,27 @@ describe('Test video abuses', function () {
     expect(res1.body.data).to.be.an('array')
     expect(res1.body.data.length).to.equal(2)
 
-    const abuse1 = res1.body.data[0]
+    const abuse1: VideoAbuse = res1.body.data[0]
     expect(abuse1.reason).to.equal('my super bad reason')
-    expect(abuse1.reporterUsername).to.equal('root')
-    expect(abuse1.reporterServerHost).to.equal('localhost:9001')
-    expect(abuse1.videoId).to.equal(servers[0].video.id)
+    expect(abuse1.reporterAccount.name).to.equal('root')
+    expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
+    expect(abuse1.video.id).to.equal(servers[0].video.id)
 
-    const abuse2 = res1.body.data[1]
+    const abuse2: VideoAbuse = res1.body.data[1]
     expect(abuse2.reason).to.equal('my super bad reason 2')
-    expect(abuse2.reporterUsername).to.equal('root')
-    expect(abuse2.reporterServerHost).to.equal('localhost:9001')
-    expect(abuse2.videoId).to.equal(servers[1].video.id)
+    expect(abuse2.reporterAccount.name).to.equal('root')
+    expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
+    expect(abuse2.video.id).to.equal(servers[1].video.id)
 
     const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
     expect(res2.body.total).to.equal(1)
     expect(res2.body.data).to.be.an('array')
     expect(res2.body.data.length).to.equal(1)
 
-    const abuse3 = res2.body.data[0]
+    const abuse3: VideoAbuse = res2.body.data[0]
     expect(abuse3.reason).to.equal('my super bad reason 2')
-    expect(abuse3.reporterUsername).to.equal('root')
-    expect(abuse3.reporterServerHost).to.equal('localhost:9001')
+    expect(abuse3.reporterAccount.name).to.equal('root')
+    expect(abuse3.reporterAccount.host).to.equal('localhost:9001')
   })
 
   after(async function () {
index 4b57f24b56c6ca950d45ff77dd013c26193312aa..ec40c546512f2ccffe37a176d398388586638b36 100644 (file)
@@ -420,7 +420,8 @@ async function completeVideoCheck (
   expect(videoDetails.tags).to.deep.equal(attributes.tags)
   expect(videoDetails.privacy).to.deep.equal(attributes.privacy)
   expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
-  expect(videoDetails.account.name).to.equal(attributes.account)
+  expect(videoDetails.account.name).to.equal(attributes.account.name)
+  expect(videoDetails.account.host).to.equal(attributes.account.host)
   expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
 
   expect(videoDetails.channel.displayName).to.equal(attributes.channel.name)
index aaedd00d4c1b1ceb16d9df0c74016468ae9f07d0..51070a7a33b01e6fa36524269744bedcd02a3499 100644 (file)
@@ -1,10 +1,14 @@
+import { Account } from '../actors'
+
 export interface VideoAbuse {
   id: number
   reason: string
-  reporterUsername: string
-  reporterServerHost: string
-  videoId: number
-  videoUUID: string
-  videoName: string
+  reporterAccount: Account
+  video: {
+    id: number
+    name: string
+    uuid: string
+    url: string
+  }
   createdAt: Date
 }
index c67d8e477a4340d963322acc140f8d062b5a6793..99bf0fd2de291525355550d927ee63f5f47797a3 100644 (file)
@@ -1094,16 +1094,13 @@ definitions:
         type: number
       reason:
         type: string
-      reporterUsername:
-        type: string
-      reporterServerHost:
-        type: string
-      videoId:
-        type: number
-      videoUUID:
-        type: string
-      videoName:
-        type: string
+      reporterAccount:
+        $ref: "#/definitions/Account"
+      video:
+        id: number
+        name: string
+        uuid: string
+        url: string
       createdAt:
         type: string
   VideoBlacklist: