diff --git a/backend/internal/common/errors.go b/backend/internal/common/errors.go index 8a8ecb1d..d385d11c 100644 --- a/backend/internal/common/errors.go +++ b/backend/internal/common/errors.go @@ -163,13 +163,6 @@ func (e *DuplicateClaimError) Error() string { } func (e *DuplicateClaimError) HttpStatusCode() int { return http.StatusBadRequest } -type AccountEditNotAllowedError struct{} - -func (e *AccountEditNotAllowedError) Error() string { - return "You are not allowed to edit your account" -} -func (e *AccountEditNotAllowedError) HttpStatusCode() int { return http.StatusForbidden } - type OidcInvalidCodeVerifierError struct{} func (e *OidcInvalidCodeVerifierError) Error() string { diff --git a/backend/internal/controller/user_controller.go b/backend/internal/controller/user_controller.go index f778ab79..dfa809e0 100644 --- a/backend/internal/controller/user_controller.go +++ b/backend/internal/controller/user_controller.go @@ -7,7 +7,6 @@ import ( "github.com/pocket-id/pocket-id/backend/internal/utils/cookie" "github.com/gin-gonic/gin" - "github.com/pocket-id/pocket-id/backend/internal/common" "github.com/pocket-id/pocket-id/backend/internal/dto" "github.com/pocket-id/pocket-id/backend/internal/middleware" "github.com/pocket-id/pocket-id/backend/internal/service" @@ -228,10 +227,6 @@ func (uc *UserController) updateUserHandler(c *gin.Context) { // @Success 200 {object} dto.UserDto // @Router /api/users/me [put] func (uc *UserController) updateCurrentUserHandler(c *gin.Context) { - if !uc.appConfigService.GetDbConfig().AllowOwnAccountEdit.IsTrue() { - _ = c.Error(&common.AccountEditNotAllowedError{}) - return - } uc.updateUser(c, true) } diff --git a/backend/internal/service/user_service.go b/backend/internal/service/user_service.go index b86ef19d..315900d4 100644 --- a/backend/internal/service/user_service.go +++ b/backend/internal/service/user_service.go @@ -294,10 +294,10 @@ func (s *UserService) updateUserInternal(ctx context.Context, userID string, upd // Check if this is an LDAP user and LDAP is enabled isLdapUser := user.LdapID != nil && s.appConfigService.GetDbConfig().LdapEnabled.IsTrue() + allowOwnAccountEdit := s.appConfigService.GetDbConfig().AllowOwnAccountEdit.IsTrue() - // For LDAP users, only allow updating the locale unless it's an LDAP sync - if !isLdapSync && isLdapUser { - // Only update the locale for LDAP users + // For LDAP users or if own account editing is not allowed, only allow updating the locale unless it's an LDAP sync + if !isLdapSync && (isLdapUser || (!allowOwnAccountEdit && !updateOwnUser)) { user.Locale = updatedUser.Locale } else { user.FirstName = updatedUser.FirstName