diff options
author | Chocobozzz <me@florianbigard.com> | 2018-03-12 11:29:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-03-12 11:44:28 +0100 |
commit | 19a3b914f19812a082e2f47d31c66fb1d9771736 (patch) | |
tree | 7e60fbec3b4fff27e018682bd36c0d5e67aed228 /server | |
parent | f2c3f7cd8a592ca1949e4f73717f17132a16c292 (diff) | |
download | PeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.tar.gz PeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.tar.zst PeerTube-19a3b914f19812a082e2f47d31c66fb1d9771736.zip |
Change video abuse API response
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video-abuse.ts | 25 | ||||
-rw-r--r-- | server/tests/api/videos/video-abuse.ts | 31 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 3 |
3 files changed, 27 insertions, 32 deletions
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 @@ | |||
1 | import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' | 2 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' |
3 | import { VideoAbuse } from '../../../shared/models/videos' | ||
3 | import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' | 4 | import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' |
4 | import { CONFIG } from '../../initializers' | ||
5 | import { Emailer } from '../../lib/emailer' | 5 | import { Emailer } from '../../lib/emailer' |
6 | import { AccountModel } from '../account/account' | 6 | import { AccountModel } from '../account/account' |
7 | import { getSort, throwIfNotValid } from '../utils' | 7 | import { 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 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { VideoAbuse } from '../../../../shared/models/videos' | ||
5 | import { | 6 | import { |
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) |