Skip to content

Commit 450e245

Browse files
committed
Update permission assignment flow for admin role
1 parent 7a17664 commit 450e245

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ impl<T: Config> Pallet<T> {
5151
admin: T::AccountId,
5252
name: FieldName,
5353
) -> DispatchResult{
54-
let pallet_id = Self::pallet_id();
55-
let global_scope = <GlobalScope<T>>::try_get().map_err(|_| Error::<T>::GlobalScopeNotSet)?;
56-
57-
T::Rbac::assign_role_to_user(
58-
admin.clone(),
59-
pallet_id.clone(),
60-
&global_scope,
61-
ProxyRole::Administrator.id())?;
62-
63-
// create a administrator user account
54+
// create a administrator user account & register it in the rbac pallet
6455
Self::sudo_register_admin(admin.clone(), name)?;
6556

6657
Self::deposit_event(Event::AdministratorAssigned(admin));
@@ -70,16 +61,7 @@ impl<T: Config> Pallet<T> {
7061
pub fn do_sudo_remove_administrator(
7162
admin: T::AccountId,
7263
) -> DispatchResult{
73-
let pallet_id = Self::pallet_id();
74-
let global_scope = <GlobalScope<T>>::try_get().map_err(|_| Error::<T>::GlobalScopeNotSet)?;
75-
76-
T::Rbac::remove_role_from_user(
77-
admin.clone(),
78-
pallet_id.clone(),
79-
&global_scope,
80-
ProxyRole::Administrator.id())?;
81-
82-
// remove administrator user account
64+
// remove administrator user account & remove it from the rbac pallet
8365
Self::sudo_delete_admin(admin.clone())?;
8466

8567
Self::deposit_event(Event::AdministratorRemoved(admin));
@@ -1625,8 +1607,7 @@ impl<T: Config> Pallet<T> {
16251607
}
16261608
}
16271609

1628-
//TODO: remove macro when used
1629-
#[allow(dead_code)]
1610+
16301611
fn is_authorized( authority: T::AccountId, project_id: &[u8;32], permission: ProxyPermission ) -> DispatchResult{
16311612
T::Rbac::is_authorized(
16321613
authority,
@@ -1666,6 +1647,15 @@ impl<T: Config> Pallet<T> {
16661647

16671648
//Insert user data
16681649
<UsersInfo<T>>::insert(admin.clone(), user_data);
1650+
1651+
// Add administrator to rbac pallet
1652+
T::Rbac::assign_role_to_user(
1653+
admin.clone(),
1654+
Self::pallet_id(),
1655+
&Self::get_global_scope(),
1656+
ProxyRole::Administrator.id()
1657+
)?;
1658+
16691659
Ok(())
16701660
}
16711661

@@ -1676,6 +1666,14 @@ impl<T: Config> Pallet<T> {
16761666
//Remove user from UsersInfo storage map
16771667
<UsersInfo<T>>::remove(admin.clone());
16781668

1669+
// Remove administrator to rbac pallet
1670+
T::Rbac::remove_role_from_user(
1671+
admin.clone(),
1672+
Self::pallet_id(),
1673+
&Self::get_global_scope(),
1674+
ProxyRole::Administrator.id()
1675+
)?;
1676+
16791677
Ok(())
16801678
}
16811679

0 commit comments

Comments
 (0)