Browse Source

Rollback forum changes: remove working group dependency

Shamil Gadelshin 4 years ago
parent
commit
2bf2ac2421

+ 0 - 6
Cargo.lock

@@ -4823,13 +4823,7 @@ dependencies = [
  "srml-system",
  "srml-timestamp",
  "substrate-common-module",
- "substrate-hiring-module",
- "substrate-membership-module",
  "substrate-primitives",
- "substrate-recurring-reward-module",
- "substrate-stake-module",
- "substrate-token-mint-module",
- "substrate-working-group-module",
 ]
 
 [[package]]

+ 2 - 2
node/src/forum_config/from_serialized.rs

@@ -23,8 +23,7 @@ fn parse_forum_json() -> Result<ForumData> {
     serde_json::from_str(data)
 }
 
-//TODO: should we set the forum_sudo account in the working group module?
-pub fn create(_forum_sudo: AccountId) -> ForumConfig {
+pub fn create(forum_sudo: AccountId) -> ForumConfig {
     let forum_data = parse_forum_json().expect("failed loading forum data");
 
     let next_category_id: CategoryId = forum_data
@@ -47,5 +46,6 @@ pub fn create(_forum_sudo: AccountId) -> ForumConfig {
         post_text_constraint: new_validation(10, 990),
         thread_moderation_rationale_constraint: new_validation(10, 290),
         post_moderation_rationale_constraint: new_validation(10, 290),
+        forum_sudo,
     }
 }

+ 0 - 38
runtime-modules/forum/Cargo.toml

@@ -30,52 +30,15 @@ git = 'https://github.com/paritytech/substrate.git'
 package = 'sr-io'
 rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
 
-[dependencies.working-group]
-default_features = false
-package = 'substrate-working-group-module'
-path = '../working-group'
-version = '1.0.0'
-
 [dev-dependencies]
 runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
 primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
 
-[dev-dependencies.membership]
-default_features = false
-package = 'substrate-membership-module'
-path = '../membership'
-
-[dev-dependencies.minting]
-default_features = false
-package = 'substrate-token-mint-module'
-path = '../token-minting'
-
-[dev-dependencies.recurringrewards]
-default_features = false
-package = 'substrate-recurring-reward-module'
-path = '../recurring-reward'
-
-[dev-dependencies.balances]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'srml-balances'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
 [dependencies.common]
 default_features = false
 package = 'substrate-common-module'
 path = '../common'
 
-[dev-dependencies.hiring]
-default_features = false
-package = 'substrate-hiring-module'
-path = '../hiring'
-
-[dev-dependencies.stake]
-default_features = false
-package = 'substrate-stake-module'
-path = '../stake'
-
 [features]
 default = ['std']
 std = [
@@ -89,6 +52,5 @@ std = [
 	'system/std',
   	'balances/std',
 	'timestamp/std',
-	'working-group/std',
 	'common/std',
 ]

+ 62 - 22
runtime-modules/forum/src/lib.rs

@@ -9,20 +9,19 @@
 #[cfg(feature = "std")]
 use serde_derive::{Deserialize, Serialize};
 
-use codec::{Codec, Decode, Encode};
 use rstd::borrow::ToOwned;
 use rstd::prelude::*;
-use runtime_primitives::traits::EnsureOrigin;
+
+use codec::{Codec, Decode, Encode};
 use runtime_primitives::traits::{MaybeSerialize, Member, One, SimpleArithmetic};
 use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure, Parameter};
-use system::{ensure_signed, RawOrigin};
-
-pub use common::constraints::InputValidationLengthConstraint;
-use common::BlockAndTime;
 
 mod mock;
 mod tests;
 
+pub use common::constraints::InputValidationLengthConstraint;
+use common::BlockAndTime;
+
 /// Constants
 /////////////////////////////////////////////////////////////////
 
@@ -31,6 +30,8 @@ mod tests;
 const MAX_CATEGORY_DEPTH: u16 = 3;
 
 /// Error messages for dispatchables
+const ERROR_FORUM_SUDO_NOT_SET: &str = "Forum sudo not set.";
+const ERROR_ORIGIN_NOT_FORUM_SUDO: &str = "Origin not forum sudo.";
 const ERROR_CATEGORY_TITLE_TOO_SHORT: &str = "Category title too short.";
 const ERROR_CATEGORY_TITLE_TOO_LONG: &str = "Category title too long.";
 const ERROR_CATEGORY_DESCRIPTION_TOO_SHORT: &str = "Category description too long.";
@@ -58,6 +59,8 @@ const ERROR_CATEGORY_NOT_BEING_UPDATED: &str = "Category not being updated.";
 const ERROR_CATEGORY_CANNOT_BE_UNARCHIVED_WHEN_DELETED: &str =
     "Category cannot be unarchived when deleted.";
 
+use system::{ensure_root, ensure_signed};
+
 /// Represents a user in this forum.
 #[derive(Debug, Copy, Clone)]
 pub struct ForumUser<AccountId> {
@@ -258,9 +261,6 @@ pub trait Trait: system::Trait + timestamp::Trait + Sized {
 
     type MembershipRegistry: ForumUserRegistry<Self::AccountId>;
 
-    /// Checks that provided signed account belongs to the leader
-    type EnsureForumLeader: EnsureOrigin<Self::Origin>;
-
     /// Thread Id type
     type ThreadId: Parameter
         + Member
@@ -303,6 +303,9 @@ decl_storage! {
         /// Post identifier value to be used for for next post created.
         pub NextPostId get(next_post_id) config(): T::PostId;
 
+        /// Account of forum sudo.
+        pub ForumSudo get(forum_sudo) config(): Option<T::AccountId>;
+
         /// Input constraints
         /// These are all forward looking, that is they are enforced on all
         /// future calls.
@@ -379,14 +382,39 @@ decl_module! {
 
         fn deposit_event() = default;
 
+        /// Set forum sudo.
+        fn set_forum_sudo(origin, new_forum_sudo: Option<T::AccountId>) -> dispatch::Result {
+            ensure_root(origin)?;
+
+            /*
+             * Question: when this routine is called by non sudo or with bad signature, what error is raised?
+             * Update ERror set in spec
+             */
+
+            // Hold on to old value
+            let old_forum_sudo = <ForumSudo<T>>::get();
+
+            // Update forum sudo
+            match new_forum_sudo.clone() {
+                Some(account_id) => <ForumSudo<T>>::put(account_id),
+                None => <ForumSudo<T>>::kill()
+            };
+
+            // Generate event
+            Self::deposit_event(RawEvent::ForumSudoSet(old_forum_sudo, new_forum_sudo));
+
+            // All good.
+            Ok(())
+        }
+
         /// Add a new category.
         fn create_category(origin, parent: Option<CategoryId>, title: Vec<u8>, description: Vec<u8>) -> dispatch::Result {
 
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
 
-            // Not signed by forum lead
-            Self::ensure_is_forum_lead(&who)?;
+            // Not signed by forum SUDO
+            Self::ensure_is_forum_sudo(&who)?;
 
             // Validate title
             Self::ensure_category_title_is_valid(&title)?;
@@ -464,8 +492,8 @@ decl_module! {
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
 
-            // Not signed by forum lead
-            Self::ensure_is_forum_lead(&who)?;
+            // Not signed by forum SUDO
+            Self::ensure_is_forum_sudo(&who)?;
 
             // Make sure something is actually being changed
             ensure!(
@@ -570,8 +598,8 @@ decl_module! {
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
 
-            // Signed by forum lead
-            Self::ensure_is_forum_lead(&who)?;
+            // Signed by forum SUDO
+            Self::ensure_is_forum_sudo(&who)?;
 
             // Get thread
             let mut thread = Self::ensure_thread_exists(thread_id)?;
@@ -705,8 +733,8 @@ decl_module! {
             // Check that its a valid signature
             let who = ensure_signed(origin)?;
 
-            // Signed by forum lead
-            Self::ensure_is_forum_lead(&who)?;
+            // Signed by forum SUDO
+            Self::ensure_is_forum_sudo(&who)?;
 
             // Make sure post exists and is mutable
             let post = Self::ensure_post_is_mutable(post_id)?;
@@ -844,9 +872,20 @@ impl<T: Trait> Module<T> {
         }
     }
 
-    fn ensure_is_forum_lead(account_id: &T::AccountId) -> dispatch::Result {
-        T::EnsureForumLeader::ensure_origin(RawOrigin::Signed(account_id.clone()).into())?;
+    fn ensure_forum_sudo_set() -> Result<T::AccountId, &'static str> {
+        match <ForumSudo<T>>::get() {
+            Some(account_id) => Ok(account_id),
+            None => Err(ERROR_FORUM_SUDO_NOT_SET),
+        }
+    }
 
+    fn ensure_is_forum_sudo(account_id: &T::AccountId) -> dispatch::Result {
+        let forum_sudo_account = Self::ensure_forum_sudo_set()?;
+
+        ensure!(
+            *account_id == forum_sudo_account,
+            ERROR_ORIGIN_NOT_FORUM_SUDO
+        );
         Ok(())
     }
 
@@ -868,9 +907,10 @@ impl<T: Trait> Module<T> {
         Self::ensure_can_mutate_in_path_leaf(&category_tree_path)
     }
 
-    // Clippy linter warning
-    #[allow(clippy::ptr_arg)] // disable it because of possible frontend API break
-                              // TODO: remove post-Constaninople
+    // TODO: remove post-Constaninople
+    // Clippy linter warning.
+    // Disable it because of possible frontend API break.
+    #[allow(clippy::ptr_arg)]
     fn ensure_can_mutate_in_path_leaf(
         category_tree_path: &CategoryTreePath<T::BlockNumber, T::Moment, T::AccountId>,
     ) -> dispatch::Result {

+ 8 - 82
runtime-modules/forum/src/mock.rs

@@ -71,11 +71,6 @@ parameter_types! {
     pub const MaximumBlockLength: u32 = 2 * 1024;
     pub const AvailableBlockRatio: Perbill = Perbill::one();
     pub const MinimumPeriod: u64 = 5;
-    pub const InitialMembersBalance: u64 = 2000;
-    pub const ExistentialDeposit: u32 = 0;
-    pub const TransferFee: u32 = 0;
-    pub const CreationFee: u32 = 0;
-    pub const StakePoolId: [u8; 8] = *b"joystake";
 }
 
 impl system::Trait for Runtime {
@@ -103,66 +98,9 @@ impl timestamp::Trait for Runtime {
     type MinimumPeriod = MinimumPeriod;
 }
 
-impl working_group::Trait<working_group::Instance1> for Runtime {
-    type Event = ();
-}
-
-impl recurringrewards::Trait for Runtime {
-    type PayoutStatusHandler = ();
-    type RecipientId = u64;
-    type RewardRelationshipId = u64;
-}
-
-impl stake::Trait for Runtime {
-    type Currency = Balances;
-    type StakePoolId = StakePoolId;
-    type StakingEventsHandler = ();
-    type StakeId = u64;
-    type SlashId = u64;
-}
-
-impl hiring::Trait for Runtime {
-    type OpeningId = u64;
-    type ApplicationId = u64;
-    type ApplicationDeactivatedHandler = ();
-    type StakeHandlerProvider = hiring::Module<Self>;
-}
-
-impl membership::members::Trait for Runtime {
-    type Event = ();
-    type MemberId = u64;
-    type PaidTermId = u64;
-    type SubscriptionId = u64;
-    type ActorId = u64;
-    type InitialMembersBalance = InitialMembersBalance;
-}
-
-impl balances::Trait for Runtime {
-    type Balance = u64;
-    type OnFreeBalanceZero = ();
-    type OnNewAccount = ();
-    type Event = ();
-    type DustRemoval = ();
-    type TransferPayment = ();
-    type ExistentialDeposit = ExistentialDeposit;
-    type TransferFee = TransferFee;
-    type CreationFee = CreationFee;
-}
-pub type Balances = balances::Module<Runtime>;
-
-impl common::currency::GovernanceCurrency for Runtime {
-    type Currency = Balances;
-}
-
-impl minting::Trait for Runtime {
-    type Currency = Balances;
-    type MintId = u64;
-}
-
 impl Trait for Runtime {
     type Event = ();
     type MembershipRegistry = registry::TestMembershipRegistryModule;
-    type EnsureForumLeader = working_group::Module<Runtime, working_group::Instance1>;
     type ThreadId = u64;
     type PostId = u64;
 }
@@ -171,19 +109,17 @@ impl Trait for Runtime {
 pub enum OriginType {
     Signed(<Runtime as system::Trait>::AccountId),
     //Inherent, <== did not find how to make such an origin yet
-    //Root,
+    Root,
 }
 
 pub fn mock_origin(origin: OriginType) -> mock::Origin {
     match origin {
         OriginType::Signed(account_id) => Origin::signed(account_id),
         //OriginType::Inherent => Origin::inherent,
-        //OriginType::Root => system::RawOrigin::Root.into(), //Origin::root
+        OriginType::Root => system::RawOrigin::Root.into(), //Origin::root
     }
 }
 
-pub static ERROR_ORIGIN_NOT_FORUM_SUDO: &str = "Invalid origin";
-
 pub const NOT_FORUM_SUDO_ORIGIN: OriginType = OriginType::Signed(111);
 
 pub const NOT_MEMBER_ORIGIN: OriginType = OriginType::Signed(222);
@@ -194,10 +130,6 @@ pub const INVLAID_THREAD_ID: RuntimeThreadId = 444;
 
 pub const INVLAID_POST_ID: RuntimePostId = 555;
 
-pub(crate) const FORUM_SUDO_ID: u64 = 33;
-
-pub(crate) const FORUM_SUDO_MEMBER_ID: u64 = 1;
-
 pub fn generate_text(len: usize) -> Vec<u8> {
     vec![b'x'; len]
 }
@@ -241,7 +173,6 @@ pub struct CreateCategoryFixture {
 
 impl CreateCategoryFixture {
     pub fn call_and_assert(&self) {
-        set_working_group_forum_lead();
         assert_eq!(
             TestForumModule::create_category(
                 mock_origin(self.origin.clone()),
@@ -264,7 +195,6 @@ pub struct UpdateCategoryFixture {
 
 impl UpdateCategoryFixture {
     pub fn call_and_assert(&self) {
-        set_working_group_forum_lead();
         assert_eq!(
             TestForumModule::update_category(
                 mock_origin(self.origin.clone()),
@@ -285,15 +215,6 @@ pub struct CreateThreadFixture {
     pub result: dispatch::Result,
 }
 
-type WorkingGroup1 = working_group::Module<Runtime, working_group::Instance1>;
-
-pub(crate) fn set_working_group_forum_lead() {
-    assert_eq!(
-        WorkingGroup1::set_lead(RawOrigin::Root.into(), FORUM_SUDO_MEMBER_ID, FORUM_SUDO_ID),
-        Ok(())
-    );
-}
-
 impl CreateThreadFixture {
     pub fn call_and_assert(&self) {
         assert_eq!(
@@ -464,7 +385,7 @@ pub fn assert_not_forum_sudo_cannot_update_category(
     update_operation: fn(OriginType, CategoryId) -> dispatch::Result,
 ) {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(origin.clone());
@@ -491,6 +412,8 @@ pub fn default_genesis_config() -> GenesisConfig<Runtime> {
         post_by_id: vec![],
         next_post_id: 1,
 
+        forum_sudo: 33,
+
         category_title_constraint: InputValidationLengthConstraint {
             min: 10,
             max_min_diff: 140,
@@ -547,6 +470,7 @@ pub type RuntimePost = Post<
 >;
 pub type RuntimeBlockchainTimestamp =
     BlockAndTime<<Runtime as system::Trait>::BlockNumber, <Runtime as timestamp::Trait>::Moment>;
+
 pub type RuntimeThreadId = <Runtime as Trait>::ThreadId;
 pub type RuntimePostId = <Runtime as Trait>::PostId;
 
@@ -557,6 +481,7 @@ pub fn genesis_config(
     next_thread_id: u64,
     post_by_id: &RuntimeMap<RuntimePostId, RuntimePost>,
     next_post_id: u64,
+    forum_sudo: <Runtime as system::Trait>::AccountId,
     category_title_constraint: &InputValidationLengthConstraint,
     category_description_constraint: &InputValidationLengthConstraint,
     thread_title_constraint: &InputValidationLengthConstraint,
@@ -571,6 +496,7 @@ pub fn genesis_config(
         next_thread_id,
         post_by_id: post_by_id.clone(),
         next_post_id,
+        forum_sudo,
         category_title_constraint: category_title_constraint.clone(),
         category_description_constraint: category_description_constraint.clone(),
         thread_title_constraint: thread_title_constraint.clone(),

+ 103 - 46
runtime-modules/forum/src/tests.rs

@@ -9,6 +9,64 @@ use srml_support::{assert_err, assert_ok};
 * NB!: No test checks for event emission!!!!
 */
 
+/*
+ * set_forum_sudo
+ * ==============================================================================
+ *
+ * Missing cases
+ *
+ * set_forum_bad_origin
+ *
+ */
+
+#[test]
+fn set_forum_sudo_unset() {
+    let config = default_genesis_config();
+
+    build_test_externalities(config).execute_with(|| {
+        // Ensure that forum sudo is default
+        assert_eq!(TestForumModule::forum_sudo(), Some(33));
+
+        // Unset forum sudo
+        assert_ok!(TestForumModule::set_forum_sudo(
+            mock_origin(OriginType::Root),
+            None
+        ));
+
+        // Sudo no longer set
+        assert!(TestForumModule::forum_sudo().is_none());
+
+        // event emitted?!
+    });
+}
+
+#[test]
+fn set_forum_sudo_update() {
+    let config = default_genesis_config();
+
+    build_test_externalities(config).execute_with(|| {
+        // Ensure that forum sudo is default
+        assert_eq!(
+            TestForumModule::forum_sudo(),
+            Some(default_genesis_config().forum_sudo)
+        );
+
+        let new_forum_sudo_account_id = 780;
+
+        // Unset forum sudo
+        assert_ok!(TestForumModule::set_forum_sudo(
+            mock_origin(OriginType::Root),
+            Some(new_forum_sudo_account_id)
+        ));
+
+        // Sudo no longer set
+        assert_eq!(
+            TestForumModule::forum_sudo(),
+            Some(new_forum_sudo_account_id)
+        );
+    });
+}
+
 /*
  * create_category
  * ==============================================================================
@@ -22,7 +80,7 @@ use srml_support::{assert_err, assert_ok};
 #[test]
 fn create_root_category_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         assert_create_category(origin, None, Ok(()));
@@ -32,7 +90,7 @@ fn create_root_category_successfully() {
 #[test]
 fn create_subcategory_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let root_category_id = create_root_category(origin.clone());
@@ -43,7 +101,7 @@ fn create_subcategory_successfully() {
 #[test]
 fn create_category_title_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.category_title_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -61,7 +119,7 @@ fn create_category_title_too_short() {
 #[test]
 fn create_category_title_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.category_title_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -79,7 +137,7 @@ fn create_category_title_too_long() {
 #[test]
 fn create_category_description_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.category_description_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -97,7 +155,7 @@ fn create_category_description_too_short() {
 #[test]
 fn create_category_description_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.category_description_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -131,7 +189,7 @@ fn update_category_undelete_and_unarchive() {
      * leaf category is deleted, and then try to undelete.
      */
 
-    let forum_sudo = FORUM_SUDO_ID;
+    let forum_sudo = 32;
 
     let created_at = RuntimeBlockchainTimestamp { block: 0, time: 0 };
 
@@ -190,6 +248,7 @@ fn update_category_undelete_and_unarchive() {
         1,                           // next_thread_id
         &vec![],                     // post_by_id
         1,                           // next_post_id
+        forum_sudo,
         &sloppy_constraint,
         &sloppy_constraint,
         &sloppy_constraint,
@@ -224,7 +283,7 @@ fn update_category_undelete_and_unarchive() {
 #[test]
 fn create_thread_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(origin);
@@ -244,7 +303,7 @@ fn create_thread_successfully() {
 #[test]
 fn create_thread_title_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.thread_title_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -265,7 +324,7 @@ fn create_thread_title_too_short() {
 #[test]
 fn create_thread_title_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.thread_title_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -286,7 +345,7 @@ fn create_thread_title_too_long() {
 #[test]
 fn create_thread_text_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.post_text_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -307,7 +366,7 @@ fn create_thread_text_too_short() {
 #[test]
 fn create_thread_text_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.post_text_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -328,7 +387,7 @@ fn create_thread_text_too_long() {
 #[test]
 fn create_post_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, _, _) = create_root_category_and_thread_and_post(origin);
@@ -338,7 +397,7 @@ fn create_post_successfully() {
 #[test]
 fn create_post_text_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.post_text_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -357,7 +416,7 @@ fn create_post_text_too_short() {
 #[test]
 fn create_post_text_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.post_text_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -379,7 +438,7 @@ fn create_post_text_too_long() {
 #[test]
 fn moderate_thread_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, thread_id) = create_root_category_and_thread(origin.clone());
@@ -390,7 +449,7 @@ fn moderate_thread_successfully() {
 #[test]
 fn cannot_moderate_already_moderated_thread() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, thread_id) = create_root_category_and_thread(origin.clone());
@@ -408,7 +467,7 @@ fn cannot_moderate_already_moderated_thread() {
 #[test]
 fn moderate_thread_rationale_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.thread_moderation_rationale_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -424,7 +483,7 @@ fn moderate_thread_rationale_too_short() {
 #[test]
 fn moderate_thread_rationale_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.thread_moderation_rationale_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -440,7 +499,7 @@ fn moderate_thread_rationale_too_long() {
 #[test]
 fn moderate_post_successfully() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, _, post_id) = create_root_category_and_thread_and_post(origin.clone());
@@ -451,7 +510,7 @@ fn moderate_post_successfully() {
 #[test]
 fn moderate_post_rationale_too_short() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let min_len = config.post_moderation_rationale_constraint.min as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -467,7 +526,7 @@ fn moderate_post_rationale_too_short() {
 #[test]
 fn moderate_post_rationale_too_long() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
     let max_len = config.post_moderation_rationale_constraint.max() as usize;
 
     build_test_externalities(config).execute_with(|| {
@@ -483,7 +542,7 @@ fn moderate_post_rationale_too_long() {
 #[test]
 fn cannot_moderate_already_moderated_post() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, _, post_id) = create_root_category_and_thread_and_post(origin.clone());
@@ -517,7 +576,7 @@ fn not_forum_sudo_cannot_create_root_category() {
 #[test]
 fn not_forum_sudo_cannot_create_subcategory() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let root_category_id = create_root_category(origin);
@@ -552,7 +611,7 @@ fn not_forum_sudo_cannot_undelete_category() {
 #[test]
 fn not_forum_sudo_cannot_moderate_thread() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, thread_id) = create_root_category_and_thread(origin.clone());
@@ -566,7 +625,7 @@ fn not_forum_sudo_cannot_moderate_thread() {
 #[test]
 fn not_forum_sudo_cannot_moderate_post() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, _, post_id) = create_root_category_and_thread_and_post(origin.clone());
@@ -583,7 +642,7 @@ fn not_forum_sudo_cannot_moderate_post() {
 #[test]
 fn not_member_cannot_create_thread() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         CreateThreadFixture {
@@ -600,7 +659,7 @@ fn not_member_cannot_create_thread() {
 #[test]
 fn not_member_cannot_create_post() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, thread_id) = create_root_category_and_thread(origin);
@@ -617,7 +676,7 @@ fn not_member_cannot_create_post() {
 #[test]
 fn not_member_cannot_edit_post() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, _, post_id) = create_root_category_and_thread_and_post(origin);
@@ -638,7 +697,7 @@ fn not_member_cannot_edit_post() {
 #[test]
 fn cannot_create_subcategory_with_invalid_parent_category_id() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         assert_create_category(
@@ -683,10 +742,9 @@ fn cannot_create_post_with_invalid_thread_id() {
 #[test]
 fn cannot_moderate_thread_with_invalid_id() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
-        set_working_group_forum_lead();
         assert_err!(
             moderate_thread(origin, INVLAID_THREAD_ID, good_rationale()),
             ERROR_THREAD_DOES_NOT_EXIST
@@ -697,10 +755,9 @@ fn cannot_moderate_thread_with_invalid_id() {
 #[test]
 fn cannot_moderate_post_with_invalid_id() {
     let config = default_genesis_config();
-    let origin = OriginType::Signed(FORUM_SUDO_ID);
+    let origin = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
-        mock::set_working_group_forum_lead();
         assert_err!(
             moderate_post(origin, INVLAID_POST_ID, good_rationale()),
             ERROR_POST_DOES_NOT_EXIST
@@ -714,7 +771,7 @@ fn cannot_moderate_post_with_invalid_id() {
 #[test]
 fn archive_then_unarchive_category_successfully() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -729,7 +786,7 @@ fn archive_then_unarchive_category_successfully() {
 #[test]
 fn delete_then_undelete_category_successfully() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -745,7 +802,7 @@ fn delete_then_undelete_category_successfully() {
 // #[test]
 // fn cannot_unarchive_not_archived_category() {
 //     let config = default_genesis_config();
-//     let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+//     let forum_sudo = OriginType::Signed(config.forum_sudo);
 
 //     build_test_externalities(config).execute_with(|| {
 //         let category_id = create_root_category(forum_sudo.clone());
@@ -766,7 +823,7 @@ fn delete_then_undelete_category_successfully() {
 // #[test]
 // fn cannot_undelete_not_deleted_category() {
 //     let config = default_genesis_config();
-//     let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+//     let forum_sudo = OriginType::Signed(config.forum_sudo);
 
 //     build_test_externalities(config).execute_with(|| {
 //         let category_id = create_root_category(forum_sudo.clone());
@@ -786,7 +843,7 @@ fn delete_then_undelete_category_successfully() {
 #[test]
 fn cannot_create_subcategory_in_archived_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -802,7 +859,7 @@ fn cannot_create_subcategory_in_archived_category() {
 #[test]
 fn cannot_create_subcategory_in_deleted_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -818,7 +875,7 @@ fn cannot_create_subcategory_in_deleted_category() {
 #[test]
 fn cannot_create_thread_in_archived_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -834,7 +891,7 @@ fn cannot_create_thread_in_archived_category() {
 #[test]
 fn cannot_create_thread_in_deleted_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -850,7 +907,7 @@ fn cannot_create_thread_in_deleted_category() {
 #[test]
 fn cannot_create_post_in_thread_of_archived_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -868,7 +925,7 @@ fn cannot_create_post_in_thread_of_archived_category() {
 #[test]
 fn cannot_create_post_in_thread_of_deleted_category() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let category_id = create_root_category(forum_sudo.clone());
@@ -886,7 +943,7 @@ fn cannot_create_post_in_thread_of_deleted_category() {
 #[test]
 fn cannot_create_post_in_moderated_thread() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (_, _, thread_id) = create_root_category_and_thread(forum_sudo.clone());
@@ -906,7 +963,7 @@ fn cannot_create_post_in_moderated_thread() {
 #[test]
 fn cannot_edit_post_in_moderated_thread() {
     let config = default_genesis_config();
-    let forum_sudo = OriginType::Signed(FORUM_SUDO_ID);
+    let forum_sudo = OriginType::Signed(config.forum_sudo);
 
     build_test_externalities(config).execute_with(|| {
         let (member_origin, _, thread_id, post_id) =

+ 3 - 23
runtime-modules/working-group/src/lib.rs

@@ -52,10 +52,10 @@ use rstd::collections::btree_map::BTreeMap;
 use rstd::collections::btree_set::BTreeSet;
 use rstd::prelude::*;
 use rstd::vec::Vec;
-use sr_primitives::traits::{EnsureOrigin, One, Zero};
+use sr_primitives::traits::{One, Zero};
 use srml_support::traits::{Currency, ExistenceRequirement, WithdrawReasons};
 use srml_support::{decl_event, decl_module, decl_storage, ensure};
-use system::{ensure_root, ensure_signed, RawOrigin};
+use system::{ensure_root, ensure_signed};
 
 use crate::types::WorkerExitInitiationOrigin;
 use common::constraints::InputValidationLengthConstraint;
@@ -336,9 +336,7 @@ decl_module! {
 
             let lead = Self::ensure_lead_is_set()?;
 
-            //
             // == MUTATION SAFE ==
-            //
 
             // Update current lead
             <CurrentLead<T, I>>::kill();
@@ -941,24 +939,6 @@ decl_module! {
     }
 }
 
-impl<Origin, T, I> EnsureOrigin<Origin> for Module<T, I>
-where
-    Origin: Into<Result<RawOrigin<T::AccountId>, Origin>> + From<RawOrigin<T::AccountId>>,
-    T: Trait<I>,
-    I: Instance,
-{
-    type Success = ();
-
-    fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
-        o.into().and_then(|o| match o {
-            RawOrigin::Signed(account_id) => {
-                Self::ensure_is_lead_account(account_id).map_err(|_| RawOrigin::None.into())
-            }
-            _ => Err(RawOrigin::None.into()),
-        })
-    }
-}
-
 impl<T: Trait<I>, I: Instance> Module<T, I> {
     /// Checks that provided lead account id belongs to the current working group leader
     pub fn ensure_is_lead_account(lead_account_id: T::AccountId) -> Result<(), Error> {
@@ -1190,7 +1170,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
 
         // Unstake if stake profile exists
         if let Some(ref stake_profile) = worker.role_stake_profile {
-            // Determine unstaknig period based on who initiated deactivation
+            // Determine unstaking period based on who initiated deactivation
             let unstaking_period = match exit_initiation_origin {
                 WorkerExitInitiationOrigin::Lead => stake_profile.termination_unstaking_period,
                 WorkerExitInitiationOrigin::Worker => stake_profile.exit_unstaking_period,

+ 1 - 7
runtime/src/lib.rs

@@ -746,7 +746,6 @@ impl forum::ForumUserRegistry<AccountId> for ShimMembershipRegistry {
 impl forum::Trait for Runtime {
     type Event = Event;
     type MembershipRegistry = ShimMembershipRegistry;
-    type EnsureForumLeader = working_group::Module<Runtime, working_group::Instance1>;
     type ThreadId = ThreadId;
     type PostId = PostId;
 }
@@ -755,11 +754,6 @@ impl migration::Trait for Runtime {
     type Event = Event;
 }
 
-// Forum working group
-impl working_group::Trait<working_group::Instance1> for Runtime {
-    type Event = Event;
-}
-
 // Storage working group
 impl working_group::Trait<working_group::Instance2> for Runtime {
     type Event = Event;
@@ -885,7 +879,7 @@ construct_runtime!(
         ProposalsDiscussion: proposals_discussion::{Module, Call, Storage, Event<T>},
         ProposalsCodex: proposals_codex::{Module, Call, Storage, Error, Config<T>},
         // --- Working groups
-        ForumWorkingGroup: working_group::<Instance1>::{Module, Call, Storage, Event<T>},
+        // reserved for the future use: ForumWorkingGroup: working_group::<Instance1>::{Module, Call, Storage, Event<T>},
         StorageWorkingGroup: working_group::<Instance2>::{Module, Call, Storage, Event<T>},
     }
 );