mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 13:21:10 +00:00
pallet-core-fellowship: import an unimported member on approve (#2883)
To align with the documentation of the approve call, we import an unimported member on approval. No changes have been made to the benchmarks as they already cover the worst-case scenario.
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
title: "pallet-core-fellowship: import an unimported on approve"
|
||||||
|
|
||||||
|
doc:
|
||||||
|
- audience: Runtime User
|
||||||
|
description: |
|
||||||
|
To align with the documentation of the approve call, we import an untracked member on approval.
|
||||||
|
|
||||||
|
crates:
|
||||||
|
- name: "pallet-core-fellowship"
|
||||||
@@ -382,7 +382,11 @@ pub mod pallet {
|
|||||||
ensure!(at_rank > 0, Error::<T, I>::InvalidRank);
|
ensure!(at_rank > 0, Error::<T, I>::InvalidRank);
|
||||||
let rank = T::Members::rank_of(&who).ok_or(Error::<T, I>::Unranked)?;
|
let rank = T::Members::rank_of(&who).ok_or(Error::<T, I>::Unranked)?;
|
||||||
ensure!(rank == at_rank, Error::<T, I>::UnexpectedRank);
|
ensure!(rank == at_rank, Error::<T, I>::UnexpectedRank);
|
||||||
let mut member = Member::<T, I>::get(&who).ok_or(Error::<T, I>::NotTracked)?;
|
let mut member = if let Some(m) = Member::<T, I>::get(&who) {
|
||||||
|
m
|
||||||
|
} else {
|
||||||
|
Self::import_member(who.clone(), rank)
|
||||||
|
};
|
||||||
|
|
||||||
member.last_proof = frame_system::Pallet::<T>::block_number();
|
member.last_proof = frame_system::Pallet::<T>::block_number();
|
||||||
Member::<T, I>::insert(&who, &member);
|
Member::<T, I>::insert(&who, &member);
|
||||||
@@ -518,13 +522,7 @@ pub mod pallet {
|
|||||||
let who = ensure_signed(origin)?;
|
let who = ensure_signed(origin)?;
|
||||||
ensure!(!Member::<T, I>::contains_key(&who), Error::<T, I>::AlreadyInducted);
|
ensure!(!Member::<T, I>::contains_key(&who), Error::<T, I>::AlreadyInducted);
|
||||||
let rank = T::Members::rank_of(&who).ok_or(Error::<T, I>::Unranked)?;
|
let rank = T::Members::rank_of(&who).ok_or(Error::<T, I>::Unranked)?;
|
||||||
|
let _ = Self::import_member(who, rank);
|
||||||
let now = frame_system::Pallet::<T>::block_number();
|
|
||||||
Member::<T, I>::insert(
|
|
||||||
&who,
|
|
||||||
MemberStatus { is_active: true, last_promotion: 0u32.into(), last_proof: now },
|
|
||||||
);
|
|
||||||
Self::deposit_event(Event::<T, I>::Imported { who, rank });
|
|
||||||
|
|
||||||
Ok(Pays::No.into())
|
Ok(Pays::No.into())
|
||||||
}
|
}
|
||||||
@@ -548,6 +546,18 @@ pub mod pallet {
|
|||||||
Self::deposit_event(e);
|
Self::deposit_event(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import_member(who: T::AccountId, rank: RankOf<T, I>) -> MemberStatusOf<T> {
|
||||||
|
let now = frame_system::Pallet::<T>::block_number();
|
||||||
|
let status = MemberStatus {
|
||||||
|
is_active: true,
|
||||||
|
last_promotion: BlockNumberFor::<T>::zero(),
|
||||||
|
last_proof: now,
|
||||||
|
};
|
||||||
|
Member::<T, I>::insert(&who, status.clone());
|
||||||
|
Self::deposit_event(Event::<T, I>::Imported { who, rank });
|
||||||
|
status
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Config<I>, I: 'static> GetSalary<RankOf<T, I>, T::AccountId, T::Balance> for Pallet<T, I> {
|
impl<T: Config<I>, I: 'static> GetSalary<RankOf<T, I>, T::AccountId, T::Balance> for Pallet<T, I> {
|
||||||
|
|||||||
@@ -378,3 +378,11 @@ fn active_changing_get_salary_works() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn approve_imports_not_tracked_member() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
set_rank(10, 5);
|
||||||
|
assert_ok!(CoreFellowship::approve(signed(5), 10, 5));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user