Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions: Add idempotent add function #1204

Open
NunoAlexandre opened this issue Feb 14, 2023 · 1 comment
Open

Permissions: Add idempotent add function #1204

NunoAlexandre opened this issue Feb 14, 2023 · 1 comment

Comments

@NunoAlexandre
Copy link
Contributor

NunoAlexandre commented Feb 14, 2023

An idea for this. Since both parameters used are the same on has() and add(), and seems it can be a recurrent pattern, why not add a new method add_idempotent() (or similar) to the trait Permissions that does exactly this? The method could have a default implementation using only has() and add() so there is no implementation on the permission pallet.

Originally posted by @lemunozm in #1160 (comment)

@NunoAlexandre NunoAlexandre mentioned this issue Feb 14, 2023
5 tasks
@lemunozm
Copy link
Contributor

I would also add an ensure() method, with the following implementation:

fn ensure(scope: Self::Scope, who: AccountId, role: Self::Role) -> DispatchResult {
    T::Permissions::has(pool_id, who, role)
        .then_some(())
        .ok_or(BadOrigin.into())
}

that is used in other places.

As the idempotent one, it only makes use of the Permissions trait, so it does not need any implementation from the pallet-permissions side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants