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

Fix/improve avatar sync from LDAP #34573

merged 4 commits into from
Jun 2, 2025

Conversation

raucao
Copy link
Contributor

@raucao raucao commented May 31, 2025

This fixes 3 issues I encountered when debugging problems with our LDAP sync:

  1. The comparison of the hashed image data in IsUploadAvatarChanged is wrong. It seems to be from before avatar hashing was changed and unified in Unify hashing for avatar #22289. This results in the function always returning true for any avatars, even if they weren't changed.
  2. Even if there's no avatar to upload (i.e. no avatar available for the LDAP entry), the upload function would still be called for every single user, only to then fail, because the data isn't valid. This is unnecessary.
  3. Another small issue is that the comparison function (and thus hashing of data) is called for every user, even if there is no avatar attribute configured at all for the LDAP source. Thus, I switched the condition nesting, so that no cycles are wasted when avatar sync isn't configured in the first place.

I also added a trace log for when there is actually a new avatar being uploaded for an existing user, which is now only shown when that is actually the case.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 31, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 31, 2025
@techknowlogick
Copy link
Member

Thanks for this PR, it seems there are some linting errors that pop-up. Would you be able to resolve those?

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 31, 2025
@lunny lunny added type/bug backport/v1.24 This PR should be backported to Gitea 1.24 labels May 31, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 1, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 1, 2025
@lunny lunny enabled auto-merge (squash) June 2, 2025 05:54
@silverwind
Copy link
Member

Pull needs manual merge because it's from an org.

@lunny lunny disabled auto-merge June 2, 2025 17:03
@lunny lunny merged commit f48c013 into go-gitea:main Jun 2, 2025
26 checks passed
@GiteaBot GiteaBot added this to the 1.25.0 milestone Jun 2, 2025
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 2, 2025
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Jun 2, 2025
This fixes 3 issues I encountered when debugging problems with our LDAP sync:

1. The comparison of the hashed image data in `IsUploadAvatarChanged` is
wrong. It seems to be from before avatar hashing was changed and unified
in go-gitea#22289. This results in the function always returning `true` for any
avatars, even if they weren't changed.
2. Even if there's no avatar to upload (i.e. no avatar available for the
LDAP entry), the upload function would still be called for every single
user, only to then fail, because the data isn't valid. This is
unnecessary.
3. Another small issue is that the comparison function (and thus hashing
of data) is called for every user, even if there is no avatar attribute
configured at all for the LDAP source. Thus, I switched the condition
nesting, so that no cycles are wasted when avatar sync isn't configured
in the first place.

I also added a trace log for when there is actually a new avatar being
uploaded for an existing user, which is now only shown when that is
actually the case.

---------

Co-authored-by: wxiaoguang <[email protected]>
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Jun 2, 2025
silverwind pushed a commit that referenced this pull request Jun 2, 2025
Backport #34573 by @raucao

This fixes 3 issues I encountered when debugging problems with our LDAP
sync:

1. The comparison of the hashed image data in `IsUploadAvatarChanged` is
wrong. It seems to be from before avatar hashing was changed and unified
in #22289. This results in the function always returning `true` for any
avatars, even if they weren't changed.
2. Even if there's no avatar to upload (i.e. no avatar available for the
LDAP entry), the upload function would still be called for every single
user, only to then fail, because the data isn't valid. This is
unnecessary.
3. Another small issue is that the comparison function (and thus hashing
of data) is called for every user, even if there is no avatar attribute
configured at all for the LDAP source. Thus, I switched the condition
nesting, so that no cycles are wasted when avatar sync isn't configured
in the first place.

I also added a trace log for when there is actually a new avatar being
uploaded for an existing user, which is now only shown when that is
actually the case.

Co-authored-by: Râu Cao <[email protected]>
Co-authored-by: wxiaoguang <[email protected]>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 3, 2025
* giteaofficial/main:
  Refactor some tests (go-gitea#34580)
  Do not mutate incoming options to SearchRepositoryByName (go-gitea#34553)
  Fix/improve avatar sync from LDAP (go-gitea#34573)
  Fix some trivial problems (go-gitea#34579)
  Retain issue sort type when a keyword search is introduced (go-gitea#34559)
  Always use an empty line to separate the commit message and trailer (go-gitea#34512)
  Fix line-button issue after file selection in file tree (go-gitea#34574)
  [skip ci] Updated translations via Crowdin
  Fix doctor deleting orphaned issues attachments (go-gitea#34142)
  [skip ci] Updated translations via Crowdin
  Fix actions skipped commit status indicator (go-gitea#34507)
  Clean up "file-view" related styles (go-gitea#34558)
  Add "View workflow file" to Actions list page (go-gitea#34538)
  Do not mutate incoming options to RenderUserSearch and SearchUsers  (go-gitea#34544)
  Add webhook assigning test and fix possible bug (go-gitea#34420)
  Fix possible nil description of pull request when migrating from CodeCommit (go-gitea#34541)
  Refactor commit reader (go-gitea#34542)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/done All backports for this PR have been created backport/v1.24 This PR should be backported to Gitea 1.24 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants