Commit Graph

19198 Commits

Author SHA1 Message Date
PieterCK 8764e15599 slack_regex: Fix overlapping capture group in Slack regex.
The Slack text regexes match specific characters before and after the
formatted string to prevent cases like reformatting already formatted
text and test like `invlaid_bold_test` in
`slack_message_conversion.json`.

However, because the capture groups consume each matching character, two
formatted strings separated by a single matching character result in one
string not being matched, as the character is used to match the other
string.

e.g., (`*abc*b*def*` → **abc**b*def*) in this case, "b" is consumed to
match *abc*.

This prep commit modifies the Slack text regex in
`slack_message_conversion.py` to use a non-greedy quantifier for the
last capture group.
2024-11-21 16:18:20 +07:00
PieterCK 5c8f10179a slack_regex: Refactor Slack text regex main capture group.
This prep commit to make `slack_incoming` use the same Slack
reformatting functions as the Slack import. Currently the Slack
regex at `slack_message_conversion.py` couldn't capture formatted
strings containing emojis in it. This commit reworks the main
capture group for formatted strings in Slack text regex in
`slack_message_conversion.py`.

Previously, the regex used multiple capture groups designed to
include everything except the formatting prefix and suffix
(`*`, `~`, `_`). This approach is replaced with a single capture
group that explicitly excludes these formatting characters,
simplifying the logic.
2024-11-21 16:18:14 +07:00
PieterCK 414c72172a slack_regex: Update Slack text regex capture newlines.
This prep commit modifies the Slack text regex in
`slack_message_conversion.py` to include the newline character (`\n`) as
part of the first and last capture groups.

Previously, the regex in `slack_message_conversion.py` couldn't capture
and reformat strings surrounded by newlines, such as "\n*ABC*\n". This
kind of string is likely not uncommon to be generated by both the Slack
exporter itself or by our Slack message block and attachment formatters
(`render_blocks` and `render_attachments`).
2024-11-21 16:10:47 +07:00
PieterCK 49eca01cfc slack_import: Create replace_links for Slack incoming webhook.
This prep commit introduces the `replace_links` function to convert
Slack-formatted links into Zulip-friendly format. This function uses the
same reformatting functions used in the Slack importer, and is intended
to replace an existing function of the same name in the Slack incoming
webhook, eliminating duplicate code.

Further refactors are needed before this function can be fully
integrated into the Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK 8dd56e2340 slack_import: Create and use convert_slack_formatting helper function.
This prep commit extracts the logic for converting Slack formatted text
into Zulip friendly markdown from `convert_to_zulip_markdown` into a new
helper function, `convert_slack_formatting`.

This is done to make reformating logic be reusable else where such as in
the Slack webhook or Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK c5bd16ec77 slack_import: Create and use the convert_slack_workspace_mentions helper.
This prep commit extracts the logic for reformatting Slack mentions into
Zulip mentions from `convert_to_zulip_markdown` into a new helper
function, `convert_slack_workspace_mentions`.

This is done to make the logic reformatting logic be reusable else where
such as in the Slack webhook or Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK 9e3cd756b0 slack_import: Rearrange convert_mailto_format function.
This prep commit moves the helper function `convert_mailto_format` to
appear before its primary usage in `convert_to_zulip_markdown`. This
adjustment aligns with code style conventions, improving readability.

The change is also part of the refactor to make Slack text reformatting
functions reusable in the Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK 2bd920418e slack_import: Rearrange convert_link_format function.
This prep commit moves the helper function `convert_link_format` to
appear before its primary usage in `convert_to_zulip_markdown`. This
adjustment aligns with code style conventions, improving readability.

The change is also part of the refactor to make Slack text reformatting
functions reusable in the Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK abcc36ab7f slack_import: Rearrange convert_markdown_syntax function.
This prep commit moves the helper function `convert_markdown_syntax` to
appear before its primary usage in `convert_to_zulip_markdown`. This
adjustment aligns with code style conventions, improving readability.

The change is also part of the refactor to make Slack text reformatting
functions reusable in the Slack incoming webhook.
2024-11-21 16:04:34 +07:00
PieterCK 8fe0fbc4a0 slack_import: Rearrange get_user_mentions function.
This prep commit moves the helper function get_user_mentions to appear
before its primary usage in `convert_to_zulip_markdown`. This adjustment
aligns with code style conventions, improving readability.

