mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 07:52:19 +00:00
actions: Split out zerver.actions.realm_linkifiers.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 975f5a3c2d)
This commit is contained in:
committed by
Tim Abbott
parent
0cb261ac6b
commit
5cb7acec36
@@ -239,7 +239,6 @@ from zerver.models import (
|
||||
RealmAuditLog,
|
||||
RealmDomain,
|
||||
RealmEmoji,
|
||||
RealmFilter,
|
||||
RealmUserDefault,
|
||||
Recipient,
|
||||
ScheduledEmail,
|
||||
@@ -279,9 +278,7 @@ from zerver.models import (
|
||||
get_user_by_delivery_email,
|
||||
get_user_profile_by_id,
|
||||
is_cross_realm_bot_email,
|
||||
linkifiers_for_realm,
|
||||
query_for_ids,
|
||||
realm_filters_for_realm,
|
||||
validate_attachment_request,
|
||||
)
|
||||
from zerver.tornado.django_api import send_event
|
||||
@@ -7718,55 +7715,6 @@ def do_mark_hotspot_as_read(user: UserProfile, hotspot: str) -> None:
|
||||
send_event(user.realm, event, [user.id])
|
||||
|
||||
|
||||
def notify_linkifiers(realm: Realm) -> None:
|
||||
realm_linkifiers = linkifiers_for_realm(realm.id)
|
||||
event: Dict[str, object] = dict(type="realm_linkifiers", realm_linkifiers=realm_linkifiers)
|
||||
send_event(realm, event, active_user_ids(realm.id))
|
||||
|
||||
# Below is code for backwards compatibility. The now deprecated
|
||||
# "realm_filters" event-type is used by older clients, and uses
|
||||
# tuples.
|
||||
realm_filters = realm_filters_for_realm(realm.id)
|
||||
event = dict(type="realm_filters", realm_filters=realm_filters)
|
||||
send_event(realm, event, active_user_ids(realm.id))
|
||||
|
||||
|
||||
# NOTE: Regexes must be simple enough that they can be easily translated to JavaScript
|
||||
# RegExp syntax. In addition to JS-compatible syntax, the following features are available:
|
||||
# * Named groups will be converted to numbered groups automatically
|
||||
# * Inline-regex flags will be stripped, and where possible translated to RegExp-wide flags
|
||||
def do_add_linkifier(realm: Realm, pattern: str, url_format_string: str) -> int:
|
||||
pattern = pattern.strip()
|
||||
url_format_string = url_format_string.strip()
|
||||
linkifier = RealmFilter(realm=realm, pattern=pattern, url_format_string=url_format_string)
|
||||
linkifier.full_clean()
|
||||
linkifier.save()
|
||||
notify_linkifiers(realm)
|
||||
|
||||
return linkifier.id
|
||||
|
||||
|
||||
def do_remove_linkifier(
|
||||
realm: Realm, pattern: Optional[str] = None, id: Optional[int] = None
|
||||
) -> None:
|
||||
if pattern is not None:
|
||||
RealmFilter.objects.get(realm=realm, pattern=pattern).delete()
|
||||
else:
|
||||
RealmFilter.objects.get(realm=realm, id=id).delete()
|
||||
notify_linkifiers(realm)
|
||||
|
||||
|
||||
def do_update_linkifier(realm: Realm, id: int, pattern: str, url_format_string: str) -> None:
|
||||
pattern = pattern.strip()
|
||||
url_format_string = url_format_string.strip()
|
||||
linkifier = RealmFilter.objects.get(realm=realm, id=id)
|
||||
linkifier.pattern = pattern
|
||||
linkifier.url_format_string = url_format_string
|
||||
linkifier.full_clean()
|
||||
linkifier.save(update_fields=["pattern", "url_format_string"])
|
||||
notify_linkifiers(realm)
|
||||
|
||||
|
||||
@transaction.atomic(durable=True)
|
||||
def do_add_realm_domain(
|
||||
realm: Realm, domain: str, allow_subdomains: bool, *, acting_user: Optional[UserProfile]
|
||||
|
||||
Reference in New Issue
Block a user