Remove Role::from_name function
This commit is contained in:
parent
21135d7704
commit
3b5c8a4131
2 changed files with 6 additions and 11 deletions
|
@ -196,7 +196,12 @@ impl SetRole {
|
||||||
&self,
|
&self,
|
||||||
db_client: &impl DatabaseClient,
|
db_client: &impl DatabaseClient,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let role = Role::from_name(&self.role)?;
|
let role = match self.role.as_str() {
|
||||||
|
"user" => Role::NormalUser,
|
||||||
|
"admin" => Role::Admin,
|
||||||
|
"read_only_user" => Role::ReadOnlyUser,
|
||||||
|
_ => return Err(anyhow!("unknown role")),
|
||||||
|
};
|
||||||
set_user_role(db_client, &self.id, role).await?;
|
set_user_role(db_client, &self.id, role).await?;
|
||||||
println!("role changed");
|
println!("role changed");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -47,16 +47,6 @@ impl Default for Role {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Role {
|
impl Role {
|
||||||
pub fn from_name(name: &str) -> Result<Self, ValidationError> {
|
|
||||||
let role = match name {
|
|
||||||
"user" => Self::NormalUser,
|
|
||||||
"admin" => Self::Admin,
|
|
||||||
"read_only_user" => Self::ReadOnlyUser,
|
|
||||||
_ => return Err(ValidationError("unknown role")),
|
|
||||||
};
|
|
||||||
Ok(role)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_permissions(&self) -> Vec<Permission> {
|
pub fn get_permissions(&self) -> Vec<Permission> {
|
||||||
match self {
|
match self {
|
||||||
Self::Guest => vec![],
|
Self::Guest => vec![],
|
||||||
|
|
Loading…
Reference in a new issue