From e8eceed1e0992190517b0b0179289146470cec97 Mon Sep 17 00:00:00 2001 From: StaNov Date: Thu, 23 Jan 2025 14:36:38 +0100 Subject: [PATCH] feat: Save notification when changed password --- .../main/kotlin/io/tolgee/constants/NotificationType.kt | 1 + .../io/tolgee/service/security/UserAccountService.kt | 8 +++++++- webapp/src/component/layout/TopBar/Notifications.tsx | 2 ++ webapp/src/service/apiSchema.generated.ts | 7 ++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/constants/NotificationType.kt b/backend/data/src/main/kotlin/io/tolgee/constants/NotificationType.kt index f81c988923..8447dc73b5 100644 --- a/backend/data/src/main/kotlin/io/tolgee/constants/NotificationType.kt +++ b/backend/data/src/main/kotlin/io/tolgee/constants/NotificationType.kt @@ -5,4 +5,5 @@ enum class NotificationType { TASK_COMPLETED, MFA_ENABLED, MFA_DISABLED, + PASSWORD_CHANGED, } diff --git a/backend/data/src/main/kotlin/io/tolgee/service/security/UserAccountService.kt b/backend/data/src/main/kotlin/io/tolgee/service/security/UserAccountService.kt index 79fb4f67be..7190024832 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/security/UserAccountService.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/security/UserAccountService.kt @@ -484,7 +484,13 @@ class UserAccountService( userAccount.tokensValidNotBefore = DateUtils.truncate(Date(), Calendar.SECOND) userAccount.password = passwordEncoder.encode(dto.password) userAccount.passwordChanged = true - return userAccountRepository.save(userAccount) + val savedUser = userAccountRepository.save(userAccount) + notificationService.save(Notification().apply { + this.user = userAccount + this.type = NotificationType.PASSWORD_CHANGED + this.originatingUser = userAccount + }) + return savedUser } private fun updateUserEmail( diff --git a/webapp/src/component/layout/TopBar/Notifications.tsx b/webapp/src/component/layout/TopBar/Notifications.tsx index b714ba6b96..edf534b9fe 100644 --- a/webapp/src/component/layout/TopBar/Notifications.tsx +++ b/webapp/src/component/layout/TopBar/Notifications.tsx @@ -108,6 +108,8 @@ function getLocalizedMessage( return ; case 'MFA_DISABLED': return ; + case 'PASSWORD_CHANGED': + return ; } } diff --git a/webapp/src/service/apiSchema.generated.ts b/webapp/src/service/apiSchema.generated.ts index 2c5f04958e..4b1ea9deaa 100644 --- a/webapp/src/service/apiSchema.generated.ts +++ b/webapp/src/service/apiSchema.generated.ts @@ -2927,7 +2927,12 @@ export interface components { linkedTask?: components["schemas"]["TaskModel"]; originatingUser?: components["schemas"]["SimpleUserAccountModel"]; project?: components["schemas"]["SimpleProjectModel"]; - type: "TASK_ASSIGNED" | "TASK_COMPLETED" | "MFA_ENABLED" | "MFA_DISABLED"; + type: + | "TASK_ASSIGNED" + | "TASK_COMPLETED" + | "MFA_ENABLED" + | "MFA_DISABLED" + | "PASSWORD_CHANGED"; }; NotificationsMarkSeenRequest: { /**