actions: Split out zerver.actions.alert_words.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-04-14 14:35:09 -07:00
parent 1ac7496855
commit 241463e215
8 changed files with 27 additions and 27 deletions

View File

@ -0,0 +1,20 @@
from typing import Iterable, Sequence
from zerver.lib.alert_words import add_user_alert_words, remove_user_alert_words
from zerver.models import UserProfile
from zerver.tornado.django_api import send_event
def notify_alert_words(user_profile: UserProfile, words: Sequence[str]) -> None:
event = dict(type="alert_words", alert_words=words)
send_event(user_profile.realm, event, [user_profile.id])
def do_add_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
words = add_user_alert_words(user_profile, alert_words)
notify_alert_words(user_profile, words)
def do_remove_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
words = remove_user_alert_words(user_profile, alert_words)
notify_alert_words(user_profile, words)

View File

@ -60,11 +60,7 @@ from zerver.actions.user_groups import (
from zerver.decorator import statsd_increment from zerver.decorator import statsd_increment
from zerver.lib import retention as retention from zerver.lib import retention as retention
from zerver.lib.addressee import Addressee from zerver.lib.addressee import Addressee
from zerver.lib.alert_words import ( from zerver.lib.alert_words import get_alert_word_automaton
add_user_alert_words,
get_alert_word_automaton,
remove_user_alert_words,
)
from zerver.lib.avatar import avatar_url, avatar_url_from_dict from zerver.lib.avatar import avatar_url, avatar_url_from_dict
from zerver.lib.bot_config import ConfigError, get_bot_config, get_bot_configs, set_bot_config from zerver.lib.bot_config import ConfigError, get_bot_config, get_bot_configs, set_bot_config
from zerver.lib.bulk_create import bulk_create_users from zerver.lib.bulk_create import bulk_create_users
@ -7454,21 +7450,6 @@ def do_remove_realm_emoji(realm: Realm, name: str) -> None:
notify_realm_emoji(realm) notify_realm_emoji(realm)
def notify_alert_words(user_profile: UserProfile, words: Sequence[str]) -> None:
event = dict(type="alert_words", alert_words=words)
send_event(user_profile.realm, event, [user_profile.id])
def do_add_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
words = add_user_alert_words(user_profile, alert_words)
notify_alert_words(user_profile, words)
def do_remove_alert_words(user_profile: UserProfile, alert_words: Iterable[str]) -> None:
words = remove_user_alert_words(user_profile, alert_words)
notify_alert_words(user_profile, words)
def do_mute_topic( def do_mute_topic(
user_profile: UserProfile, user_profile: UserProfile,
stream: Stream, stream: Stream,

View File

@ -1,6 +1,6 @@
import orjson import orjson
from zerver.lib.actions import do_add_alert_words, do_remove_alert_words from zerver.actions.alert_words import do_add_alert_words, do_remove_alert_words
from zerver.lib.alert_words import alert_words_in_realm, user_alert_words from zerver.lib.alert_words import alert_words_in_realm, user_alert_words
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import most_recent_message, most_recent_usermessage from zerver.lib.test_helpers import most_recent_message, most_recent_usermessage

View File

@ -13,6 +13,7 @@ from unittest import mock
import orjson import orjson
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from zerver.actions.alert_words import do_add_alert_words, do_remove_alert_words
from zerver.actions.default_streams import ( from zerver.actions.default_streams import (
do_add_default_stream, do_add_default_stream,
do_add_streams_to_default_stream_group, do_add_streams_to_default_stream_group,
@ -46,7 +47,6 @@ from zerver.lib.actions import (
bulk_add_subscriptions, bulk_add_subscriptions,
bulk_remove_subscriptions, bulk_remove_subscriptions,
check_add_realm_emoji, check_add_realm_emoji,
do_add_alert_words,
do_add_reaction, do_add_reaction,
do_add_realm_domain, do_add_realm_domain,
do_change_avatar_fields, do_change_avatar_fields,
@ -79,7 +79,6 @@ from zerver.lib.actions import (
do_mute_user, do_mute_user,
do_reactivate_user, do_reactivate_user,
do_regenerate_api_key, do_regenerate_api_key,
do_remove_alert_words,
do_remove_reaction, do_remove_reaction,
do_remove_realm_custom_profile_field, do_remove_realm_custom_profile_field,
do_remove_realm_domain, do_remove_realm_domain,

View File

@ -10,11 +10,11 @@ from django.db.models import Q
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from analytics.models import UserCount from analytics.models import UserCount
from zerver.actions.alert_words import do_add_alert_words
from zerver.lib import upload from zerver.lib import upload
from zerver.lib.actions import ( from zerver.lib.actions import (
check_add_reaction, check_add_reaction,
check_add_realm_emoji, check_add_realm_emoji,
do_add_alert_words,
do_add_reaction, do_add_reaction,
do_change_icon_source, do_change_icon_source,
do_change_logo_source, do_change_logo_source,

View File

@ -10,9 +10,9 @@ from django.conf import settings
from django.test import override_settings from django.test import override_settings
from markdown import Markdown from markdown import Markdown
from zerver.actions.alert_words import do_add_alert_words
from zerver.lib.actions import ( from zerver.lib.actions import (
change_user_is_active, change_user_is_active,
do_add_alert_words,
do_change_user_setting, do_change_user_setting,
do_create_realm, do_create_realm,
do_remove_realm_emoji, do_remove_realm_emoji,

View File

@ -3,7 +3,7 @@ from unittest import mock
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from zerver.lib.actions import do_add_alert_words from zerver.actions.alert_words import do_add_alert_words
from zerver.lib.soft_deactivation import ( from zerver.lib.soft_deactivation import (
add_missing_messages, add_missing_messages,
do_auto_soft_deactivate_users, do_auto_soft_deactivate_users,

View File

@ -2,7 +2,7 @@ from typing import List
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import do_add_alert_words, do_remove_alert_words from zerver.actions.alert_words import do_add_alert_words, do_remove_alert_words
from zerver.lib.alert_words import user_alert_words from zerver.lib.alert_words import user_alert_words
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success