aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-03-12 11:29:46 +0100
committerChocobozzz <me@florianbigard.com>2018-03-12 11:44:28 +0100
commit19a3b914f19812a082e2f47d31c66fb1d9771736 (patch)
tree7e60fbec3b4fff27e018682bd36c0d5e67aed228
parentf2c3f7cd8a592ca1949e4f73717f17132a16c292 (diff)
downloadPeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.tar.gz
PeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.tar.zst
PeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.zip
Change video abuse API response
-rw-r--r--CHANGELOG.md25
-rw-r--r--client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html10
-rw-r--r--client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts10
-rw-r--r--server/models/video/video-abuse.ts25
-rw-r--r--server/tests/api/videos/video-abuse.ts31
-rw-r--r--server/tests/utils/videos/videos.ts3
-rw-r--r--shared/models/videos/video-abuse.model.ts14
-rw-r--r--support/doc/api/openapi.yaml17
8 files changed, 81 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5393edbdd..d845d2f3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,30 @@
1# Changelog 1# Changelog
2 2
3## v1.0.0-alpha.7
4
5### BREAKING CHANGES
6
7 * Update videos list/search API response:
8 * Removed `accountName` field
9 * Removed `serverHost` field
10 * Added `account.name` field
11 * Added `account.displayName` field
12 * Added `account.host` field
13 * Added `account.url` field
14 * Added `account.avatar` field
15 * Update video abuses API response:
16 * Removed `reporterUsername` field
17 * Removed `reporterServerHost` field
18 * Removed `videoId` field
19 * Removed `videoUUID` field
20 * Removed `videoName` field
21 * Added `reporterAccount` field
22 * Added `video.id` field
23 * Added `video.name` field
24 * Added `video.uuid` field
25 * Added `video.url` field
26
27
3## v1.0.0-alpha.4 28## v1.0.0-alpha.4
4 29
5### Features 30### Features
diff --git a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html
index 88a1641cf..fcbdc6147 100644
--- a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html
+++ b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html
@@ -18,10 +18,16 @@
18 <ng-template pTemplate="body" let-videoAbuse> 18 <ng-template pTemplate="body" let-videoAbuse>
19 <tr> 19 <tr>
20 <td>{{ videoAbuse.reason }}</td> 20 <td>{{ videoAbuse.reason }}</td>
21 <td>{{ videoAbuse.reporterUsername + '@' + videoAbuse.reporterServerHost }}</td> 21 <td>
22 <a [href]="videoAbuse.reporterAccount.url" title="Go to the account" target="_blank">
23 {{ createByString(videoAbuse.reporterAccount) }}
24 </a>
25 </td>
22 <td>{{ videoAbuse.createdAt }}</td> 26 <td>{{ videoAbuse.createdAt }}</td>
23 <td> 27 <td>
24 <a [routerLink]="getRouterVideoLink(videoAbuse.videoUUID)" title="Go to the video">{{ videoAbuse.videoName }}</a> 28 <a [href]="videoAbuse.video.url" title="Go to the video" target="_blank">
29 {{ videoAbuse.video.name }}
30 </a>
25 </td> 31 </td>
26 </tr> 32 </tr>
27 </ng-template> 33 </ng-template>
diff --git a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
index bf9483f34..b650194b7 100644
--- a/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
+++ b/client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.ts
@@ -1,11 +1,11 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2 2import { Account } from '@app/shared/account/account.model'
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import { SortMeta } from 'primeng/components/common/sortmeta' 4import { SortMeta } from 'primeng/components/common/sortmeta'
5
6import { RestTable, RestPagination, VideoAbuseService } from '../../../shared'
7import { VideoAbuse } from '../../../../../../shared' 5import { VideoAbuse } from '../../../../../../shared'
8 6
7import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
8
9@Component({ 9@Component({
10 selector: 'my-video-abuse-list', 10 selector: 'my-video-abuse-list',
11 templateUrl: './video-abuse-list.component.html', 11 templateUrl: './video-abuse-list.component.html',
@@ -29,8 +29,8 @@ export class VideoAbuseListComponent extends RestTable implements OnInit {
29 this.loadSort() 29 this.loadSort()
30 } 30 }
31 31
32 getRouterVideoLink (videoUUID: string) { 32 createByString (account: Account) {
33 return [ '/videos', videoUUID ] 33 return Account.CREATE_BY_STRING(account.name, account.host)
34 } 34 }
35 35
36 protected loadData () { 36 protected loadData () {
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 65b734442..a6319bb79 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,7 +1,7 @@
1import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' 2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
3import { VideoAbuse } from '../../../shared/models/videos'
3import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' 4import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
4import { CONFIG } from '../../initializers'
5import { Emailer } from '../../lib/emailer' 5import { Emailer } from '../../lib/emailer'
6import { AccountModel } from '../account/account' 6import { AccountModel } from '../account/account'
7import { getSort, throwIfNotValid } from '../utils' 7import { getSort, throwIfNotValid } from '../utils'
@@ -83,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
83 }) 83 })
84 } 84 }
85 85
86 toFormattedJSON () { 86 toFormattedJSON (): VideoAbuse {
87 let reporterServerHost
88
89 if (this.Account.Actor.Server) {
90 reporterServerHost = this.Account.Actor.Server.host
91 } else {
92 // It means it's our video
93 reporterServerHost = CONFIG.WEBSERVER.HOST
94 }
95
96 return { 87 return {
97 id: this.id, 88 id: this.id,
98 reason: this.reason, 89 reason: this.reason,
99 reporterUsername: this.Account.name, 90 reporterAccount: this.Account.toFormattedJSON(),
100 reporterServerHost, 91 video: {
101 videoId: this.Video.id, 92 id: this.Video.id,
102 videoUUID: this.Video.uuid, 93 uuid: this.Video.uuid,
103 videoName: this.Video.name, 94 url: this.Video.url,
95 name: this.Video.name
96 },
104 createdAt: this.createdAt 97 createdAt: this.createdAt
105 } 98 }
106 } 99 }
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index 3fcf5d8c7..f1c4ef0ce 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -2,6 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoAbuse } from '../../../../shared/models/videos'
5import { 6import {
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 flushTests, 8 flushTests,
@@ -83,11 +84,11 @@ describe('Test video abuses', function () {
83 expect(res1.body.data).to.be.an('array') 84 expect(res1.body.data).to.be.an('array')
84 expect(res1.body.data.length).to.equal(1) 85 expect(res1.body.data.length).to.equal(1)
85 86
86 const abuse = res1.body.data[0] 87 const abuse: VideoAbuse = res1.body.data[0]
87 expect(abuse.reason).to.equal('my super bad reason') 88 expect(abuse.reason).to.equal('my super bad reason')
88 expect(abuse.reporterUsername).to.equal('root') 89 expect(abuse.reporterAccount.name).to.equal('root')
89 expect(abuse.reporterServerHost).to.equal('localhost:9001') 90 expect(abuse.reporterAccount.host).to.equal('localhost:9001')
90 expect(abuse.videoId).to.equal(servers[0].video.id) 91 expect(abuse.video.id).to.equal(servers[0].video.id)
91 92
92 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 93 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
93 expect(res2.body.total).to.equal(0) 94 expect(res2.body.total).to.equal(0)
@@ -111,27 +112,27 @@ describe('Test video abuses', function () {
111 expect(res1.body.data).to.be.an('array') 112 expect(res1.body.data).to.be.an('array')
112 expect(res1.body.data.length).to.equal(2) 113 expect(res1.body.data.length).to.equal(2)
113 114
114 const abuse1 = res1.body.data[0] 115 const abuse1: VideoAbuse = res1.body.data[0]
115 expect(abuse1.reason).to.equal('my super bad reason') 116 expect(abuse1.reason).to.equal('my super bad reason')
116 expect(abuse1.reporterUsername).to.equal('root') 117 expect(abuse1.reporterAccount.name).to.equal('root')
117 expect(abuse1.reporterServerHost).to.equal('localhost:9001') 118 expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
118 expect(abuse1.videoId).to.equal(servers[0].video.id) 119 expect(abuse1.video.id).to.equal(servers[0].video.id)
119 120
120 const abuse2 = res1.body.data[1] 121 const abuse2: VideoAbuse = res1.body.data[1]
121 expect(abuse2.reason).to.equal('my super bad reason 2') 122 expect(abuse2.reason).to.equal('my super bad reason 2')
122 expect(abuse2.reporterUsername).to.equal('root') 123 expect(abuse2.reporterAccount.name).to.equal('root')
123 expect(abuse2.reporterServerHost).to.equal('localhost:9001') 124 expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
124 expect(abuse2.videoId).to.equal(servers[1].video.id) 125 expect(abuse2.video.id).to.equal(servers[1].video.id)
125 126
126 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 127 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
127 expect(res2.body.total).to.equal(1) 128 expect(res2.body.total).to.equal(1)
128 expect(res2.body.data).to.be.an('array') 129 expect(res2.body.data).to.be.an('array')
129 expect(res2.body.data.length).to.equal(1) 130 expect(res2.body.data.length).to.equal(1)
130 131
131 const abuse3 = res2.body.data[0] 132 const abuse3: VideoAbuse = res2.body.data[0]
132 expect(abuse3.reason).to.equal('my super bad reason 2') 133 expect(abuse3.reason).to.equal('my super bad reason 2')
133 expect(abuse3.reporterUsername).to.equal('root') 134 expect(abuse3.reporterAccount.name).to.equal('root')
134 expect(abuse3.reporterServerHost).to.equal('localhost:9001') 135 expect(abuse3.reporterAccount.host).to.equal('localhost:9001')
135 }) 136 })
136 137
137 after(async function () { 138 after(async function () {
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 4b57f24b5..ec40c5465 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -420,7 +420,8 @@ async function completeVideoCheck (
420 expect(videoDetails.tags).to.deep.equal(attributes.tags) 420 expect(videoDetails.tags).to.deep.equal(attributes.tags)
421 expect(videoDetails.privacy).to.deep.equal(attributes.privacy) 421 expect(videoDetails.privacy).to.deep.equal(attributes.privacy)
422 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) 422 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
423 expect(videoDetails.account.name).to.equal(attributes.account) 423 expect(videoDetails.account.name).to.equal(attributes.account.name)
424 expect(videoDetails.account.host).to.equal(attributes.account.host)
424 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) 425 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
425 426
426 expect(videoDetails.channel.displayName).to.equal(attributes.channel.name) 427 expect(videoDetails.channel.displayName).to.equal(attributes.channel.name)
diff --git a/shared/models/videos/video-abuse.model.ts b/shared/models/videos/video-abuse.model.ts
index aaedd00d4..51070a7a3 100644
--- a/shared/models/videos/video-abuse.model.ts
+++ b/shared/models/videos/video-abuse.model.ts
@@ -1,10 +1,14 @@
1import { Account } from '../actors'
2
1export interface VideoAbuse { 3export interface VideoAbuse {
2 id: number 4 id: number
3 reason: string 5 reason: string
4 reporterUsername: string 6 reporterAccount: Account
5 reporterServerHost: string 7 video: {
6 videoId: number 8 id: number
7 videoUUID: string 9 name: string
8 videoName: string 10 uuid: string
11 url: string
12 }
9 createdAt: Date 13 createdAt: Date
10} 14}
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index c67d8e477..99bf0fd2d 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -1094,16 +1094,13 @@ definitions:
1094 type: number 1094 type: number
1095 reason: 1095 reason:
1096 type: string 1096 type: string
1097 reporterUsername: 1097 reporterAccount:
1098 type: string 1098 $ref: "#/definitions/Account"
1099 reporterServerHost: 1099 video:
1100 type: string 1100 id: number
1101 videoId: 1101 name: string
1102 type: number 1102 uuid: string
1103 videoUUID: 1103 url: string
1104 type: string
1105 videoName:
1106 type: string
1107 createdAt: 1104 createdAt:
1108 type: string 1105 type: string
1109 VideoBlacklist: 1106 VideoBlacklist: