diff --git a/prdoc/pr_2883.prdoc b/prdoc/pr_2883.prdoc new file mode 100644 index 000000000000..e2817d16a03f --- /dev/null +++ b/prdoc/pr_2883.prdoc @@ -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" diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index 2042f68e7149..ee16ae07ce6e 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -382,7 +382,11 @@ pub mod pallet { ensure!(at_rank > 0, Error::::InvalidRank); let rank = T::Members::rank_of(&who).ok_or(Error::::Unranked)?; ensure!(rank == at_rank, Error::::UnexpectedRank); - let mut member = Member::::get(&who).ok_or(Error::::NotTracked)?; + let mut member = if let Some(m) = Member::::get(&who) { + m + } else { + Self::import_member(who.clone(), rank) + }; member.last_proof = frame_system::Pallet::::block_number(); Member::::insert(&who, &member); @@ -518,13 +522,7 @@ pub mod pallet { let who = ensure_signed(origin)?; ensure!(!Member::::contains_key(&who), Error::::AlreadyInducted); let rank = T::Members::rank_of(&who).ok_or(Error::::Unranked)?; - - let now = frame_system::Pallet::::block_number(); - Member::::insert( - &who, - MemberStatus { is_active: true, last_promotion: 0u32.into(), last_proof: now }, - ); - Self::deposit_event(Event::::Imported { who, rank }); + let _ = Self::import_member(who, rank); Ok(Pays::No.into()) } @@ -548,6 +546,18 @@ pub mod pallet { Self::deposit_event(e); } } + + fn import_member(who: T::AccountId, rank: RankOf) -> MemberStatusOf { + let now = frame_system::Pallet::::block_number(); + let status = MemberStatus { + is_active: true, + last_promotion: BlockNumberFor::::zero(), + last_proof: now, + }; + Member::::insert(&who, status.clone()); + Self::deposit_event(Event::::Imported { who, rank }); + status + } } impl, I: 'static> GetSalary, T::AccountId, T::Balance> for Pallet { diff --git a/substrate/frame/core-fellowship/src/tests.rs b/substrate/frame/core-fellowship/src/tests.rs index c9098f2171f4..6d9cebbf9219 100644 --- a/substrate/frame/core-fellowship/src/tests.rs +++ b/substrate/frame/core-fellowship/src/tests.rs @@ -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)); + }); +}