The change also prepares the codebase for reusing Slack text
reformatting logic in the Slack incoming webhook.
2024-11-21 16:04:34 +07:00
Vector73 de44eb6a1b settings: Remove `invite_to_realm_policy` setting.
Removed `invite_to_realm_policy` property, as the permission
to invite other users to the organization is now controlled by
`can_invite_users_group` setting.
2024-11-20 13:35:05 -08:00
Vector73 4e89b4a88c settings: Add `can_invite_users_group` realm setting.
Added `can_invite_users_group` realm setting to replace
`invite_to_realm_policy`.
2024-11-20 13:35:05 -08:00
Sahil Batra a19287d581 streams: Optimize fetching setting values for web public subs.
This commit updates code to fetch the group setting values
efficiently for web public subscription objects.
2024-11-19 13:26:42 -08:00
Sahil Batra f4c00ce053 streams: Fix setting values passed in never subbed dicts.
This commit fixes the code to pass AnonymousSettingGroupDict
value instead of group ID when the setting is set to anonymous
groups in never subscribred streams subscription dicts.
2024-11-19 13:26:42 -08:00
oscar 9d1ca5476a integration-docs: Remove create channel for generate webhook URL docs.
Updates text of generate-webhook-url-basic.md to replace the use of
the "Create the channel" step.

Removes {!create-channel.md!} from all the integrations docs that
also include {!generate-webhook-url-basic.md!}.

Fixes #32269.
2024-11-19 13:02:01 -08:00
Anders Kaseorg c48ef926e1 mypy: Add types-defusedxml.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-19 11:09:34 -08:00
Anders Kaseorg 532aee926c requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-19 11:09:34 -08:00
jitendra-ky ca14366e38 import: Replace generic Exception with CommandError.
This change improves error handling in `do_import_realm` by replacing
the use of a generic Exception with CommandError. The updated approach
provides clearer, user-friendly error messages when there is a version
mismatch between the exported data and the Zulip server.

Fixes #32292.
2024-11-18 18:35:14 -08:00
Tim Abbott 18246ebd9f i18n: Update translation data from Transifex. 2024-11-18 16:12:31 -08:00
Sahil Batra d5a391a56b streams: Optmize code to send events on creating stream.
This commit updates code to effectively compute the setting
values when creating stream object to be sent in stream creation
events.
2024-11-18 11:55:19 -08:00
Sahil Batra 7adc83d2a0 streams: Optimize code for computing stream objects.
This commit updates code to optimize code for computing stream
objects to be sent with stream creation event and in response
for 'GET /streams/{stream_id}' endpoint by optimizing number
of queries while computing values for group permission settings.

This change does not benefit much currently as we only have one
stream group permission setting, but is important before we add
more stream permission settings.

There are a couple of places left where we can still optimize
the code and that would be done in further commits.
2024-11-18 11:55:19 -08:00
Sahil Batra 2cc0f482e1 streams: Refactor code to compute setting group values.
This commit adds a new function to compute setting group
values for a list of streams, so we can avoid having duplicate
code for computing setting group IDs from streams.
2024-11-18 11:55:19 -08:00
Sahil Batra b20c24c09d streams: Compute object only when needed.
This commit updates code to compute the values for group permission
settings in send_stream_creation_events_for_previously_inaccessible_streams
only when we need to send the events. This helps us in avoiding
unnecessary DB queries.
2024-11-18 11:55:19 -08:00
Sahil Batra f2158c42a7 streams: Do not call "locals()" inside loop.
There is no need to call "locals()" inside the loop for
stream permission settings. It should just be called once
to get values of all the settings passed to the endpoint.

It was fine as we only had one group permission setting
for stream, but is a good fix before we add more settings.
2024-11-18 11:55:19 -08:00
Shubham Padia b6ebf143cc streams: Backend changes to support anonymous groups.
can_remove_subscribers_group setting can now be set to
anonymous user groups.

Co-authored-by: Sahil Batra <sahil@zulip.com>
2024-11-16 17:11:08 -08:00
Sahil Batra b78ca79ccf user_groups: Define AnonymousSettingGroupDict in types.py.
AnonymousSettingGroupDict is now defined in types.py instead
of user_groups.py to avoid import cycles in future commits.
2024-11-15 16:36:37 -08:00
Sahil Batra 10ae4ffea4 subscription: Refactor code for creating subscription dicts.
This commit refactors code to create subscription dicts so
that we can efficiently compute can_remove_subscribers_group
setting when we add support to set the setting to anonymous
groups.
2024-11-15 16:36:37 -08:00
David Flanagan eec9b8e683
integrations: Avoid UUIDs in topics for linear.
The initial implementation for this feature used the issue UUID
to create the topics, as some of the webhook events only provide
this and it is the only way to group sub-issues with parents.

