diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-15 15:12:23 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (patch) | |
tree | a59070f4dc6b52a5b422bd31a8eb8ea3bff831a0 /server/models | |
parent | 59c857da5961e2bcddcfd07832783c1e4afcd01a (diff) | |
download | PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.gz PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.zst PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.zip |
Add video abuse to activity pub
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-abuse-interface.ts | 14 | ||||
-rw-r--r-- | server/models/video/video-abuse.ts | 44 |
2 files changed, 31 insertions, 27 deletions
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index 16806cae2..96f0fbe4a 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Promise from 'bluebird' | 1 | import * as Promise from 'bluebird' |
3 | 2 | import * as Sequelize from 'sequelize' | |
4 | import { ServerInstance } from '../server/server-interface' | ||
5 | import { ResultList } from '../../../shared' | 3 | import { ResultList } from '../../../shared' |
6 | |||
7 | // Don't use barrel, import just what we need | ||
8 | import { VideoAbuse as FormattedVideoAbuse } from '../../../shared/models/videos/video-abuse.model' | 4 | import { VideoAbuse as FormattedVideoAbuse } from '../../../shared/models/videos/video-abuse.model' |
5 | import { AccountInstance } from '../account/account-interface' | ||
6 | import { ServerInstance } from '../server/server-interface' | ||
7 | import { VideoInstance } from './video-interface' | ||
9 | 8 | ||
10 | export namespace VideoAbuseMethods { | 9 | export namespace VideoAbuseMethods { |
11 | export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse | 10 | export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse |
@@ -18,9 +17,12 @@ export interface VideoAbuseClass { | |||
18 | } | 17 | } |
19 | 18 | ||
20 | export interface VideoAbuseAttributes { | 19 | export interface VideoAbuseAttributes { |
21 | reporterUsername: string | ||
22 | reason: string | 20 | reason: string |
23 | videoId: number | 21 | videoId: number |
22 | reporterAccountId: number | ||
23 | |||
24 | Account?: AccountInstance | ||
25 | Video?: VideoInstance | ||
24 | } | 26 | } |
25 | 27 | ||
26 | export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> { | 28 | export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> { |
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index c1d070ec0..f3fdeab52 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { CONFIG } from '../../initializers' | 3 | import { CONFIG } from '../../initializers' |
4 | import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../../helpers' | 4 | import { isVideoAbuseReasonValid } from '../../helpers' |
5 | 5 | ||
6 | import { addMethodsToModel, getSort } from '../utils' | 6 | import { addMethodsToModel, getSort } from '../utils' |
7 | import { | 7 | import { |
@@ -18,16 +18,6 @@ let listForApi: VideoAbuseMethods.ListForApi | |||
18 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 18 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
19 | VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', | 19 | VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', |
20 | { | 20 | { |
21 | reporterUsername: { | ||
22 | type: DataTypes.STRING, | ||
23 | allowNull: false, | ||
24 | validate: { | ||
25 | reporterUsernameValid: value => { | ||
26 | const res = isVideoAbuseReporterUsernameValid(value) | ||
27 | if (res === false) throw new Error('Video abuse reporter username is not valid.') | ||
28 | } | ||
29 | } | ||
30 | }, | ||
31 | reason: { | 21 | reason: { |
32 | type: DataTypes.STRING, | 22 | type: DataTypes.STRING, |
33 | allowNull: false, | 23 | allowNull: false, |
@@ -45,7 +35,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
45 | fields: [ 'videoId' ] | 35 | fields: [ 'videoId' ] |
46 | }, | 36 | }, |
47 | { | 37 | { |
48 | fields: [ 'reporterServerId' ] | 38 | fields: [ 'reporterAccountId' ] |
49 | } | 39 | } |
50 | ] | 40 | ] |
51 | } | 41 | } |
@@ -69,8 +59,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
69 | toFormattedJSON = function (this: VideoAbuseInstance) { | 59 | toFormattedJSON = function (this: VideoAbuseInstance) { |
70 | let reporterServerHost | 60 | let reporterServerHost |
71 | 61 | ||
72 | if (this.Server) { | 62 | if (this.Account.Server) { |
73 | reporterServerHost = this.Server.host | 63 | reporterServerHost = this.Account.Server.host |
74 | } else { | 64 | } else { |
75 | // It means it's our video | 65 | // It means it's our video |
76 | reporterServerHost = CONFIG.WEBSERVER.HOST | 66 | reporterServerHost = CONFIG.WEBSERVER.HOST |
@@ -78,10 +68,12 @@ toFormattedJSON = function (this: VideoAbuseInstance) { | |||
78 | 68 | ||
79 | const json = { | 69 | const json = { |
80 | id: this.id, | 70 | id: this.id, |
81 | reporterServerHost, | ||
82 | reason: this.reason, | 71 | reason: this.reason, |
83 | reporterUsername: this.reporterUsername, | 72 | reporterUsername: this.Account.name, |
84 | videoId: this.videoId, | 73 | reporterServerHost, |
74 | videoId: this.Video.id, | ||
75 | videoUUID: this.Video.uuid, | ||
76 | videoName: this.Video.name, | ||
85 | createdAt: this.createdAt | 77 | createdAt: this.createdAt |
86 | } | 78 | } |
87 | 79 | ||
@@ -91,9 +83,9 @@ toFormattedJSON = function (this: VideoAbuseInstance) { | |||
91 | // ------------------------------ STATICS ------------------------------ | 83 | // ------------------------------ STATICS ------------------------------ |
92 | 84 | ||
93 | function associate (models) { | 85 | function associate (models) { |
94 | VideoAbuse.belongsTo(models.Server, { | 86 | VideoAbuse.belongsTo(models.Account, { |
95 | foreignKey: { | 87 | foreignKey: { |
96 | name: 'reporterServerId', | 88 | name: 'reporterAccountId', |
97 | allowNull: true | 89 | allowNull: true |
98 | }, | 90 | }, |
99 | onDelete: 'CASCADE' | 91 | onDelete: 'CASCADE' |
@@ -115,8 +107,18 @@ listForApi = function (start: number, count: number, sort: string) { | |||
115 | order: [ getSort(sort) ], | 107 | order: [ getSort(sort) ], |
116 | include: [ | 108 | include: [ |
117 | { | 109 | { |
118 | model: VideoAbuse['sequelize'].models.Server, | 110 | model: VideoAbuse['sequelize'].models.Account, |
119 | required: false | 111 | required: true, |
112 | include: [ | ||
113 | { | ||
114 | model: VideoAbuse['sequelize'].models.Server, | ||
115 | required: false | ||
116 | } | ||
117 | ] | ||
118 | }, | ||
119 | { | ||
120 | model: VideoAbuse['sequelize'].models.Video, | ||
121 | required: true | ||
120 | } | 122 | } |
121 | ] | 123 | ] |
122 | } | 124 | } |