Browse Source

membership: added key_can_sign_for_role

Mokhtar Naamani 5 years ago
parent
commit
5e67f4df5c
2 changed files with 19 additions and 1 deletions
  1. 15 1
      src/membership/members.rs
  2. 4 0
      src/membership/role_types.rs

+ 15 - 1
src/membership/members.rs

@@ -504,7 +504,21 @@ impl<T: Trait> Module<T> {
         Ok(())
     }
 
-    // Checks if a member identified by their member id occupies a role at least once
+    /// Determines if the signing account is a controller account of a member that has the registered
+    /// actor_in_role.
+    pub fn key_can_sign_for_role(
+        signing_account: &T::AccountId,
+        actor_in_role: ActorInRole,
+    ) -> bool {
+        Self::member_ids_by_controller_account_id(signing_account)
+            .iter()
+            .any(|member_id| {
+                let profile = Self::member_profile(member_id).unwrap(); // must exist
+                profile.roles.has_registered_role(&actor_in_role)
+            })
+    }
+
+    /// Returns true if member identified by their member id occupies a Role at least once
     pub fn member_is_in_role(member_id: T::MemberId, role: Role) -> bool {
         Self::ensure_profile(member_id)
             .ok()

+ 4 - 0
src/membership/role_types.rs

@@ -52,4 +52,8 @@ impl ActorInRoleSet {
     pub fn unregister_role(&mut self, actor_in_role: &ActorInRole) -> bool {
         self.0.remove(actor_in_role)
     }
+
+    pub fn has_registered_role(&self, actor_in_role: &ActorInRole) -> bool {
+        self.0.contains(actor_in_role)
+    }
 }