Commit Graph

912 Commits

Author SHA1 Message Date
Anders Kaseorg
d6df5337ff requirements: Upgrade Python requirements.
Also enable a 24-hour dependency cooldown:
https://docs.astral.sh/uv/concepts/resolution/#dependency-cooldowns

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2026-04-17 15:04:02 -07:00
Alex Vandiver
d00cd52619 settings: Remove PREFER_DIRECT_MESSAGE_GROUP.
With the backfill migration complete, all 1:1 and self DMs now use
DirectMessageGroup recipients.  Remove the PREFER_DIRECT_MESSAGE_GROUP
setting and all code paths that conditionally used personal recipients
when the setting was False.

This simplifies recipient_users.py to always use
get_or_create_direct_message_group, updates all data importers
(Slack, Mattermost, Rocket.Chat) to always create DM groups for
1:1 messages, and removes all @override_settings decorators and
tests that only exercised the personal-recipient code path.

Some tests see query count changes from removing the redundant
get_direct_message_group lookup in get_recipient_from_user_profiles
(which now falls through directly to
get_or_create_direct_message_group), and from tests that previously
pinned PREFER_DIRECT_MESSAGE_GROUP=False now producing DM group
recipients instead of personal ones.
2026-04-15 15:23:47 -07:00
Pritesh Shetty
f00519507f email_pill: Parse email in RFC5322 format using email-addresses library.
This commit updates the invite users email input to correctly parse and
convert email addresses with attached names into pills.
The `email-addresses` library is now used to parse email addresses in
RFC5322 format, ensuring accurate extraction of names and emails.

A new `Invitee` dataclass is introduced in the backend to store invitee
details.

Fixes part of #32874.

Co-authored-by: Maneesh Shukla <shuklamaneesh24@gmail.com>
2026-04-14 15:54:11 -07:00
Lauryn Menard
df8ccadd2b analytics-tests: Clean up create user helper in test_counts.
Since commit a352f2e10, the "delivery_email" field that's set here
hasn't been used.

The default value for bot_owner is None, so we don't need to set
that here, and we can set the bot_type field directly as a param
to create_user.
2026-04-05 20:59:57 -07:00
Lauryn Menard
b6acada050 corporate: Add BillingUserCounts dataclass for billable user counts.
In preparation for implementing automated two-tier billing on plans,
renames BillingSession.current_count_for_billed_licenses to be
current_counts_for_billed_users. The function now returns a dataclass
object, BillingUserCounts, with fields for workplace and non-workplace
users.

Currently, the non-workplace user count is hardcoded to zero for all
billing session cases, and the previously returned integer for billed
license counts is returned as the workplace user count.
2026-04-05 20:47:24 -07:00
Alex Vandiver
b071d91ce0 direct_messages: Always use DM groups if they exist.
This commit exists to ease the deployment of the new 1:1 direct
message groups.  Specifically, with PREFER_DIRECT_MESSAGE_GROUP=False,
we now respect (and make use of) direct message groups if they are
found for a pair; however, they are never created.  With
PREFER_DIRECT_MESSAGE_GROUP=True, they are created if they do not
exist already.

Regardless of the setting, the NarrowBuilder merges both personal
recipients and 1:1 DM group recipients.

This is done because setting `PREFER_DIRECT_MESSAGE_GROUP` may not
happen atomically; in large instances doing this switch without
dropping services, changing `PREFER_DIRECT_MESSAGE_GROUP` will happen
in some processes before others.  As such, some processes may begin
making 1:1 DM group recipients while other processes still have
PREFER_DIRECT_MESSAGE_GROUP=False.  To always show both old and new
messages, we must include both flavors of DM recipient, and we must
ratchet towards the 1:1 DM group recipients.

A subsequent commit will handle the migration of old messages, which
can be applied after this commit is deployed, and
PREFER_DIRECT_MESSAGE_GROUP=True.

Co-authored-by: Mohammad Reza Kianifar <mohammad.76kiani@gmail.com>
2026-04-05 10:54:59 -07:00
SiddartthVS
7fdca9e076 populate-analytics: Use Realm, UserProfile and Stream in id_args dict.
Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2026-03-13 16:39:45 -07:00
Lauryn Menard
cff8013a6a populate-analytics: Delete attachments before realm and flushing cache.
When this command is run in isolation, the attachment object added for
the realm summary statistics needs to be deleted first, so that when
the cache is flushed the UserProfile object still exists. See
flush_used_upload_space_cache.
2026-03-09 20:47:11 -07:00
Tim Abbott
9016cb1a21 decorators: Rename require_member_or_admin.
@require_human_non_guest_user communicates much better that bots are
excluded, and parallels the adjacent @require_non_guest_user.
2026-02-11 16:23:50 -08:00
Mohammad Reza Kianifar
b4348bb3f0 settings: Add variable to control recipient type for 1:1 DMs.
The PREFER_DIRECT_MESSAGE_GROUP setting controls the recipient
type for 1:1 and self DMs. It defaults to False, maintaining legacy
behavior. Tests can override this with
@override_settings(PREFER_DIRECT_MESSAGE_GROUP=True) to test the new
DirectMessageGroup recipient type behavior.
2025-11-25 09:09:15 -08:00
Prakhar Pratyush
cf577ad203 push_notification: Avoid extra DB call to fetch channel name.
While calling `get_apns_alert_title`, we already have
the channel name and topic display name available.

