Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Timshel committed Jan 16, 2025
1 parent 6f9b88e commit 0b556b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub async fn _register(data: Json<RegisterData>, mut conn: DbConn) -> JsonResult
err!("Registration email does not match invite email")
}
} else if Invitation::take(&email, &mut conn).await {
Membership::confirm_user_invitations(&user.uuid, &mut conn).await?;
Membership::accept_user_invitations(&user.uuid, &mut conn).await?;
user
} else if CONFIG.is_signup_allowed(&email)
|| (CONFIG.emergency_access_allowed()
Expand Down Expand Up @@ -298,7 +298,7 @@ async fn post_set_password(data: Json<SetPasswordData>, headers: Headers, mut co
if CONFIG.mail_enabled() {
mail::send_set_password(&user.email.to_lowercase(), &user.name).await?;
} else {
Membership::confirm_user_invitations(&user.uuid, &mut conn).await?;
Membership::accept_user_invitations(&user.uuid, &mut conn).await?;
}

user.save(&mut conn).await?;
Expand Down
14 changes: 5 additions & 9 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
auth::{decode_invite, AdminHeaders, ClientVersion, Headers, ManagerHeaders, ManagerHeadersLoose, OwnerHeaders},
db::{models::*, DbConn},
mail,
util::{convert_json_key_lcase_first, NumberOrString},
util::{convert_json_key_lcase_first, get_uuid, NumberOrString},
CONFIG,
};

Expand Down Expand Up @@ -330,7 +330,7 @@ async fn get_user_collections(headers: Headers, mut conn: DbConn) -> Json<Value>
#[get("/organizations/<_identifier>/auto-enroll-status")]
fn get_auto_enroll_status(_identifier: &str) -> JsonResult {
Ok(Json(json!({
"Id": "_",
"Id": get_uuid(),
"ResetPasswordEnabled": false, // Not implemented
})))
}
Expand Down Expand Up @@ -1882,18 +1882,14 @@ async fn list_policies_token(org_id: OrganizationId, token: &str, mut conn: DbCo
// Called during the SSO enrollment.
// Cannot use the OrganizationId guard since the Org does not exists.
#[get("/organizations/<org_id>/policies/master-password", rank = 1)]
fn get_master_password_policy(org_id: &str, _headers: Headers) -> JsonResult {
fn get_master_password_policy(org_id: OrganizationId, _headers: Headers) -> JsonResult {
let data = match CONFIG.sso_master_password_policy() {
Some(policy) => policy,
None => "null".to_string(),
};

let policy = OrgPolicy::new(
OrganizationId(org_id.to_string()),
OrgPolicyType::MasterPassword,
CONFIG.sso_master_password_policy().is_some(),
data,
);
let policy =
OrgPolicy::new(org_id, OrgPolicyType::MasterPassword, CONFIG.sso_master_password_policy().is_some(), data);

Ok(Json(policy.to_json()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/db/models/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ impl Membership {

// Should be used only when email are disabled.
// In Organizations::send_invite status is set to Accepted only if the user has a password.
pub async fn confirm_user_invitations(user_uuid: &UserId, conn: &mut DbConn) -> EmptyResult {
pub async fn accept_user_invitations(user_uuid: &UserId, conn: &mut DbConn) -> EmptyResult {
db_run! { conn: {
diesel::update(users_organizations::table)
.filter(users_organizations::user_uuid.eq(user_uuid))
Expand Down Expand Up @@ -1151,7 +1151,7 @@ impl OrganizationApiKey {
)]
#[deref(forward)]
#[from(forward)]
pub struct OrganizationId(pub String);
pub struct OrganizationId(String);

#[derive(
Clone,
Expand Down

0 comments on commit 0b556b2

Please sign in to comment.