Skip to content

Commit 35e5ba0

Browse files
committed
🐛 fix(functions.rs): add authorization check in do_cancel_offer function to ensure only admin or offer creator can cancel the offer
🐛 fix(lib.rs): remove redundant authorization check in cancel_offer function
1 parent 238a620 commit 35e5ba0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pallets/afloat/src/functions.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,14 @@ impl<T: Config> Pallet<T> {
859859
Ok(())
860860
}
861861

862-
pub fn do_cancel_offer(order_id: StorageId) -> DispatchResult {
862+
pub fn do_cancel_offer(who: T::AccountId, order_id: StorageId) -> DispatchResult {
863863
// ensure offer exists
864864
ensure!(<AfloatOffers<T>>::contains_key(order_id), Error::<T>::OfferNotFound);
865865
//get offer details
866866
let offer = <AfloatOffers<T>>::get(order_id).unwrap();
867+
let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?;
868+
ensure!(is_admin_or_owner || offer.creator_id == who, Error::<T>::Unauthorized);
869+
867870
match offer.status {
868871
OfferStatus::CREATED => {
869872
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult {

pallets/afloat/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,7 @@ pub mod pallet {
433433
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))]
434434
pub fn cancel_offer(origin: OriginFor<T>, order_id: StorageId) -> DispatchResult {
435435
let who = ensure_signed(origin.clone())?;
436-
let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?;
437-
ensure!(is_admin_or_owner, Error::<T>::Unauthorized);
438-
Self::do_cancel_offer(order_id)
436+
Self::do_cancel_offer(who, order_id)
439437
}
440438
}
441439
}

0 commit comments

Comments
 (0)