Commit Graph

18133 Commits

Author SHA1 Message Date
Alex Vandiver 952291e712 migrations: Clean up non one-to-one confirmations/invites.
These models should be one-to-one.  Various bugs in the past have
leaked violations in both directions; we clean them up such that every
PreregistrationUser which is not a multi-use invite has exactly one
Confirmation object associated with it.

Fixes: #22025
2024-05-02 14:23:04 -07:00
Alex Vandiver 594e2823a7 invites: Use transactions more consistently. 2024-05-02 14:23:04 -07:00
Alex Vandiver 9dfaa83aa8 invites: Remove invites worker, make confirmation object in-process.
The "invites" worker exists to do two things -- make a Confirmation
object, and send the outgoing email.  Making the Confirmation object
in a background process from where the PreregistrationUser is created
temporarily leaves the PreregistrationUser in invalid state, and
results in 500's, and the user not immediately seeing the sent
invitation.  That the "invites" worker also wants to create the
Confirmation object means that "resending" an invite invalidates the
URL in the previous email, which can be confusing to the user.

Moving the Confirmation creation to the same transaction solves both
of these issues, and leaves the "invites" worker with nothing to do
but send the email; as such, we remove it entirely, and use the
existing "email_senders" worker to send the invites.  The volume of
invites is small enough that this will not affect other uses of that
worker.

Fixes: #21306
Fixes: #24275
2024-05-02 14:23:04 -07:00
Alex Vandiver 512d53d01a invites: Stop adjusting invited_at on resends. 2024-05-02 14:23:04 -07:00
Alex Vandiver d863aa56de invites: Lock the realm when determining invitation counts.
This prevents users from hammering the invitation endpoint, causing
races, and inviting more users than they should otherwise be allowed
to.

Doing this requires that we not raise InvitationError when we have
partially succeeded; that behaviour is left to the one callsite of
do_invite_users.

Reported by Lakshit Agarwal (@chiekosec).
2024-05-02 14:23:04 -07:00
Alex Vandiver eef5d22944 invites: Make notify_invites_changed transaction-safe. 2024-05-02 14:23:04 -07:00
Alex Vandiver e48d5e4ad2 invites: Split out some functions from zerver.actions.invites.
This will avoid a circular dependency in future commits.
2024-05-02 14:23:04 -07:00
Prakhar Pratyush b17a006bf0 data_import: Remove gitter data import tool.
Gitter broke their older API as part of being integrated
into Matrix.

Their announcement blog says:
"Anything left using the Gitter APIs will need to be
updated to use the Matrix API"

This commit drops the legacy Gitter import tool and
we plan to build a new one for Matrix in future.
2024-05-02 13:25:25 -07:00
Tim Abbott d1921aed26 zulip_updates: Fix typo. 2024-04-30 18:13:18 -07:00
Alya Abbott 89717e767f updates: Add update message (level=3). 2024-04-30 17:53:44 -07:00
Lauryn Menard 8e953d9896 streams-settings-overlay: Update hash for stream to channel rename.
Updates the base hash for the streams setting overlay to be
"channels" instead of "streams".

Because there are Welcome Bot and Notification Bot messages that
would have been sent with the "/#streams" hash, we will need to
support parsing those overlay hashes as an alias for "/#channels"
permanently.

Part of the stream to channels rename project.
2024-04-30 14:44:12 -07:00
Vector73 de90d0acdf message_delete: Update "first_message_id" on message deletion.
We now "first_message_id" of the stream on the deletion of the first
message that was sent to it. This results in 1 extra query when any
stream message is deleted and 3 extra queries when the first message
sent to any stream is deleted.

