Browse Source

Integrating temporary forum branch snapshot with runtime

f 5 years ago
parent
commit
b4da3c5861
3 changed files with 50 additions and 0 deletions
  1. 6 0
      Cargo.toml
  2. 33 0
      src/lib.rs
  3. 11 0
      src/membership/members.rs

+ 6 - 0
Cargo.toml

@@ -37,6 +37,7 @@ std = [
     'consensus-authorities/std',
     'grandpa/std',
     'finality-tracker/std',
+    'forum/std'
 ]
 [dependencies.aura]
 default_features = false
@@ -188,3 +189,8 @@ git = 'https://github.com/joystream/substrate.git'
 package = 'srml-finality-tracker'
 rev = '6dfc3e8b057bb00322136251a0f10305fbb1ad8f'
 
+[dependencies.forum]
+default_features = false
+git = 'https://github.com/bedeho/substrate-forum-module'
+package = 'substrate-forum-module'
+rev = '9c0cf6544f8f6f9b7ae185007ccf3d8623d5f62a'

+ 33 - 0
src/lib.rs

@@ -23,6 +23,8 @@ mod membership;
 mod memo;
 mod traits;
 use membership::members;
+use forum;
+
 mod migration;
 mod roles;
 use client::{
@@ -292,6 +294,36 @@ impl members::Trait for Runtime {
     type Roles = Actors;
 }
 
+/*
+ * Forum module integration
+ */
+
+/// Shim registry which will proxy ForumUserRegistry behaviour to the members module
+pub struct ShimMembershipRegistry {}
+
+impl forum::ForumUserRegistry<AccountId> for ShimMembershipRegistry {
+
+    fn get_forum_user(id: &AccountId) -> Option<forum::ForumUser<AccountId>> {
+
+        if let Some(profile) = members::Module::<Runtime>::get_profile(id) {
+
+            // Now convert member profile to a forum user
+            Some(forum::ForumUser{
+                id: id.clone()
+            })
+
+        } else {
+            None
+        }
+    }
+}
+
+impl forum::Trait for Runtime {
+    
+    type Event = Event;
+    type MembershipRegistry = ShimMembershipRegistry;
+}
+
 impl migration::Trait for Runtime {
     type Event = Event;
 }
@@ -333,6 +365,7 @@ construct_runtime!(
 		Council: council::{Module, Call, Storage, Event<T>, Config<T>},
 		Memo: memo::{Module, Call, Storage, Event<T>},
 		Members: members::{Module, Call, Storage, Event<T>, Config<T>},
+        Forum: forum::{Module, Call, Storage, Event<T>, Config<T>},
 		Migration: migration::{Module, Call, Storage, Event<T>},
 		Actors: actors::{Module, Call, Storage, Event<T>, Config<T>},
 		DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},

+ 11 - 0
src/membership/members.rs

@@ -331,6 +331,17 @@ decl_module! {
 }
 
 impl<T: Trait> Module<T> {
+
+    pub fn get_profile(id: &T::AccountId) -> Option<Profile<T>> {
+
+        if let Some(member_id) = Self::ensure_is_member(id).ok() {
+            // This option _must_ be set
+            Self::member_profile(&member_id)
+        } else {
+            None
+        }
+    }
+
     fn ensure_not_member(who: &T::AccountId) -> dispatch::Result {
         ensure!(
             !<MemberIdByAccountId<T>>::exists(who),