mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
[NFTs] Allow to set the role to None (#13591)
* Allow to unset the role * Chore * Array instead of vec --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -106,9 +106,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
ensure!(deadline >= now, Error::<T, I>::DeadlineExpired);
|
||||
|
||||
let collection_details =
|
||||
Collection::<T, I>::get(&collection).ok_or(Error::<T, I>::UnknownCollection)?;
|
||||
|
||||
ensure!(
|
||||
Self::has_role(&collection, &signer, CollectionRole::Issuer),
|
||||
Error::<T, I>::NoPermission
|
||||
@@ -123,27 +120,28 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
item_config,
|
||||
|_, _| Ok(()),
|
||||
)?;
|
||||
let origin = Self::find_account_by_role(&collection, CollectionRole::Admin)
|
||||
.unwrap_or(collection_details.owner.clone());
|
||||
for (key, value) in attributes {
|
||||
Self::do_set_attribute(
|
||||
origin.clone(),
|
||||
collection,
|
||||
Some(item),
|
||||
AttributeNamespace::CollectionOwner,
|
||||
Self::construct_attribute_key(key)?,
|
||||
Self::construct_attribute_value(value)?,
|
||||
mint_to.clone(),
|
||||
)?;
|
||||
}
|
||||
if !metadata.len().is_zero() {
|
||||
Self::do_set_item_metadata(
|
||||
Some(origin.clone()),
|
||||
collection,
|
||||
item,
|
||||
metadata,
|
||||
Some(mint_to.clone()),
|
||||
)?;
|
||||
let admin_account = Self::find_account_by_role(&collection, CollectionRole::Admin);
|
||||
if let Some(admin_account) = admin_account {
|
||||
for (key, value) in attributes {
|
||||
Self::do_set_attribute(
|
||||
admin_account.clone(),
|
||||
collection,
|
||||
Some(item),
|
||||
AttributeNamespace::CollectionOwner,
|
||||
Self::construct_attribute_key(key)?,
|
||||
Self::construct_attribute_value(value)?,
|
||||
mint_to.clone(),
|
||||
)?;
|
||||
}
|
||||
if !metadata.len().is_zero() {
|
||||
Self::do_set_item_metadata(
|
||||
Some(admin_account.clone()),
|
||||
collection,
|
||||
item,
|
||||
metadata,
|
||||
Some(mint_to.clone()),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -23,24 +23,46 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
pub(crate) fn do_set_team(
|
||||
maybe_check_owner: Option<T::AccountId>,
|
||||
collection: T::CollectionId,
|
||||
issuer: T::AccountId,
|
||||
admin: T::AccountId,
|
||||
freezer: T::AccountId,
|
||||
issuer: Option<T::AccountId>,
|
||||
admin: Option<T::AccountId>,
|
||||
freezer: Option<T::AccountId>,
|
||||
) -> DispatchResult {
|
||||
Collection::<T, I>::try_mutate(collection, |maybe_details| {
|
||||
let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
|
||||
let is_root = maybe_check_owner.is_none();
|
||||
if let Some(check_origin) = maybe_check_owner {
|
||||
ensure!(check_origin == details.owner, Error::<T, I>::NoPermission);
|
||||
}
|
||||
|
||||
// delete previous values
|
||||
Self::clear_roles(&collection)?;
|
||||
|
||||
let account_to_role = Self::group_roles_by_account(vec![
|
||||
let roles_map = [
|
||||
(issuer.clone(), CollectionRole::Issuer),
|
||||
(admin.clone(), CollectionRole::Admin),
|
||||
(freezer.clone(), CollectionRole::Freezer),
|
||||
]);
|
||||
];
|
||||
|
||||
// only root can change the role from `None` to `Some(account)`
|
||||
if !is_root {
|
||||
for (account, role) in roles_map.iter() {
|
||||
if account.is_some() {
|
||||
ensure!(
|
||||
Self::find_account_by_role(&collection, *role).is_some(),
|
||||
Error::<T, I>::NoPermission
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let roles = roles_map
|
||||
.into_iter()
|
||||
.filter_map(|(account, role)| account.map(|account| (account, role)))
|
||||
.collect();
|
||||
|
||||
let account_to_role = Self::group_roles_by_account(roles);
|
||||
|
||||
// delete the previous records
|
||||
Self::clear_roles(&collection)?;
|
||||
|
||||
// insert new records
|
||||
for (account, roles) in account_to_role {
|
||||
CollectionRoleOf::<T, I>::insert(&collection, &account, roles);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user