Federate video abuses
authorChocobozzz <florian.bigard@gmail.com>
Thu, 16 Nov 2017 16:04:19 +0000 (17:04 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Nov 2017 18:40:52 +0000 (19:40 +0100)
server/controllers/api/videos/abuse.ts
server/helpers/custom-validators/activitypub/videos.ts
server/lib/activitypub/misc.ts
server/lib/activitypub/send-request.ts
server/models/video/video-abuse-interface.ts
server/models/video/video-abuse.ts
server/models/video/video.ts

index d9b4e8772fabfe766d72ce3970b18e1884b1bb9f..88b3d538deeb78c987e19d6e68e7e71ef23643b8 100644 (file)
@@ -75,6 +75,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
 
   await db.sequelize.transaction(async t => {
     const videoAbuseInstance = await db.VideoAbuse.create(abuseToCreate, { transaction: t })
+    videoAbuseInstance.Video = videoInstance
 
     // We send the video abuse to the origin server
     if (videoInstance.isOwned() === false) {
index 8486297adfcfd2bd41a388c67720fc2b3ea3ef98..728511e3db5e8a21c3a8e8fea0bdc02c0b3da883 100644 (file)
@@ -58,9 +58,10 @@ function isVideoTorrentObjectValid (video: any) {
 }
 
 function isVideoFlagValid (activity: any) {
-  return isBaseActivityValid(activity, 'Flag') &&
-    isVideoAbuseReasonValid(activity.content) &&
-    isActivityPubUrlValid(activity.object)
+  return isBaseActivityValid(activity, 'Create') &&
+    activity.object.type === 'Flag' &&
+    isVideoAbuseReasonValid(activity.object.content) &&
+    isActivityPubUrlValid(activity.object.object)
 }
 
 function isAnnounceValid (activity: any) {
index f853d742e05c9e9df72bd465faf62771786dd66c..c07d9f654466274ce08bee0e9de6ea8d0f240882 100644 (file)
@@ -1,14 +1,12 @@
 import * as magnetUtil from 'magnet-uri'
-import * as Sequelize from 'sequelize'
 import { VideoTorrentObject } from '../../../shared'
+import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
 import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
-import { database as db } from '../../initializers'
 import { VIDEO_MIMETYPE_EXT } from '../../initializers/constants'
+import { AccountInstance } from '../../models/account/account-interface'
 import { VideoChannelInstance } from '../../models/video/video-channel-interface'
 import { VideoFileAttributes } from '../../models/video/video-file-interface'
 import { VideoAttributes, VideoInstance } from '../../models/video/video-interface'
-import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
-import { AccountInstance } from '../../models/account/account-interface'
 
 function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) {
   return {
index d5d07011ab0d36eea214b68eabd59f4f6cca8c20..abc1b598db58b8ee887c4d72734f0ff4b990537c 100644 (file)
@@ -8,7 +8,7 @@ import {
 } from '../../models'
 import { httpRequestJobScheduler } from '../jobs'
 import { signObject, activityPubContextify } from '../../helpers'
-import { Activity } from '../../../shared'
+import { Activity, VideoAbuseObject } from '../../../shared'
 import { VideoAbuseInstance } from '../../models/video/video-abuse-interface'
 import { getActivityPubUrl } from '../../helpers/activitypub'
 import { logger } from '../../helpers/logger'
@@ -96,7 +96,7 @@ async function sendVideoAbuse (
   t: Sequelize.Transaction
 ) {
   const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString())
-  const data = await createActivityData(url, fromAccount, video.url)
+  const data = await createActivityData(url, fromAccount, videoAbuse.toActivityPubObject())
 
   return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t)
 }
index 96f0fbe4a2a7f66dc2e068568db0afad3a0aebfa..feafc4a19640b7c337ba9e0dd05a4ec94d2e17fb 100644 (file)
@@ -5,15 +5,18 @@ import { VideoAbuse as FormattedVideoAbuse } from '../../../shared/models/videos
 import { AccountInstance } from '../account/account-interface'
 import { ServerInstance } from '../server/server-interface'
 import { VideoInstance } from './video-interface'
+import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
 
 export namespace VideoAbuseMethods {
   export type ToFormattedJSON = (this: VideoAbuseInstance) => FormattedVideoAbuse
 
   export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoAbuseInstance> >
+  export type ToActivityPubObject = () => VideoAbuseObject
 }
 
 export interface VideoAbuseClass {
   listForApi: VideoAbuseMethods.ListForApi
+  toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
 }
 
 export interface VideoAbuseAttributes {
index f3fdeab524807cc7fee5bb65cc191ca2c0ad934e..e8f4f9a67e53c96eb6d3977263f2dccb5494f87e 100644 (file)
@@ -10,10 +10,12 @@ import {
 
   VideoAbuseMethods
 } from './video-abuse-interface'
+import { VideoAbuseObject } from '../../../shared/models/activitypub/objects/video-abuse-object'
 
 let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
 let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON
 let listForApi: VideoAbuseMethods.ListForApi
+let toActivityPubObject: VideoAbuseMethods.ToActivityPubObject
 
 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
   VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse',
@@ -47,7 +49,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
     listForApi
   ]
   const instanceMethods = [
-    toFormattedJSON
+    toFormattedJSON,
+    toActivityPubObject
   ]
   addMethodsToModel(VideoAbuse, classMethods, instanceMethods)
 
@@ -80,6 +83,16 @@ toFormattedJSON = function (this: VideoAbuseInstance) {
   return json
 }
 
+toActivityPubObject = function (this: VideoAbuseInstance) {
+  const videoAbuseObject: VideoAbuseObject = {
+    type: 'Flag' as 'Flag',
+    content: this.reason,
+    object: this.Video.url
+  }
+
+  return videoAbuseObject
+}
+
 // ------------------------------ STATICS ------------------------------
 
 function associate (models) {
index 5b0377c2e67e25df3553090cb4e50b0f38cee0f9..5fb254b2d8f43ec7acd31868dbb310fe15d917a0 100644 (file)
@@ -26,6 +26,7 @@ import {
   unlinkPromise,
   writeFilePromise
 } from '../../helpers'
+import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
 import {
   API_VERSION,
   CONFIG,
@@ -39,14 +40,13 @@ import {
   VIDEO_LICENCES,
   VIDEO_PRIVACIES
 } from '../../initializers'
+import { sendDeleteVideo } from '../../lib/activitypub/send-request'
 
 import { addMethodsToModel, getSort } from '../utils'
 
 import { TagInstance } from './tag-interface'
 import { VideoFileInstance, VideoFileModel } from './video-file-interface'
 import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
-import { sendDeleteVideo } from '../../lib/activitypub/send-request'
-import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
 
 const Buffer = safeBuffer.Buffer