Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
make kicking events clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski committed Apr 9, 2022
1 parent 814d520 commit f90df9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ pub mod pallet {
NotAlly,
/// Account is not a founder.
NotFounder,
/// This member is up for being kicked from the Alliance and cannot perform this operation.
UpForKicking,
/// Member is not up for consideration of being kicked.
NotKickingMember,
NotUpForKicking,
/// Account does not have voting rights.
NoVotingRights,
/// Account is already an elevated (fellow) member.
Expand All @@ -334,8 +336,6 @@ pub mod pallet {
TooManyBlacklist,
/// Length of website URL exceeds `MaxWebsiteUrlLength`.
TooLongWebsiteUrl,
/// This member is up for being kicked from the Alliance and cannot perform this operation.
MemberBeingKicked,
/// Balance is insufficient to be a candidate.
InsufficientCandidateFunds,
/// The account's identity does not have display field and website field.
Expand Down Expand Up @@ -491,8 +491,8 @@ pub mod pallet {
/// A set of members that are (potentially) being kicked out. They cannot retire until the
/// motion is settled.
#[pallet::storage]
#[pallet::getter(fn kicking_member)]
pub type KickingMembers<T: Config<I>, I: 'static = ()> =
#[pallet::getter(fn up_for_kicking)]
pub type UpForKicking<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, T::AccountId, bool, ValueQuery>;

/// The current blacklist of accounts. These accounts cannot submit candidacy.
Expand Down Expand Up @@ -532,7 +532,7 @@ pub mod pallet {

if let Some(Call::kick_member { who }) = proposal.is_sub_type() {
let strike = T::Lookup::lookup(who.clone())?;
<KickingMembers<T, I>>::insert(strike, true);
<UpForKicking<T, I>>::insert(strike, true);
}

T::ProposalProvider::propose_proposal(proposor, threshold, proposal, length_bound)?;
Expand Down Expand Up @@ -619,7 +619,7 @@ pub mod pallet {
if Pays::No == info.pays_fee {
if let Some(Call::kick_member { who }) = proposal.is_sub_type() {
let strike = T::Lookup::lookup(who.clone())?;
<KickingMembers<T, I>>::remove(strike);
<UpForKicking<T, I>>::remove(strike);
}
}
Ok(info.into())
Expand Down Expand Up @@ -845,7 +845,7 @@ pub mod pallet {
pub fn retire(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
// A member up for kicking cannot retire.
ensure!(!Self::is_being_kicked(&who), Error::<T, I>::MemberBeingKicked);
ensure!(!Self::is_up_for_kicking(&who), Error::<T, I>::UpForKicking);

let role = Self::member_role_of(&who).ok_or(Error::<T, I>::NotMember)?;
Self::remove_member(&who, role)?;
Expand All @@ -866,7 +866,7 @@ pub mod pallet {
) -> DispatchResult {
T::MembershipManager::ensure_origin(origin)?;
let member = T::Lookup::lookup(who)?;
ensure!(Self::is_being_kicked(&member), Error::<T, I>::NotKickingMember);
ensure!(Self::is_up_for_kicking(&member), Error::<T, I>::NotUpForKicking);

let role = Self::member_role_of(&member).ok_or(Error::<T, I>::NotMember)?;
Self::remove_member(&member, role)?;
Expand Down Expand Up @@ -1007,8 +1007,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

/// Check if an account's forced removal is up for consideration.
fn is_being_kicked(who: &T::AccountId) -> bool {
<KickingMembers<T, I>>::contains_key(&who)
fn is_up_for_kicking(who: &T::AccountId) -> bool {
<UpForKicking<T, I>>::contains_key(&who)
}

/// Add a user to the sorted alliance member set.
Expand Down
4 changes: 2 additions & 2 deletions frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ fn kick_member_works() {
new_test_ext().execute_with(|| {
assert_noop!(
Alliance::kick_member(Origin::signed(1), 2),
Error::<Test, ()>::NotKickingMember
Error::<Test, ()>::NotUpForKicking
);

let proposal = make_kick_member_proposal(2);
Expand All @@ -468,7 +468,7 @@ fn kick_member_works() {
Box::new(proposal.clone()),
proposal_len
));
assert_eq!(Alliance::kicking_member(2), true);
assert_eq!(Alliance::up_for_kicking(2), true);
assert_eq!(Alliance::members(MemberRole::Founder), vec![1, 2]);

assert_ok!(Alliance::kick_member(Origin::signed(1), 2));
Expand Down

0 comments on commit f90df9e

Please sign in to comment.