authentik
authentik copied to clipboard
core: custom avatar url improvements
Details
This commit improves the custom avatar url logic. Now, the custom host has the same availability check as used in the gravatar mode. If the host is not available, fallback to another avatar_mode is possible.
Also falls back to another mode if 404 is returned.
I also fixed that the mode_gravatar directly returns None on error (instead of only caching the error and returning it on next request)
closes #10100
Testing this PR
If you want to test the PR, you simply have to set a custom avatar url (e.g. https://seccdn.libravatar.org/avatar/%(mail_hash)s?d=404,gravatar,initials) and an e-mail address that has a picture uploaded.
Then, you can set the e-mail address to some returning 404 or the avatar url to something that returns an error/is not reachable.
Checklist
- [ ] Local tests pass (
ak test authentik/)- no, I believe due to the blueprint/flow creation errors that also lead to #10487 on my setup
- [x] The code has been formatted (
make lint-fix)
If an API change has been made
- ~~[ ] The API schema has been updated (
make gen-build)~~
If changes to the frontend have been made
- ~~[ ] The code has been formatted (
make web)~~
If applicable
- ~~[ ] The documentation has been updated~~
- ~~[ ] The documentation has been formatted (
make website)~~
Deploy Preview for authentik-storybook canceled.
| Name | Link |
|---|---|
| Latest commit | e8c3019174cb6ff3ef4d909309557ac90f74016f |
| Latest deploy log | https://app.netlify.com/projects/authentik-storybook/deploys/6909e6475b52a50008285aa5 |
Deploy Preview for authentik-docs canceled.
| Name | Link |
|---|---|
| Latest commit | e8c3019174cb6ff3ef4d909309557ac90f74016f |
| Latest deploy log | https://app.netlify.com/projects/authentik-docs/deploys/6909e6475cf8d30008f24506 |
I would personally replace the string concatenation with f-strings. ex:
- cache_key_hostname_available = "goauthentik.io/lib/avatars/" + hostname + "/available"
+ cache_key_hostname_available = f"goauthentik.io/lib/avatars/{hostname}/available"
would make the code more readable but im not too sure if the rest of the codebase uses this
Codecov Report
:x: Patch coverage is 57.14286% with 12 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 82.59%. Comparing base (5e4c9ad) to head (e8c3019).
:warning: Report is 71 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| authentik/lib/avatars.py | 57.14% | 12 Missing :warning: |
:exclamation: There is a different number of reports uploaded between BASE (5e4c9ad) and HEAD (e8c3019). Click for more details.
HEAD has 10 uploads less than BASE
Flag BASE (5e4c9ad) HEAD (e8c3019) e2e 8 7 unit 10 6 unit-migrate 9 4
Additional details and impacted files
@@ Coverage Diff @@
## main #10525 +/- ##
===========================================
- Coverage 92.98% 82.59% -10.39%
===========================================
Files 869 869
Lines 47949 47992 +43
===========================================
- Hits 44584 39638 -4946
- Misses 3365 8354 +4989
| Flag | Coverage Δ | |
|---|---|---|
| e2e | 44.54% <57.14%> (-0.74%) |
:arrow_down: |
| integration | 23.11% <7.14%> (-0.07%) |
:arrow_down: |
| unit | 79.56% <57.14%> (-11.51%) |
:arrow_down: |
| unit-migrate | 70.17% <57.14%> (-20.95%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I would personally replace the string concatenation with f-strings.
Thanks, good idea! Done
Does anyone know why so many workflows failed?
Are there issues with the ci? I see many command not found errors, e.g. this one:
0.516 sh: 1: docusaurus: not found
https://github.com/goauthentik/authentik/actions/runs/9961194879/job/27661861761#step:8:964
Seems I can't request a review, and none seems to be selected. This PR is finished and ready to be reviewed, but I did not get any comments for over 3 weeks now. Could I get some feedback? Do you need sth. else?
Seems I can't request a review, and none seems to be selected. This PR is finished and ready to be reviewed, but I did not get any comments for over 3 weeks now. Could I get some feedback? Do you need sth. else?
We have a bit of a backlog of PR. We'll get to this one eventually. Sorry for the delay
Another month is over, is there anything I can do? This is a very small PR with very little changed / new LOC...
This PR is now five months open, I hope it eventually gets a review and merged.
I am now unavailable and offline for a longer period of time. Maybe this can be merged without further changes? Otherwise I am grateful for someone to pick up the work. It's just a couple of lines of code for replicating the gravatar behavior, after all. One could go a step further and use the generic uri behavior instead of the gravatar specific code. This would improve code quality and simplicity further imo
@rissson I know a ping like this is a faux pas but I think this PR fell through the cracks, could you guys take a quick peek? This isn't even 50 lines but would be really helpful for custom avatar hosts :)
Deploy Preview for authentik-integrations canceled.
| Name | Link |
|---|---|
| Latest commit | e8c3019174cb6ff3ef4d909309557ac90f74016f |
| Latest deploy log | https://app.netlify.com/projects/authentik-integrations/deploys/6909e6470e51690008ead3a7 |