Fix removing scheduled update
authorChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 08:24:53 +0000 (10:24 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 08:26:20 +0000 (10:26 +0200)
client/src/app/shared/video/video-edit.model.ts
client/src/app/shared/video/video.service.ts
server/controllers/api/videos/index.ts
server/middlewares/validators/videos.ts
server/models/video/schedule-video-update.ts

index 78aed4f9f8d92523f9b9d9cd42686213233f8901..8562f8d2540d662d8ea030a6adf08a55899c6cb8 100644 (file)
@@ -55,7 +55,7 @@ export class VideoEdit implements VideoUpdate {
     })
 
     // If schedule publication, the video is private and will be changed to public privacy
-    if (values['schedulePublicationAt']) {
+    if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
       const updateAt = (values['schedulePublicationAt'] as Date)
       updateAt.setSeconds(0)
 
@@ -64,6 +64,8 @@ export class VideoEdit implements VideoUpdate {
         updateAt: updateAt.toISOString(),
         privacy: VideoPrivacy.PUBLIC
       }
+    } else {
+      this.scheduleUpdate = null
     }
   }
 
index 3af90e7ad63939fb2d4d333a406ffca4591bea22..2da36ff1b721fb8f8afa6621262fbd8cec3d4a61 100644 (file)
@@ -68,6 +68,7 @@ export class VideoService {
     const category = video.category || null
     const description = video.description || null
     const support = video.support || null
+    const scheduleUpdate = video.scheduleUpdate || null
 
     const body: VideoUpdate = {
       name: video.name,
@@ -84,7 +85,7 @@ export class VideoService {
       commentsEnabled: video.commentsEnabled,
       thumbnailfile: video.thumbnailfile,
       previewfile: video.previewfile,
-      scheduleUpdate: video.scheduleUpdate || undefined
+      scheduleUpdate
     }
 
     const data = objectToFormData(body)
index 79ca4699ff536499b7cb667979ecf52b2a09bc64..ca800a9a8bece715915a307b93d0b2845176479f 100644 (file)
@@ -342,10 +342,12 @@ async function updateVideo (req: express.Request, res: express.Response) {
           updateAt: videoInfoToUpdate.scheduleUpdate.updateAt,
           privacy: videoInfoToUpdate.scheduleUpdate.privacy || null
         }, { transaction: t })
+      } else if (videoInfoToUpdate.scheduleUpdate === null) {
+        await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
       }
 
       const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
-      await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo)
+      await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
     })
 
     logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)
index da17b4a68d44d5f16bce41eb7784a4e27cdeed3d..5595edf1795aa5838ceb9ef93bd25028f862b0bc 100644 (file)
@@ -94,6 +94,9 @@ const videosAddValidator = [
   body('channelId')
     .toInt()
     .custom(isIdValid).withMessage('Should have correct video channel id'),
+  body('scheduleUpdate')
+    .optional()
+    .customSanitizer(toValueOrNull),
   body('scheduleUpdate.updateAt')
     .optional()
     .custom(isDateValid).withMessage('Should have a valid schedule update date'),
@@ -199,6 +202,9 @@ const videosUpdateValidator = [
     .optional()
     .toInt()
     .custom(isIdValid).withMessage('Should have correct video channel id'),
+  body('scheduleUpdate')
+    .optional()
+    .customSanitizer(toValueOrNull),
   body('scheduleUpdate.updateAt')
     .optional()
     .custom(isDateValid).withMessage('Should have a valid schedule update date'),
index 3cf5f6c99b06591fe81260f6479553d348d0eedc..1e56562e1974dae3f4f198036b6719a692796ea8 100644 (file)
@@ -83,6 +83,17 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
     return ScheduleVideoUpdateModel.findAll(query)
   }
 
+  static deleteByVideoId (videoId: number, t: Transaction) {
+    const query = {
+      where: {
+        videoId
+      },
+      transaction: t
+    }
+
+    return ScheduleVideoUpdateModel.destroy(query)
+  }
+
   toFormattedJSON () {
     return {
       updateAt: this.updateAt,