Create service and DAO layer for user-role-privilege system

This commit is contained in:
Simon Goller 2024-04-28 16:01:18 +02:00
parent ab260120f2
commit 691eccc2a4
4 changed files with 795 additions and 26 deletions

View file

@ -16,8 +16,48 @@ pub trait HelloDao {
async fn get_hello(&self) -> Result<Arc<str>, DaoError>;
}
#[derive(Debug, PartialEq, Eq)]
pub struct UserEntity {
pub name: Arc<str>,
}
#[derive(Debug, PartialEq, Eq)]
pub struct RoleEntity {
pub name: Arc<str>,
}
#[derive(Debug, PartialEq, Eq)]
pub struct PrivilegeEntity {
pub name: Arc<str>,
}
#[automock]
#[async_trait]
pub trait PermissionDao {
async fn has_privilege(&self, user: &str, privilege: &str) -> Result<bool, DaoError>;
async fn create_user(&self, user: &UserEntity, process: &str) -> Result<(), DaoError>;
async fn all_users(&self) -> Result<Arc<[UserEntity]>, DaoError>;
async fn delete_user(&self, username: &str) -> Result<(), DaoError>;
async fn create_role(&self, role: &RoleEntity, process: &str) -> Result<(), DaoError>;
async fn all_roles(&self) -> Result<Arc<[RoleEntity]>, DaoError>;
async fn delete_role(&self, rolename: &str) -> Result<(), DaoError>;
async fn create_privilege(
&self,
privilege: &PrivilegeEntity,
process: &str,
) -> Result<(), DaoError>;
async fn all_privileges(&self) -> Result<Arc<[PrivilegeEntity]>, DaoError>;
async fn delete_privilege(&self, privilege: &str) -> Result<(), DaoError>;
async fn add_user_role(&self, user: &str, role: &str, process: &str) -> Result<(), DaoError>;
async fn add_role_privilege(
&self,
role: &str,
privilege: &str,
process: &str,
) -> Result<(), DaoError>;
async fn delete_role_privilege(&self, role: &str, privilege: &str) -> Result<(), DaoError>;
async fn delete_user_role(&self, user: &str, role: &str) -> Result<(), DaoError>;
}