Skip to content

Commit

Permalink
default to authenticated user search for nda groups
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Feb 18, 2020
1 parent cc8a4a5 commit f462737
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/api/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use serde_derive::Deserialize;
#[derive(Deserialize)]
struct SearchUsersQuery {
q: String,
#[serde(default = "TrustType::ndaed")]
t: TrustType,
t: Option<TrustType>,
g: Option<String>,
}

Expand Down
19 changes: 17 additions & 2 deletions src/db/operations/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::db::users::DisplayUser;
use crate::db::users::UserProfile;
use crate::db::Pool;
use crate::rules::engine::SEARCH_USERS;
use crate::rules::is_nda_group;
use crate::rules::RuleContext;
use crate::user::User;
use cis_profile::schema::Profile;
Expand All @@ -24,7 +25,7 @@ pub fn search_users(
pool: &Pool,
scope_and_user: ScopeAndUser,
group_name: Option<String>,
trust: TrustType,
trust: Option<TrustType>,
q: &str,
) -> Result<Vec<DisplayUser>, Error> {
let connection = pool.get()?;
Expand All @@ -38,6 +39,14 @@ pub fn search_users(
&host.user_uuid,
))?;

let trust = if let Some(trust) = trust {
trust
} else if is_nda_group(&group_name) {
TrustType::Authenticated
} else {
TrustType::Ndaed
};

internal::user::search_users_for_group(
&connection,
&group_name,
Expand All @@ -47,7 +56,13 @@ pub fn search_users(
5,
)
}
None => internal::user::search_users(&connection, trust, scope_and_user.scope.into(), q, 5),
None => internal::user::search_users(
&connection,
trust.unwrap_or(TrustType::Ndaed),
scope_and_user.scope.into(),
q,
5,
),
}
}

Expand Down

0 comments on commit f462737

Please sign in to comment.