Browse Source

Review fixes

pull/3899/head
Timshel 3 months ago
parent
commit
f353933b53
  1. 2
      src/api/identity.rs
  2. 14
      src/auth.rs
  3. 7
      src/db/models/organization.rs
  4. 2
      src/sso.rs

2
src/api/identity.rs

@ -20,7 +20,7 @@ use crate::{
ApiResult, EmptyResult, JsonResult, ApiResult, EmptyResult, JsonResult,
}, },
auth, auth,
auth::{AuthMethod, AuthMethodScope, ClientHeaders, ClientIp}, auth::{AuthMethod, ClientHeaders, ClientIp},
db::{models::*, DbConn}, db::{models::*, DbConn},
error::MapResult, error::MapResult,
mail, sso, util, CONFIG, mail, sso, util, CONFIG,

14
src/auth.rs

@ -1001,14 +1001,8 @@ pub enum AuthMethod {
UserApiKey, UserApiKey,
} }
pub trait AuthMethodScope { impl AuthMethod {
fn scope_vec(&self) -> Vec<String>; pub fn scope(&self) -> String {
fn scope(&self) -> String;
fn check_scope(&self, scope: Option<&String>) -> ApiResult<String>;
}
impl AuthMethodScope for AuthMethod {
fn scope(&self) -> String {
match self { match self {
AuthMethod::OrgApiKey => "api.organization".to_string(), AuthMethod::OrgApiKey => "api.organization".to_string(),
AuthMethod::Password => "api offline_access".to_string(), AuthMethod::Password => "api offline_access".to_string(),
@ -1017,11 +1011,11 @@ impl AuthMethodScope for AuthMethod {
} }
} }
fn scope_vec(&self) -> Vec<String> { pub fn scope_vec(&self) -> Vec<String> {
self.scope().split_whitespace().map(str::to_string).collect() self.scope().split_whitespace().map(str::to_string).collect()
} }
fn check_scope(&self, scope: Option<&String>) -> ApiResult<String> { pub fn check_scope(&self, scope: Option<&String>) -> ApiResult<String> {
let method_scope = self.scope(); let method_scope = self.scope();
match scope { match scope {
None => err!("Missing scope"), None => err!("Missing scope"),

7
src/db/models/organization.rs

@ -802,6 +802,13 @@ impl UserOrganization {
.execute(conn) .execute(conn)
.map_res("Error confirming invitations") .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<Self> { pub async fn find_any_state_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec<Self> {

2
src/sso.rs

@ -19,7 +19,7 @@ use openidconnect::{
use crate::{ use crate::{
api::ApiResult, api::ApiResult,
auth, auth,
auth::{AuthMethod, AuthMethodScope, AuthTokens, TokenWrapper, BW_EXPIRATION, DEFAULT_REFRESH_VALIDITY}, auth::{AuthMethod, AuthTokens, TokenWrapper, BW_EXPIRATION, DEFAULT_REFRESH_VALIDITY},
db::{ db::{
models::{Device, SsoNonce, User}, models::{Device, SsoNonce, User},
DbConn, DbConn,

Loading…
Cancel
Save