Browse Source

Storage: add can_add_content check

iorveth 4 years ago
parent
commit
ca9110ed1e

+ 6 - 0
runtime-modules/common/src/storage.rs

@@ -48,4 +48,10 @@ pub trait StorageSystem<T: crate::StorageOwnership + crate::MembershipTypes> {
         owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
         content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
     ) -> DispatchResult;
+
+    // Checks if given owner can add provided content to the storage system
+    fn can_add_content(
+        owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
+        content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
+    ) -> bool;
 }

+ 8 - 0
runtime-modules/storage/src/data_directory.rs

@@ -440,4 +440,12 @@ impl<T: Trait> common::storage::StorageSystem<T> for Module<T> {
         Self::upload_content(liaison, content, owner);
         Ok(())
     }
+
+    fn can_add_content(
+        _owner: StorageObjectOwner<MemberId<T>, ChannelId<T>, DAOId<T>>,
+        content: Vec<ContentParameters<T::ContentId, DataObjectTypeId<T>>>,
+    ) -> bool {
+        Self::ensure_content_is_valid(&content).is_ok()
+            && T::StorageProviderHelper::get_random_storage_provider().is_ok()
+    }
 }