Browse Source

Allow empty vector as a value for optional channel fields: title, description, avatar, banner

Alex Siman 5 years ago
parent
commit
18ee62a9dc
1 changed files with 25 additions and 8 deletions
  1. 25 8
      src/content_working_group/lib.rs

+ 25 - 8
src/content_working_group/lib.rs

@@ -2100,33 +2100,50 @@ impl<T: Trait> Module<T> {
         Ok(())
     }
 
-    fn ensure_channel_title_is_valid(title: &Vec<u8>) -> dispatch::Result {
+    
+    fn ensure_channel_title_is_valid(text: &Vec<u8>) -> dispatch::Result {
+        if text.is_empty() {
+            return Ok(())
+        }
+
         ChannelTitleConstraint::get().ensure_valid(
-            title.len(),
+            text.len(),
             MSG_CHANNEL_TITLE_TOO_SHORT,
             MSG_CHANNEL_TITLE_TOO_LONG,
         )
     }
 
-    fn ensure_channel_description_is_valid(description: &Vec<u8>) -> dispatch::Result {
+    fn ensure_channel_description_is_valid(text: &Vec<u8>) -> dispatch::Result {
+        if text.is_empty() {
+            return Ok(())
+        }
+
         ChannelDescriptionConstraint::get().ensure_valid(
-            description.len(),
+            text.len(),
             MSG_CHANNEL_DESCRIPTION_TOO_SHORT,
             MSG_CHANNEL_DESCRIPTION_TOO_LONG,
         )
     }
 
-    fn ensure_channel_avatar_is_valid(avatar: &Vec<u8>) -> dispatch::Result {
+    fn ensure_channel_avatar_is_valid(text: &Vec<u8>) -> dispatch::Result {
+        if text.is_empty() {
+            return Ok(())
+        }
+
         ChannelAvatarConstraint::get().ensure_valid(
-            avatar.len(),
+            text.len(),
             MSG_CHANNEL_AVATAR_TOO_SHORT,
             MSG_CHANNEL_AVATAR_TOO_LONG,
         )
     }
 
-    fn ensure_channel_banner_is_valid(banner: &Vec<u8>) -> dispatch::Result {
+    fn ensure_channel_banner_is_valid(text: &Vec<u8>) -> dispatch::Result {
+        if text.is_empty() {
+            return Ok(())
+        }
+        
         ChannelBannerConstraint::get().ensure_valid(
-            banner.len(),
+            text.len(),
             MSG_CHANNEL_BANNER_TOO_SHORT,
             MSG_CHANNEL_BANNER_TOO_LONG,
         )