-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(user): implement force password reset #3572
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c136f3e
feat(user): implement force password reset
apoorvdixit88 00fa3e0
Merge branch 'main' into force-password
apoorvdixit88 cd9bff9
resolve review comments
apoorvdixit88 34bba65
resolve pr comments
apoorvdixit88 98a1d8f
resolve racnan comments
apoorvdixit88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
use api_models::user::{self as user_api, InviteMultipleUserResponse}; | ||
use api_models::user::{ | ||
self as user_api, dashboard_metadata::SetMetaDataRequest, InviteMultipleUserResponse, | ||
}; | ||
#[cfg(feature = "email")] | ||
use diesel_models::user_role::UserRoleUpdate; | ||
use diesel_models::{enums::UserStatus, user as storage_user, user_role::UserRoleNew}; | ||
use diesel_models::{enums, enums::UserStatus, user as storage_user, user_role::UserRoleNew}; | ||
#[cfg(feature = "email")] | ||
use error_stack::IntoReport; | ||
use error_stack::ResultExt; | ||
|
@@ -11,6 +13,7 @@ use router_env::env; | |
#[cfg(feature = "email")] | ||
use router_env::logger; | ||
|
||
use self::dashboard_metadata::set_metadata; | ||
use super::errors::{UserErrors, UserResponse, UserResult}; | ||
#[cfg(feature = "email")] | ||
use crate::services::email::types as email_types; | ||
|
@@ -308,6 +311,19 @@ pub async fn change_password( | |
.await | ||
.change_context(UserErrors::InternalServerError)?; | ||
|
||
#[cfg(not(feature = "email"))] | ||
{ | ||
state | ||
.store | ||
.delete_user_scoped_dashboard_metadata_by_merchant_id_data_key( | ||
&user_from_token.user_id, | ||
&user_from_token.merchant_id, | ||
enums::DashboardMetadata::IsChangePasswordRequired, | ||
) | ||
.await | ||
.ok(); | ||
} | ||
|
||
Ok(ApplicationResponse::StatusOk) | ||
} | ||
|
||
|
@@ -475,11 +491,11 @@ pub async fn invite_user( | |
.insert_user_role(UserRoleNew { | ||
user_id: new_user.get_user_id().to_owned(), | ||
merchant_id: user_from_token.merchant_id.clone(), | ||
role_id: request.role_id, | ||
org_id: user_from_token.org_id, | ||
role_id: request.role_id.clone(), | ||
org_id: user_from_token.org_id.clone(), | ||
status: invitation_status, | ||
created_by: user_from_token.user_id.clone(), | ||
last_modified_by: user_from_token.user_id, | ||
last_modified_by: user_from_token.user_id.clone(), | ||
created_at: now, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't have to clone this probably. |
||
last_modified: now, | ||
}) | ||
|
@@ -515,6 +531,16 @@ pub async fn invite_user( | |
#[cfg(not(feature = "email"))] | ||
{ | ||
is_email_sent = false; | ||
let invited_user_token = auth::UserFromToken { | ||
user_id: new_user.get_user_id(), | ||
merchant_id: user_from_token.merchant_id.clone(), | ||
org_id: user_from_token.org_id.clone(), | ||
role_id: request.role_id.clone(), | ||
}; | ||
ThisIsMani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let r_request = SetMetaDataRequest::IsChangePasswordRequired; | ||
|
||
ThisIsMani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set_metadata(state.clone(), invited_user_token, r_request).await?; | ||
} | ||
|
||
Ok(ApplicationResponse::Json(user_api::InviteUserResponse { | ||
|
@@ -692,6 +718,17 @@ async fn handle_new_user_invitation( | |
#[cfg(not(feature = "email"))] | ||
{ | ||
is_email_sent = false; | ||
|
||
let invited_user_token = auth::UserFromToken { | ||
user_id: new_user.get_user_id(), | ||
merchant_id: user_from_token.merchant_id.clone(), | ||
org_id: user_from_token.org_id.clone(), | ||
role_id: request.role_id.clone(), | ||
}; | ||
|
||
let r_request = SetMetaDataRequest::IsChangePasswordRequired; | ||
|
||
set_metadata(state.clone(), invited_user_token, r_request).await?; | ||
} | ||
ThisIsMani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Ok(InviteMultipleUserResponse { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a migration change right @apoorvdixit88?