Browse Source

added extra moderator tests set

ignazio 3 years ago
parent
commit
21608cf37e

+ 1 - 1
runtime-modules/content/src/lib.rs

@@ -1866,7 +1866,7 @@ decl_module! {
             let sender = ensure_signed(origin)?;
             let owner = Self::ensure_channel_validity(&channel_id)?.owner;
 
-            ensure_actor_authorized_to_update_mod_set::<T>(
+            ensure_actor_can_manage_moderators::<T>(
                 &sender,
                 &actor,
                 &owner,

+ 13 - 10
runtime-modules/content/src/permissions/mod.rs

@@ -127,6 +127,19 @@ pub fn ensure_actor_can_manage_collaborators<T: Trait>(
     }
 }
 
+/// Ensure actor is authorized to manage moderator set for a channel
+pub fn ensure_actor_can_manage_moderators<T: Trait>(
+    sender: &T::AccountId,
+    owner: &ChannelOwner<T::MemberId, T::CuratorGroupId>,
+    actor: &ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
+) -> DispatchResult {
+    ensure_actor_auth_success::<T>(sender, actor)?;
+    match actor {
+        ContentActor::Lead => ensure_channel_is_owned_by_curators::<T>(owner),
+        _ => ensure_actor_is_channel_owner::<T>(actor, owner),
+    }
+}
+
 /// Ensure actor is authorized to manage reward account for a channel
 pub fn ensure_actor_can_manage_reward_account<T: Trait>(
     sender: &T::AccountId,
@@ -347,16 +360,6 @@ pub fn ensure_actor_is_comment_author<T: Trait>(
     Ok(())
 }
 
-// Authenticate actor and verify he's the owner
-pub fn ensure_actor_authorized_to_update_mod_set<T: Trait>(
-    sender: &T::AccountId,
-    actor: &ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
-    owner: &ChannelOwner<T::MemberId, T::CuratorGroupId>,
-) -> DispatchResult {
-    ensure_actor_auth_success::<T>(sender, actor)?;
-    ensure_actor_is_channel_owner::<T>(actor, owner)
-}
-
 pub fn actor_to_channel_owner<T: Trait>(
     actor: &ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
 ) -> Result<ChannelOwner<T::MemberId, T::CuratorGroupId>, DispatchError> {

+ 53 - 1
runtime-modules/content/src/tests/posts.rs

@@ -1112,7 +1112,7 @@ pub fn unsuccessful_moderators_update_with_invalid_members_id() {
 }
 
 #[test]
-pub fn successful_moderators_update_by_owner() {
+pub fn successful_moderators_update_by_member_owner() {
     with_default_mock_builder(|| {
         run_to_block(1);
 
@@ -1124,6 +1124,26 @@ pub fn successful_moderators_update_by_owner() {
     })
 }
 
+#[test]
+pub fn successful_moderators_update_by_curator_owner() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_curator_owned_channel();
+
+        let default_curator_group_id = Content::next_curator_group_id() - 1;
+        UpdateModeratorSetFixture::default()
+            .with_sender(DEFAULT_CURATOR_ACCOUNT_ID)
+            .with_actor(ContentActor::Curator(
+                default_curator_group_id,
+                DEFAULT_CURATOR_ID,
+            ))
+            .call_and_assert(Ok(()));
+    })
+}
+
 #[test]
 pub fn unsuccessful_moderators_update_with_invalid_channel_id() {
     with_default_mock_builder(|| {
@@ -1138,3 +1158,35 @@ pub fn unsuccessful_moderators_update_with_invalid_channel_id() {
             .call_and_assert(Err(Error::<Test>::ChannelDoesNotExist.into()))
     })
 }
+
+#[test]
+pub fn unsuccessful_moderators_update_by_lead_with_member_owned_channel() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_member_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_sender(LEAD_ACCOUNT_ID)
+            .with_actor(ContentActor::Lead)
+            .call_and_assert(Err(Error::<Test>::ActorCannotOwnChannel.into()))
+    })
+}
+
+#[test]
+pub fn successful_moderators_update_by_lead_with_curator_owned_channel() {
+    with_default_mock_builder(|| {
+        run_to_block(1);
+
+        create_initial_storage_buckets_helper();
+        increase_account_balance_helper(DEFAULT_CURATOR_ACCOUNT_ID, INITIAL_BALANCE);
+        create_default_curator_owned_channel();
+
+        UpdateModeratorSetFixture::default()
+            .with_sender(LEAD_ACCOUNT_ID)
+            .with_actor(ContentActor::Lead)
+            .call_and_assert(Ok(()))
+    })
+}