Skip to content

Fix/improve avatar sync from LDAP #34573

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

Merged
merged 4 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions models/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package user

import (
"context"
"crypto/md5"
"fmt"
"image/png"
"io"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (u *User) IsUploadAvatarChanged(data []byte) bool {
if !u.UseCustomAvatar || len(u.Avatar) == 0 {
return true
}
avatarID := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
avatarID := avatar.HashAvatar(u.ID, data)
return u.Avatar != avatarID
}

Expand Down
5 changes: 3 additions & 2 deletions services/auth/source/ldap/source_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
}
}

if usr.IsUploadAvatarChanged(su.Avatar) {
if err == nil && source.AttributeAvatar != "" {
if err == nil && source.AttributeAvatar != "" {
if len(su.Avatar) > 0 && usr.IsUploadAvatarChanged(su.Avatar) {
log.Trace("SyncExternalUsers[%s]: Uploading new avatar for %s", source.AuthSource.Name, usr.Name)
_ = user_service.UploadAvatar(ctx, usr, su.Avatar)
}
}
Expand Down