diff --git a/src/api/identity.rs b/src/api/identity.rs index 1ba59a03..3474add1 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -20,7 +20,7 @@ use crate::{ ApiResult, EmptyResult, JsonResult, }, auth, - auth::{AuthMethod, AuthMethodScope, ClientHeaders, ClientIp}, + auth::{AuthMethod, ClientHeaders, ClientIp}, db::{models::*, DbConn}, error::MapResult, mail, sso, util, CONFIG, diff --git a/src/auth.rs b/src/auth.rs index ea09a24f..f0b07a70 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1001,14 +1001,8 @@ pub enum AuthMethod { UserApiKey, } -pub trait AuthMethodScope { - fn scope_vec(&self) -> Vec; - fn scope(&self) -> String; - fn check_scope(&self, scope: Option<&String>) -> ApiResult; -} - -impl AuthMethodScope for AuthMethod { - fn scope(&self) -> String { +impl AuthMethod { + pub fn scope(&self) -> String { match self { AuthMethod::OrgApiKey => "api.organization".to_string(), AuthMethod::Password => "api offline_access".to_string(), @@ -1017,11 +1011,11 @@ impl AuthMethodScope for AuthMethod { } } - fn scope_vec(&self) -> Vec { + pub fn scope_vec(&self) -> Vec { self.scope().split_whitespace().map(str::to_string).collect() } - fn check_scope(&self, scope: Option<&String>) -> ApiResult { + pub fn check_scope(&self, scope: Option<&String>) -> ApiResult { let method_scope = self.scope(); match scope { None => err!("Missing scope"), diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 2ee86512..2e722c85 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -802,6 +802,13 @@ impl UserOrganization { .execute(conn) .map_res("Error confirming invitations") }} + .and_then(|updated| match updated { + 1 => Ok(()), + count => err!(format!( + "Failed to update users_organizations to accepted for user ({}) was expecting invited status (updated row: {})).", + user_uuid, count + )), + }) } pub async fn find_any_state_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec { diff --git a/src/sso.rs b/src/sso.rs index 0df5700c..2fbb5206 100644 --- a/src/sso.rs +++ b/src/sso.rs @@ -19,7 +19,7 @@ use openidconnect::{ use crate::{ api::ApiResult, auth, - auth::{AuthMethod, AuthMethodScope, AuthTokens, TokenWrapper, BW_EXPIRATION, DEFAULT_REFRESH_VALIDITY}, + auth::{AuthMethod, AuthTokens, TokenWrapper, BW_EXPIRATION, DEFAULT_REFRESH_VALIDITY}, db::{ models::{Device, SsoNonce, User}, DbConn,