However, if we sacrifice this and allow sub-issues to be
their own topic then we can avoid using the UUID as the topic name.

I think the quality of life improvement to topics here warrants this change,
as UUID topic names can be come unruly very quickly.

Part of #23118.
2024-11-15 11:06:39 -08:00
whilstsomebody 8356a9d9e4
narrow_filter: Add negation support for in:home narrow filter.
The in:home narrow filter is used to filter messages that appear
in the home view, i.e., messages that are not muted. Conversely,
`-in:home` should filter messages that are not in the home view,
i.e., muted messages. However, `-in:home` did not work as expected
because this filter lacked negation support, unlike similar code
paths.

This commit adds negation support for the in:home filter.

For more information, see:
<https://chat.zulip.org/#narrow/channel/378-api-design/topic/mark.20muted-topic.20messages.20as.20read/near/1980534>.
2024-11-14 15:10:01 -08:00
Prakhar Pratyush 6820cbb980 realm_export: Change tarball_size_bytes to PositiveBigIntegerField.
This commit updates `tarball_size_bytes` field from
`PositiveIntegerField` to `PositiveBigIntegerField` to support
larger values.
2024-11-14 10:09:03 -08:00
Anders Kaseorg 2de648df02 makemessages: Write with orjson.
orjson’s use of Unicode is more consistent with what we get from
Transifex.  (We could alternatively use json’s ensure_ascii=False
flag.)

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-13 17:40:51 -08:00
Anders Kaseorg 01540b45b0 web: Set "type": "module" and convert various CJS files to ESM.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-13 09:18:56 -08:00
Anders Kaseorg 687f1b1651 tests: Rename the Node tests to *.cjs.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-13 09:18:56 -08:00
Anders Kaseorg b3f18b805d ruff: Enable B008 function-call-in-default-argument.
https://docs.astral.sh/ruff/rules/function-call-in-default-argument/

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-11-10 22:43:55 -08:00
Mateusz Mandera 70fb590466 change_realm_subdomain: Revoke user sessions.
If we don't revoke sessions, this can lead to issues when we import a
realm (e.g. from Slack) into the original subdomain for the same
organization. Because then, users who already had sessions before the
move end up stuck:
- when they try to open Zulip on the original subdomain, which now has
the imported instance, they get redirected to the moved subdomain due to
their pre-existing session cookie.
- they can't even log out to get rid of the bugged cookie, because the
account they're logged into in that session is now on the moved
subdomain.
2024-11-10 19:13:14 -08:00
Mateusz Mandera 1f21b7437c test_import_export: Don't hard-code ZULIP_VERSION in fixtures.
Otherwise, these tests fail if ZULIP_VERSION is different locally from
what's hard-coded. Use a placeholder instead and replace dynamically in
a helper function.
2024-11-10 19:12:39 -08:00
PieterCK 0d7199b22e data_import: Add migration status file to converted exports.
This commit updates all third-party importer tools (Slack, Mattermost,
and Rocket Chat) in the `zerver/data_import` directory to also output a
migration_status.json file in their output tarball.

This is required because all importable tarball will be checked for
migration compatibility during import.

Fixes #28443.
2024-11-08 15:52:45 -08:00
PieterCK a9838d8089 import: Verify exported realm's migration compatibility.
When transferring a realm to a server that has a different set of
applied migrations (different Zulip versions), there is a chance that
the imported data formats appear to be compatible but data invariants
could still be violated.

This commit adds an assertion during the import process to verify
that both the exported realm and the importing server have matching
Zulip versions and have a compatible set of migrations.
2024-11-08 15:52:45 -08:00
PieterCK 40bcb4b42b export: Add migration status file to export tarball.
This commit updates the export process to write the migration status of
the realm as a JSON file to be included in the export tarball.

This is a preparatory step for adding an assertion to ensure that the
importing and exporting realms have a compatible set of applied
migrations.
2024-11-08 15:52:45 -08:00
Giovanni Silva 70d559cafa integrations: Update New Relic integration.
Newrelic has introduced a new update. This commit
updates the exisiting integration by adding support
for new types of payloads and cleaning up legacy
codes and fixtures.

Fixes #29729.

Co-authored-by: Pieter CK <pieterceka123@gmail.com>
Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-11-08 15:49:56 -08:00
Mateusz Mandera 420849ff6a slack: Call the correct resize_* function when importing realm icon.
For resizing the icon.png files, we use resize_avatar, not resize_logo.
This is pretty confusing - sure, for icons we use the same function as
for avatars, but we should have a proper name for the function called in
the icon context. So this commit also adds resize_realm_icon, and
changes the calls to resize_avatar in icon contexts to
resize_realm_icon.
2024-11-08 15:43:18 -08:00
Mateusz Mandera a669fece3a email_mirror: Check that email gateway bot can send to the channel.
Otherwise this leads to an uncaught exception when the check happens
later in `check_message`.
2024-11-08 13:13:15 -08:00
Harsh e468818d2b import: Remove skipping of too-long messages during import.
This commit eliminates the skipping of messages longer than 10K characters during the import process.
2024-11-07 16:04:14 -08:00
PieterCK 92437b4ab5 integrations: Refactor slack_incoming webhook.
This commit refactors `render_attachment` and `render_block`
out of slack_incoming.py to promote reusability.

The primary motivation for this refactor is to add support for
converting integration bots messages in Slack exports, which could use
the same functions.

Part of #31311.
2024-11-07 10:47:08 -08:00
swayam0322 6c583c9bfe integrations: Update GoCD integration.
Previously, the GoCD integration relied on GoCD's integration with bug
tracking and monitoring tools through the users' Config XML file [1].
However, this feature no longer works as expected, as it cannot send
HTTPS payloads to an external endpoint.

This commit updates our GoCD integration to use Sentry's WebHook
notifier GoCD plugin [2] to send webhook payloads from users GoCD server
to Zulip. We are using an older version of the plugin—v0.0.6—because the
newer version—v0.0.9—doesn't work at this time.

Additionally, this change reformats the notifications to include more
details on the GoCD event, such as lists of passed and failed jobs.

Fixes #21224.

Co-authored-by: Pieter CK <pieterceka123@gmail.com>

[1]:
https://docs.gocd.org/current/integration/#integration-with-bug-tracking-and-story-management-tools
[2]:
https://github.com/getsentry/gocd-webhook-notification-plugin/releases/tag/v0.0.6
2024-11-07 10:25:29 -08:00
Prakhar Pratyush 86a909e703 users: Add `savepoint=False` to avoid creating savepoints.
'do_deactivate_user' is used inside an outer db transaction
created in 'sync_user_from_ldap'.

`transaction.atomic()` block in 'do_deactivate_user' resulted
in savepoint creation.

This commit adds `savepoint=False` to avoid that.
2024-11-05 17:58:47 -08:00
Prakhar Pratyush 27eeb08459 streams: Add `savepoint=False` to avoid creating savepoints.
'bulk_remove_subscriptions' is used inside an outer db transaction
created in 'do_change_bot_owner'.

`transaction.atomic()` block in 'bulk_remove_subscriptions'
resulted in savepoint creation.

This commit adds `savepoint=False` to avoid that.
2024-11-05 17:58:47 -08:00
Prakhar Pratyush 8c8cc80183 create_user: Add `savepoint=False` to avoid creating savepoints.
'do_activate_mirror_dummy_user' is used inside an outer db
transaction created in 'registration_helper'.

`transaction.atomic()` block in 'do_activate_mirror_dummy_user'
resulted in savepoint creation.

This commit adds `savepoint=False` to avoid that.
2024-11-05 17:58:47 -08:00
Prakhar Pratyush ca4760a04c recipients: Add `savepoint=False` to avoid creating savepoints.
'get_or_create_direct_message_group' is used inside an outer
db transaction created in 'edit_scheduled_message'.

`transaction.atomic()` block in 'get_or_create_direct_message_group'
resulted in savepoint creation.

This commit adds `savepoint=False` to avoid that.
2024-11-05 17:58:47 -08:00
Prakhar Pratyush 0e67e4f1a1 compose_views: Add `savepoint=False` to avoid creating savepoints.
'compose_views' is used inside an outer db transaction created in
'update_user_group_backend'.

`transaction.atomic()` block in 'compose_views' resulted in
savepoint creation.

This commit adds `savepoint=False` to avoid that.
2024-11-05 17:58:47 -08:00