Browse Source

Merge branch 'sumer' into sumer-content-dir-module

Mokhtar Naamani 4 years ago
parent
commit
19484bcdf2

+ 8 - 9
runtime-modules/common/src/storage.rs

@@ -1,3 +1,4 @@
+use crate::working_group::WorkingGroup;
 use codec::{Decode, Encode};
 #[cfg(feature = "std")]
 use serde::{Deserialize, Serialize};
@@ -13,21 +14,13 @@ pub struct ContentParameters<ContentId, DataObjectTypeId> {
 }
 
 // TODO Reuse enum in ../working_group.rs
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
-pub enum WorkingGroupType {
-    ContentDirectory,
-    Builders,
-    StorageProviders,
-}
-
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
 pub enum AbstractStorageObjectOwner<ChannelId, DAOId> {
     Channel(ChannelId), // acts through content directory module, where again DAOs can own channels for example
     DAO(DAOId),         // acts through upcoming `content_finance` module
     Council,            // acts through proposal system
-    WorkingGroup(WorkingGroupType), // acts through new extrinsic in working group
+    WorkingGroup(WorkingGroup), // acts through new extrinsic in working group
 }
 
 // New owner type for storage object struct
@@ -49,4 +42,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>>,
+    ) -> DispatchResult;
 }

+ 1 - 1
runtime-modules/common/src/working_group.rs

@@ -6,7 +6,7 @@ use strum_macros::EnumIter;
 
 /// Defines well-known working groups.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize, EnumIter))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Copy, Debug)]
+#[derive(Clone, Copy, Encode, Decode, PartialEq, Eq, Debug)]
 pub enum WorkingGroup {
     /* Reserved
         /// Forum working group: working_group::Instance1.

+ 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>>>,
+    ) -> DispatchResult {
+        T::StorageProviderHelper::get_random_storage_provider()?;
+        Self::ensure_content_is_valid(&content)
+    }
 }