mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
fix(user): blacklist token after delete user role (#4428)
This commit is contained in:
@ -70,8 +70,8 @@ impl UserRole {
|
|||||||
conn: &PgPooledConn,
|
conn: &PgPooledConn,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
merchant_id: String,
|
merchant_id: String,
|
||||||
) -> StorageResult<bool> {
|
) -> StorageResult<Self> {
|
||||||
generics::generic_delete::<<Self as HasTable>::Table, _>(
|
generics::generic_delete_one_with_result::<<Self as HasTable>::Table, _, _>(
|
||||||
conn,
|
conn,
|
||||||
dsl::user_id
|
dsl::user_id
|
||||||
.eq(user_id)
|
.eq(user_id)
|
||||||
|
|||||||
@ -282,7 +282,7 @@ pub async fn delete_user_role(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if user_roles.len() > 1 {
|
let deleted_user_role = if user_roles.len() > 1 {
|
||||||
state
|
state
|
||||||
.store
|
.store
|
||||||
.delete_user_role_by_user_id_merchant_id(
|
.delete_user_role_by_user_id_merchant_id(
|
||||||
@ -291,9 +291,7 @@ pub async fn delete_user_role(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.change_context(UserErrors::InternalServerError)
|
.change_context(UserErrors::InternalServerError)
|
||||||
.attach_printable("Error while deleting user role")?;
|
.attach_printable("Error while deleting user role")?
|
||||||
|
|
||||||
Ok(ApplicationResponse::StatusOk)
|
|
||||||
} else {
|
} else {
|
||||||
state
|
state
|
||||||
.store
|
.store
|
||||||
@ -310,8 +308,9 @@ pub async fn delete_user_role(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.change_context(UserErrors::InternalServerError)
|
.change_context(UserErrors::InternalServerError)
|
||||||
.attach_printable("Error while deleting user role")?;
|
.attach_printable("Error while deleting user role")?
|
||||||
|
};
|
||||||
|
|
||||||
Ok(ApplicationResponse::StatusOk)
|
auth::blacklist::insert_user_in_blacklist(&state, &deleted_user_role.user_id).await?;
|
||||||
}
|
Ok(ApplicationResponse::StatusOk)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2376,7 +2376,7 @@ impl UserRoleInterface for KafkaStore {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
) -> CustomResult<bool, errors::StorageError> {
|
) -> CustomResult<user_storage::UserRole, errors::StorageError> {
|
||||||
self.diesel_store
|
self.diesel_store
|
||||||
.delete_user_role_by_user_id_merchant_id(user_id, merchant_id)
|
.delete_user_role_by_user_id_merchant_id(user_id, merchant_id)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@ -48,7 +48,7 @@ pub trait UserRoleInterface {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
) -> CustomResult<bool, errors::StorageError>;
|
) -> CustomResult<storage::UserRole, errors::StorageError>;
|
||||||
|
|
||||||
async fn list_user_roles_by_user_id(
|
async fn list_user_roles_by_user_id(
|
||||||
&self,
|
&self,
|
||||||
@ -145,8 +145,9 @@ impl UserRoleInterface for Store {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
) -> CustomResult<bool, errors::StorageError> {
|
) -> CustomResult<storage::UserRole, errors::StorageError> {
|
||||||
let conn = connection::pg_connection_write(self).await?;
|
let conn = connection::pg_connection_write(self).await?;
|
||||||
|
|
||||||
storage::UserRole::delete_by_user_id_merchant_id(
|
storage::UserRole::delete_by_user_id_merchant_id(
|
||||||
&conn,
|
&conn,
|
||||||
user_id.to_owned(),
|
user_id.to_owned(),
|
||||||
@ -459,18 +460,19 @@ impl UserRoleInterface for MockDb {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
) -> CustomResult<bool, errors::StorageError> {
|
) -> CustomResult<storage::UserRole, errors::StorageError> {
|
||||||
let mut user_roles = self.user_roles.lock().await;
|
let mut user_roles = self.user_roles.lock().await;
|
||||||
let user_role_index = user_roles
|
|
||||||
|
match user_roles
|
||||||
.iter()
|
.iter()
|
||||||
.position(|user_role| {
|
.position(|role| role.user_id == user_id && role.merchant_id == merchant_id)
|
||||||
user_role.user_id == user_id && user_role.merchant_id == merchant_id
|
{
|
||||||
})
|
Some(index) => Ok(user_roles.remove(index)),
|
||||||
.ok_or(errors::StorageError::ValueNotFound(format!(
|
None => Err(errors::StorageError::ValueNotFound(
|
||||||
"No user available for user_id = {user_id}"
|
"Cannot find user role to delete".to_string(),
|
||||||
)))?;
|
)
|
||||||
user_roles.remove(user_role_index);
|
.into()),
|
||||||
Ok(true)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_user_roles_by_user_id(
|
async fn list_user_roles_by_user_id(
|
||||||
@ -521,7 +523,7 @@ impl UserRoleInterface for super::KafkaStore {
|
|||||||
&self,
|
&self,
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
) -> CustomResult<bool, errors::StorageError> {
|
) -> CustomResult<storage::UserRole, errors::StorageError> {
|
||||||
self.diesel_store
|
self.diesel_store
|
||||||
.delete_user_role_by_user_id_merchant_id(user_id, merchant_id)
|
.delete_user_role_by_user_id_merchant_id(user_id, merchant_id)
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user