Fixes #28877.
2024-04-30 14:15:22 -07:00
N-Shar-ma d64d535c2d todo: Require space after colon to separate task title from description.
This fixes the annoying behaviour where a task title with a url in it,
for example, "Fix issue https://github/com/zulip/zulip/issues/1234"
would be wrongly split into a description at the `:` in the url.
2024-04-30 12:36:42 -07:00
Anders Kaseorg d32d4434dd partial: Replace returns plugin with an annotation.
The returns plugin hasn’t been updated for mypy ≥ 1.6.  This
annotation is more limited in that it only supports a fixed number of
positional arguments and no keyword arguments, but is good enough for
our purposes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-29 17:14:41 -07:00
Anders Kaseorg 87f228fcb0 test_events: Switch verify_action to a context manager API.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-29 17:14:41 -07:00
Anders Kaseorg 9efba89a43 test_invite: Use context manager form of assertRaises.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-29 17:14:41 -07:00
Anders Kaseorg 6fef5c3e46 webhooks: Use partial with positional arguments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-29 17:14:41 -07:00
Mateusz Mandera 5ff3f0d99a get_presence_dicts_for_rows: Remove dead code for mobile_user_ids.
The argument isn't used for anything anymore.
2024-04-29 17:07:18 -07:00
Mateusz Mandera 217161824f presence: Always run do_update_user_presence in a transaction.
It was already in a transaction in one of the two call points.
2024-04-29 17:07:18 -07:00
Lauryn Menard 62e17c987f exceptions: Add IncompatibleParametersError as a JsonableError.
Creates an IncompatibleParametersError to be used in cases where
there are two (or more) optional parameters for an endpoint that
are incompatible with each other, e.g. there's a parameter for a
user name and a user ID but only one should be sent in the request
to identify the user.

Documents the error on the /api/rest-error-handling article.

Updates the PATCH users/me/subscriptions/muted_topics endpoint to
use this error when both the stream and stream_id parameters are
passed (note this endpoint is currently deprecated).
2024-04-29 16:58:47 -07:00
Sahil Batra 7518d550f2 user_groups: Remove unneeded fields from UserGroup model.
This commit removes name, description, is_system_group and
can_mention_group fields from UserGroup model and rename
them in NamedUserGroup model.

Fixes #29554.
2024-04-26 17:03:09 -07:00
Sahil Batra 27558315a2 settings: Use named_user_group field to access name.
This commit updates code to access name from named_user_group
field which points to the "NamedUserGroup" instead of directly
accessing name from "UserGroup", since name field will only
be present on NamedUserGroup objects in further commits.
2024-04-26 17:03:09 -07:00
Sahil Batra e78d0aacaf tests: Use NamedUserGroup for queries. 2024-04-26 17:03:09 -07:00
Sahil Batra a96c8b8352 groups: Use NamedUserGroup for all queries. 2024-04-26 17:03:09 -07:00
Sahil Batra 8e9c22afdc groups: Move constants inside NamedUserGroup. 2024-04-26 17:03:09 -07:00
Sahil Batra 85b7dbddbc groups: Update subgroup to be NamedUserGroup. 2024-04-26 17:03:09 -07:00
Sahil Batra dfeb896107 mention: Use NamedUserGroup objects in mention code. 2024-04-26 17:03:09 -07:00
Sahil Batra 0ff9aacb96 audit_logs: Set modified_user_group field to NamedUserGroup. 2024-04-26 17:03:09 -07:00
Sahil Batra 6b4f665b36 user_groups: Add migration to copy data to NamedUserGroup table. 2024-04-26 17:03:09 -07:00
Sahil Batra c9a7c13ea7 import: Add code to support import and export of NamedUserGroups. 2024-04-26 17:03:09 -07:00
Sahil Batra b60d5b6fc9 user_groups: Update code in actions module to use NamedUserGroup. 2024-04-26 17:03:09 -07:00
Sahil Batra 86f73fcb3d user_groups: Create NamedUserGroup objects when creating new groups. 2024-04-26 17:03:09 -07:00
Sahil Batra 71b601cf5a groups: Create NamedUserGroup table. 2024-04-26 17:03:09 -07:00
Sahil Batra 75b1f32a19 user_groups: Add get_recursive_strict_subgroups function.
This commit adds get_recursive_strict_subgroups function
which returns all the subgroups but not includes the user
group passed to the function.

We also update the test to check subgroups of named user
groups using the get_recursive_strict_subgroups function.
This is fine as we already test the get_recursive_subgroups
function.
2024-04-26 17:03:09 -07:00
nimishmedatwal ba196cfd6b help: Change URL from all-messages to combined-feed.
Changes url from /help/all-messages to /help/combined-feed.

Also renames files "all-messages.md" and "go-to-all-messages.md"
to "combined-feed.md" and "go-to-combined-feed.md" respectively.

Fixes #27802.
2024-04-26 14:28:13 -07:00
Anders Kaseorg 96fbe060a6 python: Mark regexes as raw strings.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-26 12:30:31 -07:00
Prakhar Pratyush c727b36e9c soft_reactivate: Soft reactivate if group mention has < 12 members.
Earlier, we didn't soft-reactivate users for group mentions
at all because it wasn't easy to calculate group size.

Now, we will soft reactivate if the user group mentions has
less than 12 members.

We don't reactivate all users because a user group can have a
very large size, which can lead to large backlogs in the
deferred-work queue.

Fixes part of #27586.
2024-04-24 17:40:37 -07:00
Prakhar Pratyush 43136abb70 push_notification: Use 'get_mentioned_user_group' function.
This commit updates the code in 'handle_push_notifications'
to use a common lib function 'get_mentioned_user_group'.

The code logically does the same thing in both the places,
hence the change.
2024-04-24 17:40:37 -07:00
Prakhar Pratyush e1ad0e87dd notification_data: Fix incorrect user_group size being used.
Earlier, in 'get_mentioned_user_group_name()' we were using
'get_user_group_direct_member_ids' function which just checks
the number of direct members and not the recursive membership
of the group.

We should instead use 'get_user_group_member_ids' to calculate
the correct members count of the user group.
2024-04-24 17:40:37 -07:00
Alex Vandiver e8e6abdbba management: Add lockfiles to all _once management jobs.
These would be bad if more than once ran at once.
2024-04-24 14:40:28 -07:00
Alex Vandiver 11dd6791c4 management: Provide a common lockfile dir, and a decorator for it.
Factor out the repeated pattern of taking a lock, or immediately
aborting with a message if it cannot be acquired.  The exit code in
that situation is changed to be exit code 1, rather than the successful
0; we are likely missing new work since that process started.

We move the lockfiles to a common directory under `/srv/zulip-locks`
rather than muddy up `/home/zulip/deployments`.
2024-04-24 14:40:28 -07:00
Lauryn Menard 9be4d07442 i18n: Update translated errors for stream to channel rename.
Updates various areas of the backend code that generate
JsonableErrors with translated strings to use channel
instead of stream.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard df3ab8deea invites: Update translated errors for stream to channel rename.
In zerver/views/invite.py, updates translated errors strings to
use channel instead of stream.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 9aaddc6231 stream-policy: Update everyone policy for stream to channel rename.
In zerver/models/streams.py, updates translated string for when everyone
can post to a stream/channel to use channel instead of stream.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard eb9a142a9e stream-events: Update topic name for stream to channel rename.
In zerver/models/realms.py, updates the topic for stream/channel updates
to be "channel events" instead of "stream events".

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 9b46204fad onboarding: Update new org welcome msgs for stream to channel rename.
Updates the translated strings in the messages sent by the welcome
bot in new Zulip organizations to use channel instead of stream.

Comments out part of a test that uses translated Italian strings
to check these welcome bot messages and adds a TODO comment to
note that the test code should be uncommented when those strings
are translated for the stream -> channel rename.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 3f79fd0f10 hotspots: Update "intro_streams" text for stream to channel rename.
Updates the "intro_streams" hotspot translated strings to use
channel instead of stream.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 0b5f325e48 exceptions: Update translated errors for stream to channel rename.
In zerver/lib/exceptions.py, updates translated error strings
to use channel instead of stream.

Note that the STREAM_WILDCARD_MENTION_NOT_ALLOWED and the
STREAM_DOES_NOT_EXIST error codes, and any additional fields
included with those errors, are not changed in these updates.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 51b3ef8ee3 streams-events: Update notifications for stream to channel rename.
Updates notification messages that are sent to "stream events"
topic when a permission or policy setting is changed to use channel
instead of stream. Also, updates some strings that were not marked
for translation in the message that was sent when the retention
policy was changed.

Updates notification messages that are sent when a stream/channel
is created.

Updates notification messages that are sent when a user is
subscribed to stream/channel(s).

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00
Lauryn Menard 91ffb548cc streams: Update translated errors for stream to channel rename.
Updates translated JsonableError strings that relate to streams
to use channel instead of stream. Separated from other error string
updates as this is a dense area of changes for this rename.

Part of stream to channel rename project.
2024-04-24 14:35:05 -07:00