Instead of doing a DB query to get channel name and
preparing topic display name again within `get_apns_alert_title`,
we pass these two values as arguments.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
2025-11-19 09:38:34 -08:00
Prakhar Pratyush
4ce17711e1 push_notification: Avoid duplicate get_message_payload call.
If a user had both android and apple device registered,
preparing legacy payload resulted in executing
`get_message_payload` twice - which includes DB queries
and other operations.

This commit extracts out the function to avoid duplicate
call while preparing legacy FCM and APNs payload.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
2025-11-19 09:38:34 -08:00
Anders Kaseorg
f24a0a6b81 ruff: Fix RUF059 Unpacked variable is never used.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-30 16:47:54 -07:00
Sahil Batra
764f4aa2e0 groups: Use realm_for_sharding for limiting NamedUserGroup queries.
For get and filter queries of NamedUserGroup, realm_for_sharding
field is used instead of realm field, as directly using
realm_for_sharding field on NamedUserGroup makes the query faster
than using realm present on the base UserGroup table.
2025-09-23 12:15:53 -07:00
Anders Kaseorg
40a022dcc3 zephyr: Remove Zephyr mirroring support.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-16 11:18:18 -07:00
Mohammad Reza Kianifar
2aad468807 analytics: Support DM groups in count message type query.
To maintain API compatibility during and after the migration to direct
message groups for 1:1 and self messages, update the analytics count
query to treat DM groups of size 2 or less as private messages.
2025-07-21 10:39:40 -07:00
Alex Vandiver
3e5af466e4 push_notifications: Remove vestiges of base64 storage of tokens.
APNs tokens are provided by the client in hex, and we store them in
hex.  The existing code which attempts to "validate" them by parsing
them as base64 only works because base64 is a superset of hex.

Enforce that APNs tokens are hex, and remove all of the pieces of test
code which were incorrectly passing them in as base64 strings.
2025-07-16 16:59:58 -07:00
Alex Vandiver
a5a5791794 management: Skip hourly crons during deploys.
This is most important for `send_zulip_update_announcements`, which
can race with the version run as a post-deploy hook.  However, all of
these crons can tolerate being slightly delayed, and there's little
benefit to them taking CPU or possibly hitting odd borderline race
conditions when the deploy is in progress.

For safety, we only trust the deploy lockfile if it was created
within the last hour -- deploys should not take more than an hour, and
failing to ever run hourly crons is much worse than perhaps running
them during a real very-long deploy.
2025-07-15 09:07:36 -07:00
Lauryn Menard
4e97a6d80e analytics: Get user by delivery email when creating users in test set up.
In the analytics tests, where users are created as part of the set up
of the test, we want to get users by the delivery email and not the
visible-to-other-users email field.

Prep for setting default new user email visibility in realm creation
by the organization type.
2025-07-08 09:30:39 -07:00
Anders Kaseorg
e8fdae8f7b ruff: Fix PLR1733 Unnecessary lookup of dictionary value by key.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-06-25 11:49:02 -07:00
Lauryn Menard
3aadb86225 analytics: Update labels for mobile apps for Flutter launch.
Updates the labels in the"Messages set by client" chart so that
the Flutter app is no longer labeled as "beta".

The React Native app is now labeled as "old". And the older
Android and iOS apps are now labeled as "ancient".
2025-06-13 17:00:55 -07:00
bedo
c04558fe31 stream: Add subscriber_count field.
Fixes #34246.

Add subscriber_count field to Stream model to track number of
non-deactivated users subscribed to the channel.
2025-05-13 17:36:53 -07:00
Mateusz Mandera
74019706d7 populate_analytics_db: Create missing system group memberships. 2025-05-06 12:54:35 -07:00
Tim Abbott
e92d68fffe streams: Remove require_active in access_stream code path.
This was confusingly doing an assertion about the subscription being
active, not the channel. We could rename it to
require_active_subscription. But it was only passed with a non-default
value in b2cb443d24, and that call was
removed in 378062cc83.
2025-03-07 18:08:41 -08:00
Anders Kaseorg
22de8cfea3 counts: Fix current_month_accumulated_count_for_user bounds.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-02-28 15:15:21 -08:00
Mateusz Mandera
517538a296 management: Don't silence send_server_data_to_push_bouncer exceptions.
When these exceptions are thrown from the request-to-bouncer functions
inside of manage.py register_server/update_analytics_counts, they
shouldn't be silenced, merely calling maybe_mark_pushes_disabled in the
background.
This results in the occurrence of the error not being shown to the
user. Failure to upload analytics data when running these commands
should result in a loud, obvious error.

Failure of running register_server before this change:
```
./manage.py register_server
This command registers your server for the Mobile Push Notifications Service.
Doing so will share basic metadata with the service's maintainers:

* This server's configured hostname: zulipdev.com:9991
* This server's configured contact email address: desdemona+admin@zulip.com
* Metadata about each organization hosted by the server; see:

    <https://zulip.com/doc-permalinks/basic-metadata>

Use of this service is governed by the Zulip Terms of Service:

    <https://zulip.com/policies/terms>

Do you want to agree to the Zulip Terms of Service and proceed? [Y/n]

Mobile Push Notification Service registration successfully updated!
```

The occurrence of the error is not revealed to the user. Same concern
applies to the update_analytics_counts command.

After this change:
```
./manage.py register_server
This command registers your server for the Mobile Push Notifications Service.
Doing so will share basic metadata with the service's maintainers:
    <...>
Do you want to agree to the Zulip Terms of Service and proceed? [Y/n]

Traceback (most recent call last):
  File "/srv/zulip/./manage.py", line 150, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/zulip/./manage.py", line 115, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip/zerver/lib/management.py", line 97, in execute
    super().execute(*args, **options)
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
  File "/srv/zulip/zerver/management/commands/register_server.py", line 137, in handle
    send_server_data_to_push_bouncer(consider_usage_statistics=False, raise_on_error=True)
  File "/srv/zulip/zerver/lib/remote_server.py", line 453, in send_server_data_to_push_bouncer
    response = send_to_push_bouncer(
  File "/srv/zulip/zerver/lib/remote_server.py", line 233, in send_to_push_bouncer
    raise JsonableError(msg)
zerver.lib.exceptions.JsonableError: Duplicate registration detected.
```
2025-02-19 17:11:35 -08:00
Shubham Padia
35f9305acb stream: Modify flag to allow access for users with metadata access. 2025-02-11 15:09:16 -08:00
Aman Agrawal
2f5aea6604 message_summary: Add setting to put a monthly rate limit per user. 2025-02-06 12:03:24 -08:00
Mateusz Mandera
0caf815e36 do_activate_mirror_dummy_user: Assert user_profile is a mirror dummy.
If this is called on a user without is_mirror_dummy=True, that seems
certain to be a bug. Therefore, an assert is preferable in order to
catch this, rather than returning early with noop like some other
function such as do_deactivate_user.
2025-01-28 09:38:56 -08:00
Aman Agrawal
b047c4d322 message_summary: Add API endpoint to generate narrow summary.
This prototype API is disabled in production through settings not
configuring a default model.
2025-01-22 12:12:08 -08:00
Anders Kaseorg
653b0b0436 ruff: Partially reformat Python with Ruff 0.9 (2025 style).
These are the changes that are backwards compatible with the 2024
style.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-01-14 09:42:16 -08:00
Anders Kaseorg
58822372d5 typos: Fix typos caught by typos and mwic.
Some checks failed
Code scanning / CodeQL (push) Has been cancelled
Zulip production suite / Ubuntu 22.04 production build (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:bookworm, true, false, Debian 12 (Python 3.11, backend + documentation), bookworm) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:jammy, false, true, Ubuntu 22.04 (Python 3.10, backend + frontend), jammy) (push) Has been cancelled
Zulip CI / ${{ matrix.name }} (zulip/ci:noble, false, false, Ubuntu 24.04 (Python 3.12, backend), noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm, --test-custom-db, Debian 12 production install with custom db name and user, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy, , Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble, , Ubuntu 24.04 production install, noble) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-7.0, 7.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:bookworm-8.0, 8.0 Version Upgrade, bookworm) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:jammy-6.0, 6.0 Version Upgrade, jammy) (push) Has been cancelled
Zulip production suite / ${{ matrix.name }} (zulip/ci:noble-9.0, 9.0 Version Upgrade, noble) (push) Has been cancelled
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-12-24 19:15:36 -08:00
Shubham Padia
eb943d54a9 streams: Add can_administer_channel_group as a stream setting.
We have not added current user as the default for new channels in this
commit.
2024-12-03 18:38:25 -08:00
Shubham Padia
6dcd4c4ca6 stream: Rename function to get defaults for stream permission groups. 2024-12-02 10:05:53 -08:00
Shubham Padia
9f6764a70a stream: Do not use hardcoded default values for group settings.
We were using admins group as a hardcoded value for the default of
`can_remove_subscribers_group`, now we use a function to get the value
of the default group.
2024-12-01 19:32:22 -08:00
Anders Kaseorg
5b486a74f5 test_counts: Remove mostly unused assert_table_count helper.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-10-20 18:16:27 -07:00
Lauryn Menard
10d161638e audit-log: Move subscription event types to AuditLogEventType enum.
Event types moved: SUBSCRIPTION_CREATED, SUBSCRIPTION_ACTIVATED,
SUBSCRIPTION_DEACTIVATED, SUBSCRIPTION_PROPERTY_CHANGED.
2024-09-09 11:50:13 -07:00
Lauryn Menard
caeeaf3c3f audit-log: Move user event types to AuditLogEventType enum.
Event types moved: USER_SOFT_ACTIVATED, USER_SOFT_DEACTIVATED
USER_PASSWORD_CHANGED, USER_AVATAR_SOURCE_CHANGED, USER_FULL_NAME_CHANGED
USER_EMAIL_CHANGED, USER_TERMS_OF_SERVICE_VERSION_CHANGED
USER_API_KEY_CHANGED, USER_BOT_OWNER_CHANGED,
USER_DEFAULT_SENDING_STREAM_CHANGED, USER_DEFAULT_REGISTER_STREAM_CHANGED
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED, USER_SETTING_CHANGED
USER_DIGEST_EMAIL_CREATED
2024-09-09 11:50:13 -07:00
Lauryn Menard
e5daa3470f audit-log: Move user event types to AuditLogEventType enum.
Event types moved: USER_CREATED, USER_ACTIVATED, USER_DEACTIVATED
USER_REACTIVATED, USER_ROLE_CHANGED, USER_DELETED
USER_DELETED_PRESERVING_MESSAGES
2024-09-09 11:50:13 -07:00
Anders Kaseorg
91ade25ba3 python: Simplify with str.removeprefix, str.removesuffix.
These are available in Python ≥ 3.9.
https://docs.python.org/3/library/stdtypes.html#str.removeprefix

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-09-03 12:30:16 -07:00
Kenneth Rodrigues
00a54099a2 analytics: Migrate to @typed_endpoint. 2024-08-26 08:57:49 -07:00
Tim Abbott
54ea20cc5b migrations: Squash analytics migrations.
Created using manage.py squashmigrations, with my patch to the Django
migration optimizer to correctly collapse
AddConstraints/RemoveConstraints operations.
2024-08-23 17:15:35 -07:00
Tim Abbott
afecb2eca6 migrations: Add missing elidable tags on RunPython/RunSQL steps.
This helps the squashmigrations tool know that it can squash these.
2024-08-23 17:15:35 -07:00
roanster007
c6a06d4684 direct_message_group: Add new group_size field.
This commit adds a new `group_size` field to the `DirectMessageGroup`
model, and backfills its value to each of the existing direct message
groups.

