From: Chocobozzz Date: Mon, 12 Mar 2018 10:29:46 +0000 (+0100) Subject: Change video abuse API response X-Git-Tag: v1.0.0-alpha.7~3 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=19a3b914f19812a082e2f47d31c66fb1d9771736;p=github%2FChocobozzz%2FPeerTube.git Change video abuse API response --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 5393edbdd..d845d2f3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 @@ {{ videoAbuse.reason }} - {{ videoAbuse.reporterUsername + '@' + videoAbuse.reporterServerHost }} + + + {{ createByString(videoAbuse.reporterAccount) }} + + {{ videoAbuse.createdAt }} - {{ videoAbuse.videoName }} + + {{ videoAbuse.video.name }} + 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 @@ 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 () { 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 @@ 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 { }) } - 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 } } 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 @@ 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 () { 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 ( 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) 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 @@ +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 } 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: 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: