Commit Graph

19720 Commits

Author SHA1 Message Date
Alex Vandiver
f58c29b290 presence: Use the narrow user cache.
These two endpoints make up ~85% of requests to Zulip servers; since
presence is also a performance-critical endpoint, having them share
the same cache increases how hot it stays in memcached, in addition to
making the presence endpoint faster.

This comes at the very slightly cost of one extra field.  Checks
for the `is_bot` column are switched to the equivalent `bot_type`
check, since the columns are slightly duplicative, and we can get away
with only checking bot_type.
2025-02-13 12:40:53 -08:00
Alex Vandiver
44f0e936c2 sessions: Use the narrow user fetch when expiring sessions. 2025-02-13 12:40:53 -08:00
Alex Vandiver
58bf2a7935 tornado: Limit the width of the user queries, when they're needed.
Tornado requests try hard to not make SQL queries -- and if they're
necessary, to minimize the number of them.  Specifically, both session
objects and user objects are cached in memcached, and we expect that
both of them will have been filled there by Django before any requests
are made to Tornado.

In the event that memcached is flushed, or data is otherwise evicted,
we perform two database queries -- one for the session, and one for
the user.  However, the *width* of the latter query has grown
significantly over time, as the Realm object grew more fields, and
recently with the addition of role groups, which require multiple
joins each.  This leads to a query which is over 12k of text long, and
results in 319 columns.  In the event of a memcached flush, this can
result in a *significant* amount of SQL traffic, as nearly every
active Tornado request will make that query.

We do not wish to narrow the default query for Django; we instead tag
the request in the REST wrapper, and use that to use a much narrower
user cache entry.  That narrower cache entry is filled before the
queue is created in Django; we also use it to explicitly set the log
data, so the second "half" of the continued Tornado request does not
need to fetch any user data either when writing its log line.

Because they use different cache keys, this only affects the
session-based `/json/events` endpoint, which caches by user-id; the
`/api/v1/events` endpoint, which uses an API-key cache, keeps its wide
user object.  The former is 50% of the total request volume, whereas
the latter is only 2%, so adding an additional cache for it is
unnecessary complexity.
2025-02-13 12:40:53 -08:00
Alex Vandiver
7c20f1d3ea tornado: Always copy requester_for_logs from initial request.
The previous logic over-wrote the requester with the old value if it
had been set to anything in the new request, which it never could have
been.  This logic likely stems from confusion in the hasattr
introduced in `89394fc1ebee`.

Always copy the `requester_for_logs` from the first half of the
request.
2025-02-13 12:40:53 -08:00
Alex Vandiver
7ed35845df tornado: Remove incorrect rate_limit request note.
1ea2f188ce mistakenly introduced a `_rate_limit` member of the
request, which was dutifully transcribed in 3f9a5e1e17.  However,
`_rate_limit` was never read from, nor written to -- `_ratelimit` (with
no middle `_`) was the dict that contained rate-limiting data.  This
`_ratelimit` dict was later renamed to the `_ratelimits_applied` list,
in e86cfbdbd7, which became the `ratelimits_applied` request note
field in 03693cd27e.

Remove the entirely unused `rate_limit` note, and properly copy the
`ratelimits_applied` data into the new request.
2025-02-13 12:40:53 -08:00
Aman Agrawal
75be449d45 CVE-2025-25195: Only send "active" change events to channel subscribers.
This fixes a bug where private stream event to update stream's
active status was sent to all active users instead of just
its subscribers.
2025-02-13 11:58:23 -08:00
Aman Agrawal
a2a1a7f8d1 streams: Use a common func to send stream recently active update event.
This helps us to apply fix for sending event update for
private stream to only its subscribers.
2025-02-13 11:58:23 -08:00
Mateusz Mandera
367d193639 register_server: Rename flag to --agree-to-terms-of-service.
That's a better style than the underscores.
2025-02-13 11:03:44 -08:00
Mateusz Mandera
1c57e04cc1 docs: Change /doc-permalinks/ redirects to point to /stable/ RTD.
With the exception of /registration-transfer, the /stable/ docs have the
relevant sections - so that's the better choice to link to.
2025-02-13 11:03:44 -08:00
Mateusz Mandera
a8fbf6d5d5 docs: Remove HostnameAlreadyInUseBouncerError.docs_url.
Now that we introduced an URL for serving permalinks redirecting to
docs in #33444, the docs_url mechanism is no longer needed, as we can
have a URL that's safe to hard-code in register_server.py.

The HostnameAlreadyInUseBouncerError.docs_url has been merged in main
briefly enough, that this should be safe to remove.
2025-02-13 09:49:28 -08:00
Vector73
2ef9695ef0 settings: Migrate wildcard_mention_policy to group-based permission.
Added new group-based permission setting
`can_mention_many_users_group` to replace `wildcard_mention_policy`.
2025-02-12 23:21:33 -08:00
opmkumar
2a15da47d9 message_edit: Show typing indicator for message editing.
This commit adds typing indicators for message editing in stream
as well as in dm, if the send typing notification
for corresponding is enabled.

Based on earlier work in #28585.

Co-authored-by: Rohan Gudimetla <rohan.gudimetla07@gmail.com>

Fixes #25719.
2025-02-12 15:08:56 -08:00
opmkumar
c2821ef0f4 typing: Remove an unnecessary comment in zerver/actions/typing.py.
The comment was incorrectly placed and misleadingly suggested that
`long_term_idle` subscribers were excluded from `subscription_query`,
whereas they were not.
2025-02-12 15:08:56 -08:00
Aman Agrawal
3d5307c0a9 message_summary: Add markdown support for generated summary. 2025-02-12 13:23:42 -08:00
Tim Abbott
ca0babc7e9 message_summary: Don't meter analytics query as AI work. 2025-02-12 13:23:42 -08:00
roanster007
c562503089 markdown: Fix stream description with topic permalink not rendered.
Previously, when description for a channel -- either during its
creating or when we change its description contained a topic
permalink (through #-mention), then it was not rendered. This
is because of lack of authorization to access the channel.

This is fixed by passing the acting_user through the methods
which update or add the description, so that permissions
of the acting_user could be used to determine whether to
render the #-mention in stream description or not.
2025-02-12 12:50:25 -08:00
roanster007
4789de2e96 markdown: Fix #-mention of private channel's topic made by system bots.
Previously when system bots used to `#-mention` a private
channel's topics in cases like moving messages of a private
channel, then the #-mentions were not rendered by the
markdown. This was because the system bots did not have
authorization to mention these channels.

This is fixed by passing down an `acting_user` parameter
in code paths involving sending these move message
notifications so that permission of acting_user to mention
the topic is verified for rendering the markdown, rather
than that of the system bot.
2025-02-12 12:50:25 -08:00
Aman Agrawal
a2dd84541d auth: Fix 500 error on accessing selfhosting subdomain user login page.
selfhosting in not to valid subdomain for user login, so we render
invalid_realm page on that URL.
2025-02-12 12:43:23 -08:00
Sahil Batra
7eeb8a2c26 settings: Add personal setting to show or hide AI features.
Fixes #33231.
2025-02-12 12:05:04 -08:00
Sahil Batra
4ca28bb850 settings: Add setting to control permission for topic summarization. 2025-02-12 12:05:04 -08:00
Sahil Batra
9b38444e42 register: Add server_can_summarize_topics to response.
We now pass a new field in register response to tell
clients whether summarizing topics is enabled for the
server or not.
2025-02-12 12:05:04 -08:00
Mateusz Mandera
ac0af8d5ff install: Replace RTD links with our new permalinks. 2025-02-12 09:50:52 -08:00
Mateusz Mandera
a6f1916ab1 docs: Add endpoint for permalinks to some push notifs docs.
This will gives us the flexibility to edit our documentation, including
section names, without worrying about breaking links to docs hard-coded
in older releases / deployed self-hosted servers.
2025-02-12 09:50:52 -08:00
Alya Abbott
8f7c968408 help: Update self-hosted billing instructions.
Remove most references to Server 8.0 (not relevant for new installs).
2025-02-12 09:41:20 -08:00
Prakhar Pratyush
0e284464f1 api_docs: Improve docs related to mandatory topics. 2025-02-12 09:37:21 -08:00
Shubham Padia
552b464de7 stream: Notify all users with metadata access when unarchiving. 2025-02-12 09:35:17 -08:00
Shubham Padia
1db2487f1c stream: Guest users cannot get metadata access to channel via groups. 2025-02-12 09:35:17 -08:00
Tim Abbott
77d3029ec5 streams: Exclude guests from permissions groups access.
This adds missing enforcement and explanatory comments regarding
`allow_everyone_group` for these permissions code paths.
2025-02-11 15:09:16 -08:00
Shubham Padia
6e588b5b4a openapi: Make stream setting groups documentation up-to-date. 2025-02-11 15:09:16 -08:00
Shubham Padia
cbd23cc535 stream: Notify guest add subscribers group users for public channels.
For the test, we've only modified `test_rename_stream` to test for this
+ the guest susbcriber test case that was missing.
2025-02-11 15:09:16 -08:00
Shubham Padia
596aa2d357 subscription: Do not prefetch recursive user ids for single stream.
Pass a UserGroupMembershipDetails object to store
`user_recursive_group_ids` and fetch it only once max.
2025-02-11 15:09:16 -08:00
Shubham Padia
3893dcfcb8 stream: Do not send redundant events to users with metadata access.
When a user gets access to a private channel, they get a stream creation
event. Channel admins and users in `can_add_subscribers_group` already
have metadata access to a private channel and therefore do not need to
be notified.
2025-02-11 15:09:16 -08:00
Shubham Padia
33ea2b366e user_groups: Add function to get union of members of two groups.
This helps us important database queries when we want to perform a union
on the members of multiple user groups.
2025-02-11 15:09:16 -08:00
Shubham Padia
121af1c815 stream: Pass group id to get recursive group members.
Previously, we needed to pass the group to the function, which sometimes
meant having 1 extra query to fetch the user group when we just needed
the group id for this function.
2025-02-11 15:09:16 -08:00
Shubham Padia
35f9305acb stream: Modify flag to allow access for users with metadata access. 2025-02-11 15:09:16 -08:00
Shubham Padia
9725de99e9 stream: Move bulk_get_subscriber_peer_info to subscription_info.
We were not able to use
get_user_ids_with_metadata_access_via_permission_groups in the function
in question due to a cyclic dependency to `lib/streams.py`.
2025-02-11 15:09:16 -08:00
Shubham Padia
aabf42c2ce stream: Show private channel for their channel admins.
Fixes https://chat.zulip.org/#narrow/channel/101-design/topic/permissions.20for.20admin.20to.20unsubscribe.20others/near/2060197
Non realm admin users were not able to view private channels they were
an administrator of but not subscribed to it. This commit changes that.
We also made changes for those users to be able to see the subscribers
list.

The increase in query count in test_home and test_event_system can be
mitigated by only fetching recursive user group ids when needed within
the `validate_user_access_to_subscribers_helper` function. But that
would require refactoring that function to handle multiple streams and
subscriptions at once, along with changing how that function is used at
different places, which might be an exercise better left as a follow up.
We have optimised the code a little bit by not fetching the group ids in
case the current user is a realm admin.

We are fetching channel_admin_ids and users belonging to
can_add_subscribers_group directly in stream_subscription.py without
using the helper function
`get_user_ids_with_metadata_access_via_permission_groups`. This is due
to a cyclic dependency and we will move `bulk_get_subscriber_peer_info`
to another file in the next commit.
2025-02-11 15:09:16 -08:00
Shubham Padia
48eec43f48 stream: Notify users with metadata access on unarchiving stream. 2025-02-11 15:09:16 -08:00
Shubham Padia
f6301c24fe stream: Notify users with metadata access for lib/streams.py.
Users in `can_administer_channel_group` and `can_add_subscribers_group`
have access to private channel metadata. They should be notified of
relevant events.
We've only made relevant changes to lib/streams.py in this commit to
make the changes small and reviewable.
2025-02-11 15:09:16 -08:00
Shubham Padia
ca1aba9fc3 stream: Allow realm & channel admins to change private channel setting.
Previously, realm and channel admins were not able to change settings
for a private channel they were not subscribed to. This commit changes
that.

We have only added the exception for can_add_subscribers_group
and not privacy settings.

We also need proper functions with proper terminologies for content
and metadata access.
2025-02-11 15:09:16 -08:00
Shubham Padia
4d02a082a0 stream: Users with permission to administer can unsubscribe others.
We've also converted the function to check for permission to unsubscribe
others to accept a list of streams instead of checking each stream one
by one.
2025-02-11 15:09:16 -08:00
Shubham Padia
0f51b029a0 stream: User with just can add permissions should be able to add. 2025-02-11 15:09:16 -08:00
Shubham Padia
9e09a240d7 stream: Pass is_subscribed to check_basic_stream_access.
Earlier, we were passing the whole subscription object to the function
in order to check if the user was subscribed or not. In the future
commits, we want to check that without fetching and passing the complete
subscription object and this commit will help us do that.
2025-02-11 15:09:16 -08:00
Shubham Padia
98c5243c9b stream: Refactor to use functions for administer and add subscribers. 2025-02-11 15:09:16 -08:00
Lauryn Menard
2de2b22d55 help: Update for subscribe/unsubscribe user to channel terminology.
Instead of referring to users being added or removed from channels,
we now use subscribe or unsubscribed from channels.

Splits the article for adding and removing users from a channel
into separate articles: /help/subscribe-users-to-a-channel and
/help/unsubscribe-users-from-a-channel.

The URL redirects for the combined add/remove articles (for both
channel and stream terminology) go to the subscribe users to a
channel article.
2025-02-10 15:54:35 -08:00
apoorvapendse
5e6764373f copy_and_paste: Remove spannification logic for math expressions.
We instead use a turndown filter to get
what we want in case of inline expressions.

This removes most of the faulty logic
introduced by @apoorvapendse.

Fixes: https://chat.zulip.org/#narrow/channel/9-issues/topic/HTML.20paragraphs.20misconverted.20by.20copy.20and.20paste/near/2078384
2025-02-10 10:02:10 -08:00
Sahil Batra
4deb0a46a3 test_events: Refresh self.user_profile in verify_action.
For some cases, if the function called for testing events
changes some realm property using the realm object other
than the one derived from self.user_profile, then while
matching the states, self.user_profile still has the
old realm object.
2025-02-06 17:20:01 -08:00
Sahil Batra
58d21c432e event_schema: Update check_user_group_update to check multiple fields.
We can send data for multiple fields in user group update event
so this commit updates check_user_group_update accordingly.
2025-02-06 17:20:01 -08:00
Sahil Batra
8b068cf244 groups: Remove unused parameter from parse_group_setting_value.
setting_name parameter was not being used in
parse_group_setting_value function.
2025-02-06 17:20:01 -08:00
Vector73
cb6f0fd63c realm: Add setting to notify user on DMing guest.
Added `enable_guest_user_dm_warning` setting to decide whether
clients should show a warning when a user is composing to a guest
user in the organization.

Fixes #30078.

Co-authored-by: adnan-td <generaladnan139@gmail.com>
2025-02-06 12:15:41 -08:00