Fixes part of #25713
2024-08-23 11:09:41 -07:00
Anders Kaseorg
c03839f42f mypy: Reenable explicit-override for models.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-08-01 17:39:04 -07:00
roanster007
7b3e163d55 refactor: Rename huddle to direct_message_group in non api files.
This commit completes rename of "huddle" to "direct_message_group"
in all the non API files.

Part of #28640
2024-07-31 23:25:56 -07:00
Alex Vandiver
94795500b5 analytics: Better indexed join to analytics_usercount, using realm_id.
analytics_usercount_property_realm_id_end_time_591dbec1_idx, added
back in b7df84d5a8, makes this lookup actually indexed.
195defb031 rewrote this query in a way which stopped using the
index.
2024-07-30 09:40:55 -07:00
Mateusz Mandera
4a93149435 settings: Rework how push notifications service is configured.
Instead of the PUSH_NOTIFICATIONS_BOUNCER_URL and
SUBMIT_USAGE_STATISTICS settings, we want servers to configure
individual ZULIP_SERVICE_* settings, while maintaining backward
compatibility with the old settings. Thus, if all the new
ZULIP_SERVICE_* are at their default False value, but the legacy
settings are activated, they need to be translated in computed_settings
to the modern way.
2024-07-17 17:14:06 -07:00
Anders Kaseorg
1e9b6445a9 ruff: Fix PLR6104 Use += to perform an augmented assignment directly.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:49:51 -07:00
Anders Kaseorg
48202389b8 ruff: Bump target-version from py38 to py310.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00