Add functions to manage Acl (super-)admins#8
Conversation
Add functions acl_{is, add}_admin*
Implement {revoke, renounce} admin
Add tests for acl_{revoke, renounce}_admin*
Add acl_is_super_admin
Test acl_{add, revoke}_super_admin_unchecked
mfornet
left a comment
There was a problem hiding this comment.
Looks good in general. I left a comment about removing unchecked methods from the public contract interface.
|
FYI: project doesn't compile for me when doing cargo test |
Hm on my machine it compiles and all tests are passing. I'm having near-sdk version 4.0.0 in If it's not related to the version of near-sdk, could you please post more infos about the compilation error? |
|
I'm in the process of removing the Tests rely on calling
|
|
IMO, unchecked methods are an internal detail about our default implementation and not mandatory for every other implementation out there. It is conceivable that other implementations use different mechanisms internally. Arguably unchecked-like methods will be present one way or another, but we should try to keep the main interface as simple as possible.
This is a great example of what I try to convey.
We can keep this method behind a testing feature flag.
I like the new proposal, even we can take it further and have the method: fn acl_init_super_admin(accountId: AccountId);This method can only be called once and will add the account passed as an argument as super admin. In particular, it is mandatory (or strongly recommended) to developers that this is called during initialization. |
Check compilation-error-logs and Cargo.lock. |
| /// Exposing internal methods to facilitate integration testing. | ||
| #[near_bindgen] | ||
| impl StatusMessage { | ||
| #[private] | ||
| pub fn acl_add_super_admin_unchecked(&mut self, account_id: AccountId) -> bool { | ||
| self.__acl.add_super_admin_unchecked(&account_id) | ||
| } | ||
|
|
||
| #[private] | ||
| pub fn acl_revoke_super_admin_unchecked(&mut self, account_id: AccountId) -> bool { | ||
| self.__acl.revoke_super_admin_unchecked(&account_id) | ||
| } | ||
|
|
||
| #[private] | ||
| pub fn acl_add_admin_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { | ||
| self.__acl.add_admin_unchecked(role, &account_id) | ||
| } | ||
|
|
||
| #[private] | ||
| pub fn acl_revoke_admin_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { | ||
| self.__acl.revoke_admin_unchecked(role, &account_id) | ||
| } | ||
|
|
||
| #[private] | ||
| pub fn acl_grant_role_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { | ||
| self.__acl.grant_role_unchecked(role, &account_id) | ||
| } | ||
| } |
There was a problem hiding this comment.
Let's add this behind [integration-test] feature flag, similar as it is used in the engine today.
There was a problem hiding this comment.
The contract containing these methods is compiled and deployed via workspaces::compile_project which has only one parameter: project_path: &str. AFAIK this prevents us from working with features in this contract, since we'd have to enable required features by default (see below).
The following works, though if the integration-test feature needs to be enabled by default, I'm not sure if it makes sense to have it?
# near-plugins/tests/contracts/access_controllable/Cargo.toml
[features]
default = ["integration-test"]
integration-test = []
It might be worth a feature request for compile_project to have an additional parameter &[&str] that specifies the features to be enabled.
Do we want it to be callable strictly once? I think that would require a new field like Alternatively we might relax it a bit and say |
|
Regarding the compilation errors: After removing |
Running |
mfornet
left a comment
There was a problem hiding this comment.
LGTM. I'll revisit later about having init_super_admin as a public method, hidden under a private modifier, I think this is no needed and can be internal. But let's move forward with this PR for now.
This PR builds on top of #5 and adds Acl functions related to (super-)admin permissions. A super-admin may act as admin for every role, these tests provide an overview of super-admin permissions.
Overview
AccessControllable.#[access_controllable]adds implementations of these methods.near-plugins/tests/access_controllable.rsNotes on super-admin
Currently only
acl_init_super_adminis added to the public interface, i.e. only the contract itself may add a super-admin. Potential further additions could be:Next up
A follow-up PR to add some missing functions related to roles: