Change video abuse API response

This commit is contained in:
Chocobozzz 2018-03-12 11:29:46 +01:00
parent f2c3f7cd8a
commit 19a3b914f1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
8 changed files with 81 additions and 54 deletions

View File

@ -1,5 +1,30 @@
# Changelog # 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 ## v1.0.0-alpha.4
### Features ### Features

View File

@ -18,10 +18,16 @@
<ng-template pTemplate="body" let-videoAbuse> <ng-template pTemplate="body" let-videoAbuse>
<tr> <tr>
<td>{{ videoAbuse.reason }}</td> <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>{{ videoAbuse.createdAt }}</td>
<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> </td>
</tr> </tr>
</ng-template> </ng-template>

View File

@ -1,11 +1,11 @@
import { Component, OnInit } from '@angular/core' import { Component, OnInit } from '@angular/core'
import { Account } from '@app/shared/account/account.model'
import { NotificationsService } from 'angular2-notifications' import { NotificationsService } from 'angular2-notifications'
import { SortMeta } from 'primeng/components/common/sortmeta' import { SortMeta } from 'primeng/components/common/sortmeta'
import { RestTable, RestPagination, VideoAbuseService } from '../../../shared'
import { VideoAbuse } from '../../../../../../shared' import { VideoAbuse } from '../../../../../../shared'
import { RestPagination, RestTable, VideoAbuseService } from '../../../shared'
@Component({ @Component({
selector: 'my-video-abuse-list', selector: 'my-video-abuse-list',
templateUrl: './video-abuse-list.component.html', templateUrl: './video-abuse-list.component.html',
@ -29,8 +29,8 @@ export class VideoAbuseListComponent extends RestTable implements OnInit {
this.loadSort() this.loadSort()
} }
getRouterVideoLink (videoUUID: string) { createByString (account: Account) {
return [ '/videos', videoUUID ] return Account.CREATE_BY_STRING(account.name, account.host)
} }
protected loadData () { protected loadData () {

View File

@ -1,7 +1,7 @@
import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
import { VideoAbuse } from '../../../shared/models/videos'
import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
import { CONFIG } from '../../initializers'
import { Emailer } from '../../lib/emailer' import { Emailer } from '../../lib/emailer'
import { AccountModel } from '../account/account' import { AccountModel } from '../account/account'
import { getSort, throwIfNotValid } from '../utils' import { getSort, throwIfNotValid } from '../utils'
@ -83,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
}) })
} }
toFormattedJSON () { toFormattedJSON (): VideoAbuse {
let reporterServerHost
if (this.Account.Actor.Server) {
reporterServerHost = this.Account.Actor.Server.host
} else {
// It means it's our video
reporterServerHost = CONFIG.WEBSERVER.HOST
}
return { return {
id: this.id, id: this.id,
reason: this.reason, reason: this.reason,
reporterUsername: this.Account.name, reporterAccount: this.Account.toFormattedJSON(),
reporterServerHost, video: {
videoId: this.Video.id, id: this.Video.id,
videoUUID: this.Video.uuid, uuid: this.Video.uuid,
videoName: this.Video.name, url: this.Video.url,
name: this.Video.name
},
createdAt: this.createdAt createdAt: this.createdAt
} }
} }

View File

@ -2,6 +2,7 @@
import * as chai from 'chai' import * as chai from 'chai'
import 'mocha' import 'mocha'
import { VideoAbuse } from '../../../../shared/models/videos'
import { import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
flushTests, flushTests,
@ -83,11 +84,11 @@ describe('Test video abuses', function () {
expect(res1.body.data).to.be.an('array') expect(res1.body.data).to.be.an('array')
expect(res1.body.data.length).to.equal(1) 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.reason).to.equal('my super bad reason')
expect(abuse.reporterUsername).to.equal('root') expect(abuse.reporterAccount.name).to.equal('root')
expect(abuse.reporterServerHost).to.equal('localhost:9001') expect(abuse.reporterAccount.host).to.equal('localhost:9001')
expect(abuse.videoId).to.equal(servers[0].video.id) expect(abuse.video.id).to.equal(servers[0].video.id)
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
expect(res2.body.total).to.equal(0) 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).to.be.an('array')
expect(res1.body.data.length).to.equal(2) 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.reason).to.equal('my super bad reason')
expect(abuse1.reporterUsername).to.equal('root') expect(abuse1.reporterAccount.name).to.equal('root')
expect(abuse1.reporterServerHost).to.equal('localhost:9001') expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
expect(abuse1.videoId).to.equal(servers[0].video.id) 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.reason).to.equal('my super bad reason 2')
expect(abuse2.reporterUsername).to.equal('root') expect(abuse2.reporterAccount.name).to.equal('root')
expect(abuse2.reporterServerHost).to.equal('localhost:9001') expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
expect(abuse2.videoId).to.equal(servers[1].video.id) expect(abuse2.video.id).to.equal(servers[1].video.id)
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
expect(res2.body.total).to.equal(1) expect(res2.body.total).to.equal(1)
expect(res2.body.data).to.be.an('array') expect(res2.body.data).to.be.an('array')
expect(res2.body.data.length).to.equal(1) 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.reason).to.equal('my super bad reason 2')
expect(abuse3.reporterUsername).to.equal('root') expect(abuse3.reporterAccount.name).to.equal('root')
expect(abuse3.reporterServerHost).to.equal('localhost:9001') expect(abuse3.reporterAccount.host).to.equal('localhost:9001')
}) })
after(async function () { after(async function () {

View File

@ -420,7 +420,8 @@ async function completeVideoCheck (
expect(videoDetails.tags).to.deep.equal(attributes.tags) expect(videoDetails.tags).to.deep.equal(attributes.tags)
expect(videoDetails.privacy).to.deep.equal(attributes.privacy) expect(videoDetails.privacy).to.deep.equal(attributes.privacy)
expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[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.commentsEnabled).to.equal(attributes.commentsEnabled)
expect(videoDetails.channel.displayName).to.equal(attributes.channel.name) expect(videoDetails.channel.displayName).to.equal(attributes.channel.name)

View File

@ -1,10 +1,14 @@
import { Account } from '../actors'
export interface VideoAbuse { export interface VideoAbuse {
id: number id: number
reason: string reason: string
reporterUsername: string reporterAccount: Account
reporterServerHost: string video: {
videoId: number id: number
videoUUID: string name: string
videoName: string uuid: string
url: string
}
createdAt: Date createdAt: Date
} }

View File

@ -1094,16 +1094,13 @@ definitions:
type: number type: number
reason: reason:
type: string type: string
reporterUsername: reporterAccount:
type: string $ref: "#/definitions/Account"
reporterServerHost: video:
type: string id: number
videoId: name: string
type: number uuid: string
videoUUID: url: string
type: string
videoName:
type: string
createdAt: createdAt:
type: string type: string
VideoBlacklist: VideoBlacklist: