mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-26 15:04:46 +03:00
fix: allow LDAP users to update their locale
This commit is contained in:
@@ -262,13 +262,13 @@ func (s *UserService) createUserInternal(ctx context.Context, input dto.UserCrea
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) UpdateUser(ctx context.Context, userID string, updatedUser dto.UserCreateDto, updateOwnUser bool, allowLdapUpdate bool) (model.User, error) {
|
func (s *UserService) UpdateUser(ctx context.Context, userID string, updatedUser dto.UserCreateDto, updateOwnUser bool, isLdapSync bool) (model.User, error) {
|
||||||
tx := s.db.Begin()
|
tx := s.db.Begin()
|
||||||
defer func() {
|
defer func() {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
user, err := s.updateUserInternal(ctx, userID, updatedUser, updateOwnUser, allowLdapUpdate, tx)
|
user, err := s.updateUserInternal(ctx, userID, updatedUser, updateOwnUser, isLdapSync, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.User{}, err
|
return model.User{}, err
|
||||||
}
|
}
|
||||||
@@ -292,11 +292,14 @@ func (s *UserService) updateUserInternal(ctx context.Context, userID string, upd
|
|||||||
return model.User{}, err
|
return model.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disallow updating the user if it is an LDAP group and LDAP is enabled
|
// Check if this is an LDAP user and LDAP is enabled
|
||||||
if !isLdapSync && user.LdapID != nil && s.appConfigService.GetDbConfig().LdapEnabled.IsTrue() {
|
isLdapUser := user.LdapID != nil && s.appConfigService.GetDbConfig().LdapEnabled.IsTrue()
|
||||||
return model.User{}, &common.LdapUserUpdateError{}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// For LDAP users, only allow updating the locale unless it's an LDAP sync
|
||||||
|
if !isLdapSync && isLdapUser {
|
||||||
|
// Only update the locale for LDAP users
|
||||||
|
user.Locale = updatedUser.Locale
|
||||||
|
} else {
|
||||||
user.FirstName = updatedUser.FirstName
|
user.FirstName = updatedUser.FirstName
|
||||||
user.LastName = updatedUser.LastName
|
user.LastName = updatedUser.LastName
|
||||||
user.Email = updatedUser.Email
|
user.Email = updatedUser.Email
|
||||||
@@ -306,6 +309,7 @@ func (s *UserService) updateUserInternal(ctx context.Context, userID string, upd
|
|||||||
user.IsAdmin = updatedUser.IsAdmin
|
user.IsAdmin = updatedUser.IsAdmin
|
||||||
user.Disabled = updatedUser.Disabled
|
user.Disabled = updatedUser.Disabled
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = tx.
|
err = tx.
|
||||||
WithContext(ctx).
|
WithContext(ctx).
|
||||||
|
|||||||
Reference in New Issue
Block a user