Fix unset video language on video update
authorChocobozzz <florian.bigard@gmail.com>
Fri, 5 May 2017 12:29:58 +0000 (14:29 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 5 May 2017 12:29:58 +0000 (14:29 +0200)
client/src/app/videos/shared/video.service.ts
client/src/app/videos/video-edit/video-update.component.ts
server/controllers/api/videos.js
server/helpers/custom-validators/videos.js

index ba83c72fd12a8933e630399f1d17627d71cc625b..ef683dea68f42e8348b316eed59f93a8eef37caa 100644 (file)
@@ -81,14 +81,17 @@ export class VideoService {
   }
 
   updateVideo(video: Video) {
+    const language = video.language ? video.language : null;
+
     const body = {
       name: video.name,
       category: video.category,
       licence: video.licence,
-      language: video.language,
+      language,
       description: video.description,
       tags: video.tags
     };
+
     const headers = new Headers({ 'Content-Type': 'application/json' });
     const options = new RequestOptions({ headers: headers });
 
index adb3d295c084b10b2e4a2866580dbcbc2f09cfcc..933132cc0643077de1b8573fb882de6001f72a51 100644 (file)
@@ -98,7 +98,17 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
                      );
   }
 
+  checkForm() {
+    this.forceCheck();
+
+    return this.form.valid;
+  }
+
   update() {
+    if (this.checkForm() === false) {
+      return;
+    }
+
     this.video.patch(this.form.value);
 
     this.videoService.updateVideo(this.video)
index 4a4c5e162c0f7b21d7586b015073db6f27812c15..aeefaa555e6ee25440a858027cba8edb7added7b 100644 (file)
@@ -444,12 +444,12 @@ function updateVideo (req, res, finalCallback) {
         transaction: t
       }
 
-      if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
-      if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
-      if (videoInfosToUpdate.licence) videoInstance.set('licence', videoInfosToUpdate.licence)
-      if (videoInfosToUpdate.language) videoInstance.set('language', videoInfosToUpdate.language)
-      if (videoInfosToUpdate.nsfw) videoInstance.set('nsfw', videoInfosToUpdate.nsfw)
-      if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
+      if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name)
+      if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category)
+      if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence)
+      if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language)
+      if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw)
+      if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description)
 
       videoInstance.save(options).asCallback(function (err) {
         return callback(err, t, tagInstances)
index 8dabb828d0d51941b626671d17fac7c6e126e405..196731e04228d5ce870207f4902f5d95ead160af 100644 (file)
@@ -53,7 +53,7 @@ function isVideoLicenceValid (value) {
 }
 
 function isVideoLanguageValid (value) {
-  return constants.VIDEO_LANGUAGES[value] !== undefined
+  return value === null || constants.VIDEO_LANGUAGES[value] !== undefined
 }
 
 function isVideoNSFWValid (value) {