Browse Source

Merge pull request #1772 from iorveth/fix/issue_1367

ensure_is_thread_author should not do thread mutability check
Bedeho Mender 4 years ago
parent
commit
7817fccc67
1 changed files with 11 additions and 10 deletions
  1. 11 10
      runtime-modules/forum/src/lib.rs

+ 11 - 10
runtime-modules/forum/src/lib.rs

@@ -1129,24 +1129,25 @@ impl<T: Trait> Module<T> {
         // Check that account is forum member
         Self::ensure_is_forum_user(account_id, &forum_user_id)?;
 
+        // Ensure thread is mutable
+        let (_, thread) = Self::ensure_thread_is_mutable(category_id, thread_id)?;
+
         // Ensure forum user is author of the thread
-        let thread = Self::ensure_is_thread_author(&category_id, &thread_id, &forum_user_id)?;
+        Self::ensure_is_thread_author(&thread, forum_user_id)?;
 
         Ok(thread)
     }
 
     fn ensure_is_thread_author(
-        category_id: &T::CategoryId,
-        thread_id: &T::ThreadId,
+        thread: &Thread<T::ForumUserId, T::CategoryId, T::Moment, T::Hash>,
         forum_user_id: &T::ForumUserId,
-    ) -> Result<Thread<T::ForumUserId, T::CategoryId, T::Moment, T::Hash>, Error<T>> {
-        let (_, thread) = Self::ensure_thread_is_mutable(category_id, thread_id)?;
-
-        if thread.author_id != *forum_user_id {
-            return Err(Error::<T>::AccountDoesNotMatchThreadAuthor);
-        }
+    ) -> Result<(), Error<T>> {
+        ensure!(
+            thread.author_id == *forum_user_id,
+            Error::<T>::AccountDoesNotMatchThreadAuthor
+        );
 
-        Ok(thread)
+        Ok(())
     }
 
     fn ensure_actor_role(