-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
bots: Only send avatar_url from backend when client cannot compute it. #25073
base: main
Are you sure you want to change the base?
Conversation
@sahil839 please review this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted few comments. Also, there is a typo in second commit message. It should be "deprecated".
zerver/openapi/zulip.yaml
Outdated
@@ -416,6 +416,7 @@ paths: | |||
The ID of the user who is affected by this change. | |||
avatar_url: | |||
type: string | |||
nullable: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add **Changes**
entry here and also the appropriate changes in changelog.md
and version.py
.
zerver/actions/users.py
Outdated
avatar_source=botdict["avatar_source"], | ||
avatar_version=botdict["avatar_version"], | ||
medium=False, | ||
client_gravatar=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot pass client_gravatar
as True
always. It depends on the client.
@@ -516,7 +516,15 @@ def get_owned_bot_dicts( | |||
"default_events_register_stream": botdict["default_events_register_stream__name"], | |||
"default_all_public_streams": botdict["default_all_public_streams"], | |||
"owner_id": botdict["bot_owner_id"], | |||
"avatar_url": avatar_url_from_dict(botdict), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If removing this line removes 100% coverage on zerver/lib/avatar.py
, then the function should be removed in this commit itself, since we want each commit to pass the tests.
zerver/actions/create_user.py
Outdated
@@ -343,7 +343,7 @@ def stream_name(stream: Optional[Stream]) -> Optional[str]: | |||
default_sending_stream=default_sending_stream_name, | |||
default_events_register_stream=default_events_register_stream_name, | |||
default_all_public_streams=user_profile.default_all_public_streams, | |||
avatar_url=avatar_url(user_profile), | |||
avatar_url=avatar_url(user_profile, client_gravatar=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to set client_gravatar
as False
here, since we would not know whether client can compute the gravatar or not. notify_created_user
has similar implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sahil839 making client_gravatar
always equal to False
here will cause various backend tests related to bots to fail. The reason for this is that many tests are calling the function implemented here. As this function matches the state received from server and states after applying events. As in states received from event avatar_url
is always sent and in state received from server avatar_url
is None
states does not match and hence tests are failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot assume that client can compute url for all clients by passing client_gravatar
as True
just for the sake of tests. Otherwise, the clients who cannot compute the url will also not recieve URL and would not be able to render the avatar correctly.
Instead we should assume that client cannot compute gravatar and send the url to all clients. For the tests, we would need to add code to events.py
which sets the avatar_url
to None
if client can compute it. See the code for realm_user/add
type event in lib/events.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was able to figure out how to fix the failing test cases.
fb741d0
to
4664c87
Compare
@sahil839 I have addressed all your comments. Please have a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the documentation changes once again. You have added Changes
entry in the places where behavior is not changed.
description: | | ||
URL for the user's avatar. | ||
|
||
**Changes**: In Zulip 7.0 (feature level 177) | ||
this will be `null` when client can compute the URL. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this PR changes the response of the users/me
endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are always passing client_gravatar=False
to get_raw_user_data
from get_profile_backend
.
description: | | ||
Present if `realm_user` is present in `fetch_event_types`. | ||
|
||
The URL of the avatar for the current user at 100x100 | ||
resolution. See also `avatar_url_medium`. | ||
|
||
**Changes**: In Zulip 7.0 (feature level 177) | ||
this will be `null` when client can compute the URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also incorrect. The avatar_url
field for the user themselves is always passed assuming client_gravatar=False
.
Earlier `realm_bots` data sent in `page_params` contain `avatar_url` for all cases. This commit changes this behaviour and now `avatar_url` is only sent when client cannot compute it and also make changes in frontend for computing the `avatar_url` when not sent from backend and removes deprecated function `avatar_url_from_dict` in `zerver.lib.avatar` as it was no longer used. Fixes zulip#24698.
Heads up @Ujjawal3, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
4ec3636
to
88b200c
Compare
Earlier
realm_bots
data sent inpage_params
containavatar_url
for all cases. This commit changes this behaviour and nowavatar_url
is only sent when client cannot compute it and also make changes in frontend for computing theavatar_url
when not sent from backend.Fixes: #24698
Screenshots and screen captures:
Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: