Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
chore(perms): permissions store adapted to upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Jun 29, 2023
1 parent 2f2eb74 commit b123746
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bucket/ddc_bucket/perm/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@ type PermKey = Vec<u8>;

#[derive(SpreadAllocate, SpreadLayout, Default)]
#[cfg_attr(feature = "std", derive(ink_storage::traits::StorageLayout, Debug))]
pub struct PermStore(pub Mapping<PermKey, bool>);
// TODO: Switch to Mapping (must upgrade ink first).
pub struct PermStore {
pub perms: Mapping<PermKey, bool>
}


impl PermStore {
pub fn grant_permission(&mut self, account_id: AccountId, permission: &Permission) {
let key = (account_id, permission).encode();
self.0.insert(key, &true);
self.perms.insert(key, &true);
}

pub fn revoke_permission(&mut self, account_id: AccountId, permission: &Permission) {
let key = (account_id, permission).encode();
self.0.remove(&key);
self.perms.remove(&key);
}

pub fn has_permission(&self, account_id: AccountId, permission: Permission) -> bool {
let key = (account_id, permission).encode();
if self.0.contains(&key) {
if self.perms.contains(&key) {
return true;
}

let admin_key = (account_id, Permission::SuperAdmin).encode();
self.0.contains(&admin_key)
self.perms.contains(&admin_key)
}
}

0 comments on commit b123746

Please sign in to comment.