Skip to content

Commit

Permalink
Deduplicate privilege entries (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueleo authored Aug 4, 2023
1 parent 6d227ed commit bfb9a7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion server/src/handlers/http/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*/

use std::collections::HashSet;

use crate::{
option::CONFIG,
rbac::{
Expand Down Expand Up @@ -124,7 +126,8 @@ pub async fn put_role(
) -> Result<String, RBACError> {
let username = username.into_inner();
let role = role.into_inner();
let role: Vec<DefaultPrivilege> = serde_json::from_value(role)?;
let role: HashSet<DefaultPrivilege> = serde_json::from_value(role)?;
let role = role.into_iter().collect();

if !Users.contains(&username) {
return Err(RBACError::UserDoesNotExist);
Expand Down
2 changes: 1 addition & 1 deletion server/src/rbac/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl RoleBuilder {
pub mod model {
use super::{Action, RoleBuilder};

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, Hash)]
#[serde(tag = "privilege", content = "resource", rename_all = "lowercase")]
pub enum DefaultPrivilege {
Admin,
Expand Down

0 comments on commit bfb9a7f

Please sign in to comment.