diff --git a/near-plugins-derive/src/access_controllable.rs b/near-plugins-derive/src/access_controllable.rs index 1175376..2088ebb 100644 --- a/near-plugins-derive/src/access_controllable.rs +++ b/near-plugins-derive/src/access_controllable.rs @@ -433,11 +433,6 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream self.#acl_field.is_super_admin(&account_id) } - #[private] - fn acl_init_super_admin(&mut self, account_id: ::near_sdk::AccountId) -> bool { - self.#acl_field.init_super_admin(&account_id) - } - fn acl_add_admin(&mut self, role: String, account_id: ::near_sdk::AccountId) -> Option { let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); self.#acl_field.add_admin(role, &account_id) @@ -458,32 +453,25 @@ pub fn access_controllable(attrs: TokenStream, item: TokenStream) -> TokenStream self.#acl_field.renounce_admin(role) } - #[private] - fn acl_revoke_admin_unchecked(&mut self, role: String, account_id: ::near_sdk::AccountId) -> bool { + fn acl_revoke_role(&mut self, role: String, account_id: ::near_sdk::AccountId) -> Option { let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); - self.#acl_field.revoke_admin_unchecked(role, &account_id) + self.#acl_field.revoke_role(role, &account_id) } - fn acl_grant_role(&mut self, role: String, account_id: ::near_sdk::AccountId) -> Option { + fn acl_renounce_role(&mut self, role: String) -> bool { let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); - self.#acl_field.grant_role(role, &account_id) + self.#acl_field.renounce_role(role) } - #[private] - fn acl_grant_role_unchecked(&mut self, role: String, account_id: ::near_sdk::AccountId) -> bool { + fn acl_grant_role(&mut self, role: String, account_id: ::near_sdk::AccountId) -> Option { let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); - self.#acl_field.grant_role_unchecked(role, &account_id) + self.#acl_field.grant_role(role, &account_id) } - fn acl_has_role(&self, role: String, account_id: ::near_sdk::AccountId) -> bool { - let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); - self.#acl_field.renounce_role(role) - } - #[private] - fn acl_revoke_role_unchecked(&mut self, role: String, account_id: ::near_sdk::AccountId) -> bool { + fn acl_has_role(&self, role: String, account_id: ::near_sdk::AccountId) -> bool { let role = <#role_type>::try_from(role.as_str()).expect(#ERR_PARSE_ROLE); - self.#acl_field.revoke_role_unchecked(role, &account_id) + self.#acl_field.has_role(role, &account_id) } fn acl_has_any_role(&self, roles: Vec, account_id: ::near_sdk::AccountId) -> bool { diff --git a/near-plugins/src/access_controllable.rs b/near-plugins/src/access_controllable.rs index 1be3099..efc358c 100644 --- a/near-plugins/src/access_controllable.rs +++ b/near-plugins/src/access_controllable.rs @@ -19,18 +19,6 @@ pub trait AccessControllable { /// Returns the storage prefix for collections related to access control. fn acl_storage_prefix() -> &'static [u8]; - /// Adds `account_id` as super-admin __without__ checking any permissions in - /// case there are no super-admins. This function can be used to add a - /// super-admin during contract initialization. Moreover, it may provide a - /// recovery mechanism if (mistakenly) all super-admins have been removed. - /// - /// The return value indicates whether `account_id` was added as - /// super-admin. - /// - /// It is `#[private]` in the implementation provided by this trait, i.e. - /// only the contract itself may call this method. - fn acl_init_super_admin(&mut self, account_id: AccountId) -> bool; - /// Returns whether `account_id` is a super-admin. fn acl_is_super_admin(&self, account_id: AccountId) -> bool; @@ -61,13 +49,6 @@ pub trait AccessControllable { /// whether the predecessor was an admin for `role`. fn acl_renounce_admin(&mut self, role: String) -> bool; - /// Revokes admin permissions from `account_id` __without__ checking any - /// permissions. Returns whether `account_id` was an admin for `role`. - /// - /// This method is `#[private]` in the implementation provided by this - /// crate. - fn acl_revoke_admin_unchecked(&mut self, role: String, account_id: AccountId) -> bool; - /// Grants `role` to `account_id` provided that the predecessor has /// sufficient permissions, i.e. is an admin as defined by [`acl_is_admin`]. /// @@ -76,13 +57,6 @@ pub trait AccessControllable { /// `None` is returned and internal state is not modified. fn acl_grant_role(&mut self, role: String, account_id: AccountId) -> Option; - /// Grants `role` to `account_id` __without__ checking any permissions. - /// Returns whether `role` was newly granted to `account_id`. - /// - /// This method is `#[private]` in the implementation provided by this - /// crate. - fn acl_grant_role_unchecked(&mut self, role: String, account_id: AccountId) -> bool; - /// Returns whether `account_id` has been granted `role`. fn acl_has_role(&self, role: String, account_id: AccountId) -> bool; @@ -98,13 +72,6 @@ pub trait AccessControllable { /// of `role`. fn acl_renounce_role(&mut self, role: String) -> bool; - /// Revokes `role` from `account_id` __without__ checking any permissions. - /// Returns whether `account_id` was a grantee of `role`. - /// - /// This method is `#[private]` in the implementation provided by this - /// crate. - fn acl_revoke_role_unchecked(&mut self, role: String, account_id: AccountId) -> bool; - /// Returns whether `account_id` has been granted any of the `roles`. fn acl_has_any_role(&self, roles: Vec, account_id: AccountId) -> bool; diff --git a/near-plugins/tests/contracts/access_controllable/src/lib.rs b/near-plugins/tests/contracts/access_controllable/src/lib.rs index afddfbf..394222f 100644 --- a/near-plugins/tests/contracts/access_controllable/src/lib.rs +++ b/near-plugins/tests/contracts/access_controllable/src/lib.rs @@ -75,6 +75,11 @@ impl StatusMessage { /// Exposing internal methods to facilitate integration testing. #[near_bindgen] impl StatusMessage { + #[private] + pub fn acl_init_super_admin(&mut self, account_id: ::near_sdk::AccountId) -> bool { + self.__acl.init_super_admin(&account_id) + } + #[private] pub fn acl_add_super_admin_unchecked(&mut self, account_id: AccountId) -> bool { self.__acl.add_super_admin_unchecked(&account_id) @@ -85,6 +90,11 @@ impl StatusMessage { self.__acl.revoke_super_admin_unchecked(&account_id) } + #[private] + pub fn acl_revoke_role_unchecked(&mut self, role: Role, account_id: AccountId) -> bool { + self.__acl.revoke_role_unchecked(role.into(), &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)