use near_sdk::{AccountId, near};
use std::collections::HashMap;
pub trait AccessControllable {
fn acl_storage_prefix() -> &'static [u8];
fn acl_role_variants(&self) -> Vec<&'static str>;
fn acl_init_super_admin(&mut self, account_id: AccountId) -> bool;
fn acl_add_super_admin(&mut self, account_id: AccountId) -> Option<bool>;
fn acl_is_super_admin(&self, account_id: AccountId) -> bool;
fn acl_revoke_super_admin(&mut self, account_id: AccountId) -> Option<bool>;
fn acl_transfer_super_admin(&mut self, account_id: AccountId) -> Option<bool>;
fn acl_add_admin(&mut self, role: String, account_id: AccountId) -> Option<bool>;
fn acl_is_admin(&self, role: String, account_id: AccountId) -> bool;
fn acl_revoke_admin(&mut self, role: String, account_id: AccountId) -> Option<bool>;
fn acl_renounce_admin(&mut self, role: String) -> bool;
fn acl_grant_role(&mut self, role: String, account_id: AccountId) -> Option<bool>;
fn acl_has_role(&self, role: String, account_id: AccountId) -> bool;
fn acl_revoke_role(&mut self, role: String, account_id: AccountId) -> Option<bool>;
fn acl_renounce_role(&mut self, role: String) -> bool;
fn acl_has_any_role(&self, roles: Vec<String>, account_id: AccountId) -> bool;
fn acl_get_super_admins(&self, skip: u64, limit: u64) -> Vec<AccountId>;
fn acl_get_admins(&self, role: String, skip: u64, limit: u64) -> Vec<AccountId>;
fn acl_get_grantees(&self, role: String, skip: u64, limit: u64) -> Vec<AccountId>;
fn acl_get_permissioned_accounts(&self) -> PermissionedAccounts;
}
#[near(serializers = [json])]
#[derive(Debug)]
pub struct PermissionedAccounts {
pub super_admins: Vec<AccountId>,
pub roles: HashMap<String, PermissionedAccountsPerRole>,
}
#[near(serializers = [json])]
#[derive(Debug)]
pub struct PermissionedAccountsPerRole {
pub admins: Vec<AccountId>,
pub grantees: Vec<AccountId>,
}
pub mod events {
use crate::events::{AsEvent, EventMetadata};
use near_sdk::AccountId;
use near_sdk::serde::Serialize;
const STANDARD: &str = "AccessControllable";
const VERSION: &str = "1.0.0";
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct SuperAdminAdded {
pub account: AccountId,
pub by: AccountId,
}
impl AsEvent<SuperAdminAdded> for SuperAdminAdded {
fn metadata(&self) -> EventMetadata<SuperAdminAdded> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "super_admin_added".to_string(),
data: Some(self.clone()),
}
}
}
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct SuperAdminRevoked {
pub account: AccountId,
pub by: AccountId,
}
impl AsEvent<SuperAdminRevoked> for SuperAdminRevoked {
fn metadata(&self) -> EventMetadata<SuperAdminRevoked> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "super_admin_revoked".to_string(),
data: Some(self.clone()),
}
}
}
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct AdminAdded {
pub role: String,
pub account: AccountId,
pub by: AccountId,
}
impl AsEvent<AdminAdded> for AdminAdded {
fn metadata(&self) -> EventMetadata<AdminAdded> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "admin_added".to_string(),
data: Some(self.clone()),
}
}
}
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct AdminRevoked {
pub role: String,
pub account: AccountId,
pub by: AccountId,
}
impl AsEvent<AdminRevoked> for AdminRevoked {
fn metadata(&self) -> EventMetadata<AdminRevoked> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "admin_revoked".to_string(),
data: Some(self.clone()),
}
}
}
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct RoleGranted {
pub role: String,
pub to: AccountId,
pub by: AccountId,
}
impl AsEvent<RoleGranted> for RoleGranted {
fn metadata(&self) -> EventMetadata<RoleGranted> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "role_granted".to_string(),
data: Some(self.clone()),
}
}
}
#[derive(Serialize, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct RoleRevoked {
pub role: String,
pub from: AccountId,
pub by: AccountId,
}
impl AsEvent<RoleRevoked> for RoleRevoked {
fn metadata(&self) -> EventMetadata<RoleRevoked> {
EventMetadata {
standard: STANDARD.to_string(),
version: VERSION.to_string(),
event: "role_revoked".to_string(),
data: Some(self.clone()),
}
}
}
}