2022-04-11 19:26:16 +02:00
|
|
|
from typing import Any, Dict, List, Optional, Union
|
2020-06-11 00:54:34 +02:00
|
|
|
|
|
|
|
from django.core.exceptions import ValidationError
|
2016-07-26 23:16:20 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2018-11-12 14:15:49 +01:00
|
|
|
from django.shortcuts import render
|
2021-04-16 00:57:30 +02:00
|
|
|
from django.utils.translation import gettext as _
|
2019-08-12 05:44:35 +02:00
|
|
|
from django.views.decorators.http import require_safe
|
2018-01-25 19:08:40 +01:00
|
|
|
|
2022-11-17 09:30:48 +01:00
|
|
|
from confirmation.models import Confirmation, ConfirmationKeyError, get_object_from_key
|
2022-04-14 23:58:15 +02:00
|
|
|
from zerver.actions.create_realm import do_change_realm_subdomain
|
2022-04-14 23:57:15 +02:00
|
|
|
from zerver.actions.realm_settings import (
|
2022-04-11 19:26:16 +02:00
|
|
|
do_change_realm_org_type,
|
2020-06-11 00:54:34 +02:00
|
|
|
do_deactivate_realm,
|
|
|
|
do_reactivate_realm,
|
2017-03-21 18:08:40 +01:00
|
|
|
do_set_realm_authentication_methods,
|
2017-06-09 20:50:38 +02:00
|
|
|
do_set_realm_notifications_stream,
|
2017-03-21 18:08:40 +01:00
|
|
|
do_set_realm_property,
|
2020-06-11 00:54:34 +02:00
|
|
|
do_set_realm_signup_notifications_stream,
|
2021-07-21 13:23:23 +02:00
|
|
|
do_set_realm_user_default_setting,
|
2016-07-26 23:16:20 +02:00
|
|
|
)
|
2022-04-14 23:57:15 +02:00
|
|
|
from zerver.decorator import require_realm_admin, require_realm_owner
|
|
|
|
from zerver.forms import check_subdomain_available as check_subdomain
|
2022-11-17 09:30:48 +01:00
|
|
|
from zerver.lib.exceptions import JsonableError, OrganizationOwnerRequiredError
|
2016-08-04 17:32:41 +02:00
|
|
|
from zerver.lib.i18n import get_available_language_codes
|
2022-04-12 13:13:02 +02:00
|
|
|
from zerver.lib.message import parse_message_content_edit_or_delete_limit
|
2021-07-16 22:11:10 +02:00
|
|
|
from zerver.lib.request import REQ, has_request_variables
|
2021-06-30 18:35:50 +02:00
|
|
|
from zerver.lib.response import json_success
|
2020-06-21 11:14:35 +02:00
|
|
|
from zerver.lib.retention import parse_message_retention_days
|
2017-06-09 20:50:38 +02:00
|
|
|
from zerver.lib.streams import access_stream_by_id
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.validator import (
|
|
|
|
check_bool,
|
2021-04-07 22:00:40 +02:00
|
|
|
check_capped_string,
|
2020-06-11 00:54:34 +02:00
|
|
|
check_dict,
|
|
|
|
check_int,
|
|
|
|
check_int_in,
|
2021-07-21 13:23:23 +02:00
|
|
|
check_string_in,
|
2020-06-21 11:14:35 +02:00
|
|
|
check_string_or_int,
|
2020-06-11 00:54:34 +02:00
|
|
|
to_non_negative_int,
|
|
|
|
)
|
2022-07-26 15:48:26 +02:00
|
|
|
from zerver.models import Realm, RealmReactivationStatus, RealmUserDefault, UserProfile
|
2021-09-09 20:19:08 +02:00
|
|
|
from zerver.views.user_settings import check_settings_values
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2022-04-11 19:26:16 +02:00
|
|
|
ORG_TYPE_IDS: List[int] = [t["id"] for t in Realm.ORG_TYPES.values()]
|
|
|
|
|
2017-03-21 18:08:40 +01:00
|
|
|
|
2016-07-26 23:16:20 +02:00
|
|
|
@require_realm_admin
|
|
|
|
@has_request_variables
|
2017-12-06 12:25:18 +01:00
|
|
|
def update_realm(
|
2021-02-12 08:19:30 +01:00
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
2021-04-07 22:00:40 +02:00
|
|
|
name: Optional[str] = REQ(
|
|
|
|
str_validator=check_capped_string(Realm.MAX_REALM_NAME_LENGTH), default=None
|
|
|
|
),
|
|
|
|
description: Optional[str] = REQ(
|
|
|
|
str_validator=check_capped_string(Realm.MAX_REALM_DESCRIPTION_LENGTH), default=None
|
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
emails_restricted_to_domains: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
disallow_disposable_email_addresses: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
invite_required: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-04-02 18:47:08 +02:00
|
|
|
invite_to_realm_policy: Optional[int] = REQ(
|
2021-07-18 10:11:58 +02:00
|
|
|
json_validator=check_int_in(Realm.INVITE_TO_REALM_POLICY_TYPES), default=None
|
2021-04-02 18:47:08 +02:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
name_changes_disabled: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
email_changes_disabled: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
avatar_changes_disabled: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
inline_image_preview: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
inline_url_embed_preview: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-05-04 19:02:24 +02:00
|
|
|
add_custom_emoji_policy: Optional[int] = REQ(
|
2021-05-17 15:40:28 +02:00
|
|
|
json_validator=check_int_in(Realm.COMMON_POLICY_TYPES), default=None
|
2021-05-04 19:02:24 +02:00
|
|
|
),
|
2021-06-08 13:45:14 +02:00
|
|
|
delete_own_message_policy: Optional[int] = REQ(
|
2021-06-21 18:52:51 +02:00
|
|
|
json_validator=check_int_in(Realm.COMMON_MESSAGE_POLICY_TYPES), default=None
|
2021-06-08 13:45:14 +02:00
|
|
|
),
|
2021-06-14 18:49:28 +02:00
|
|
|
message_content_delete_limit_seconds_raw: Optional[Union[int, str]] = REQ(
|
|
|
|
"message_content_delete_limit_seconds", json_validator=check_string_or_int, default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
allow_message_editing: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-05-26 12:21:37 +02:00
|
|
|
edit_topic_policy: Optional[int] = REQ(
|
2022-09-28 16:30:10 +02:00
|
|
|
json_validator=check_int_in(Realm.EDIT_TOPIC_POLICY_TYPES), default=None
|
2021-05-26 12:21:37 +02:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2022-04-12 13:13:02 +02:00
|
|
|
message_content_edit_limit_seconds_raw: Optional[Union[int, str]] = REQ(
|
|
|
|
"message_content_edit_limit_seconds", json_validator=check_string_or_int, default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
allow_edit_history: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-04-07 22:00:40 +02:00
|
|
|
default_language: Optional[str] = REQ(default=None),
|
2021-02-12 08:19:30 +01:00
|
|
|
waiting_period_threshold: Optional[int] = REQ(converter=to_non_negative_int, default=None),
|
2021-04-07 22:00:44 +02:00
|
|
|
authentication_methods: Optional[Dict[str, Any]] = REQ(
|
|
|
|
json_validator=check_dict([]), default=None
|
|
|
|
),
|
|
|
|
notifications_stream_id: Optional[int] = REQ(json_validator=check_int, default=None),
|
|
|
|
signup_notifications_stream_id: Optional[int] = REQ(json_validator=check_int, default=None),
|
2021-02-12 08:19:30 +01:00
|
|
|
message_retention_days_raw: Optional[Union[int, str]] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
"message_retention_days", json_validator=check_string_or_int, default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
send_welcome_emails: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
digest_emails_enabled: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-02-12 08:19:30 +01:00
|
|
|
message_content_allowed_in_email_notifications: Optional[bool] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_bool, default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
|
|
|
bot_creation_policy: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.BOT_CREATION_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-03-27 05:48:37 +01:00
|
|
|
create_public_stream_policy: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(Realm.COMMON_POLICY_TYPES), default=None
|
|
|
|
),
|
|
|
|
create_private_stream_policy: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.COMMON_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-10-04 08:33:31 +02:00
|
|
|
create_web_public_stream_policy: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(Realm.CREATE_WEB_PUBLIC_STREAM_POLICY_TYPES), default=None
|
|
|
|
),
|
2021-02-12 08:19:30 +01:00
|
|
|
invite_to_stream_policy: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.COMMON_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-04-08 19:24:01 +02:00
|
|
|
move_messages_between_streams_policy: Optional[int] = REQ(
|
2022-09-29 09:03:12 +02:00
|
|
|
json_validator=check_int_in(Realm.MOVE_MESSAGES_BETWEEN_STREAMS_POLICY_TYPES), default=None
|
2021-04-08 19:24:01 +02:00
|
|
|
),
|
2021-02-12 08:19:30 +01:00
|
|
|
user_group_edit_policy: Optional[int] = REQ(
|
2021-05-21 07:02:43 +02:00
|
|
|
json_validator=check_int_in(Realm.COMMON_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
|
|
|
private_message_policy: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.PRIVATE_MESSAGE_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
|
|
|
wildcard_mention_policy: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.WILDCARD_MENTION_POLICY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
|
|
|
email_address_visibility: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.EMAIL_ADDRESS_VISIBILITY_TYPES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-04-07 22:00:44 +02:00
|
|
|
video_chat_provider: Optional[int] = REQ(json_validator=check_int, default=None),
|
2021-03-31 13:10:46 +02:00
|
|
|
giphy_rating: Optional[int] = REQ(json_validator=check_int, default=None),
|
2021-04-07 22:00:40 +02:00
|
|
|
default_code_block_language: Optional[str] = REQ(default=None),
|
2021-02-12 08:19:30 +01:00
|
|
|
digest_weekday: Optional[int] = REQ(
|
2021-04-07 22:00:44 +02:00
|
|
|
json_validator=check_int_in(Realm.DIGEST_WEEKDAY_VALUES), default=None
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-09-13 20:01:35 +02:00
|
|
|
string_id: Optional[str] = REQ(
|
|
|
|
str_validator=check_capped_string(Realm.MAX_REALM_SUBDOMAIN_LENGTH),
|
|
|
|
default=None,
|
|
|
|
),
|
2022-04-11 19:26:16 +02:00
|
|
|
org_type: Optional[int] = REQ(json_validator=check_int_in(ORG_TYPE_IDS), default=None),
|
2021-10-03 14:16:07 +02:00
|
|
|
enable_spectator_access: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2022-04-22 18:45:30 +02:00
|
|
|
want_advertise_in_communities_directory: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
2022-08-04 11:43:59 +02:00
|
|
|
enable_read_receipts: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2017-12-06 12:25:18 +01:00
|
|
|
) -> HttpResponse:
|
2017-04-16 17:30:49 +02:00
|
|
|
realm = user_profile.realm
|
|
|
|
|
|
|
|
# Additional validation/error checking beyond types go here, so
|
|
|
|
# the entire request can succeed or fail atomically.
|
2016-08-04 17:32:41 +02:00
|
|
|
if default_language is not None and default_language not in get_available_language_codes():
|
2020-06-15 23:22:24 +02:00
|
|
|
raise JsonableError(_("Invalid language '{}'").format(default_language))
|
2020-06-11 16:24:15 +02:00
|
|
|
if authentication_methods is not None:
|
|
|
|
if not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2020-06-11 16:24:15 +02:00
|
|
|
if True not in list(authentication_methods.values()):
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(_("At least one authentication method must be enabled."))
|
2021-02-12 08:19:30 +01:00
|
|
|
if video_chat_provider is not None and video_chat_provider not in {
|
2021-02-12 08:20:45 +01:00
|
|
|
p["id"] for p in Realm.VIDEO_CHAT_PROVIDERS.values()
|
2021-02-12 08:19:30 +01:00
|
|
|
}:
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(_("Invalid video_chat_provider {}").format(video_chat_provider))
|
2021-03-31 13:10:46 +02:00
|
|
|
if giphy_rating is not None and giphy_rating not in {
|
|
|
|
p["id"] for p in Realm.GIPHY_RATING_OPTIONS.values()
|
|
|
|
}:
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(_("Invalid giphy_rating {}").format(giphy_rating))
|
2017-04-16 17:30:49 +02:00
|
|
|
|
2020-06-24 19:59:36 +02:00
|
|
|
message_retention_days: Optional[int] = None
|
|
|
|
if message_retention_days_raw is not None:
|
2020-06-11 21:16:53 +02:00
|
|
|
if not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2020-05-19 14:38:43 +02:00
|
|
|
realm.ensure_not_on_limited_plan()
|
2020-06-21 11:14:35 +02:00
|
|
|
message_retention_days = parse_message_retention_days(
|
2021-02-12 08:19:30 +01:00
|
|
|
message_retention_days_raw, Realm.MESSAGE_RETENTION_SPECIAL_VALUES_MAP
|
|
|
|
)
|
2022-10-30 00:07:03 +02:00
|
|
|
message_retention_days # used by locals() below
|
2020-05-09 19:46:56 +02:00
|
|
|
|
2021-07-28 18:23:39 +02:00
|
|
|
if (
|
|
|
|
invite_to_realm_policy is not None or invite_required is not None
|
|
|
|
) and not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2021-07-19 11:47:42 +02:00
|
|
|
|
2021-07-28 18:43:09 +02:00
|
|
|
if (
|
|
|
|
emails_restricted_to_domains is not None or disallow_disposable_email_addresses is not None
|
|
|
|
) and not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2021-07-28 18:43:09 +02:00
|
|
|
|
2021-07-29 09:57:58 +02:00
|
|
|
if waiting_period_threshold is not None and not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2021-07-29 09:57:58 +02:00
|
|
|
|
2022-08-03 12:24:39 +02:00
|
|
|
if enable_spectator_access:
|
|
|
|
realm.ensure_not_on_limited_plan()
|
|
|
|
|
2021-06-14 18:49:28 +02:00
|
|
|
data: Dict[str, Any] = {}
|
|
|
|
|
|
|
|
message_content_delete_limit_seconds: Optional[int] = None
|
|
|
|
if message_content_delete_limit_seconds_raw is not None:
|
2022-04-12 13:13:02 +02:00
|
|
|
message_content_delete_limit_seconds = parse_message_content_edit_or_delete_limit(
|
2021-06-14 18:49:28 +02:00
|
|
|
message_content_delete_limit_seconds_raw,
|
2022-04-12 13:13:02 +02:00
|
|
|
Realm.MESSAGE_CONTENT_EDIT_OR_DELETE_LIMIT_SPECIAL_VALUES_MAP,
|
|
|
|
setting_name="message_content_delete_limit_seconds",
|
2021-06-14 18:49:28 +02:00
|
|
|
)
|
2022-04-13 19:05:15 +02:00
|
|
|
if (
|
|
|
|
message_content_delete_limit_seconds is None
|
|
|
|
and realm.message_content_delete_limit_seconds is not None
|
|
|
|
):
|
|
|
|
# We handle 'None' here separately, since in the loop below,
|
|
|
|
# do_set_realm_property is called only if setting value is
|
|
|
|
# not None.
|
|
|
|
do_set_realm_property(
|
|
|
|
realm,
|
|
|
|
"message_content_delete_limit_seconds",
|
|
|
|
message_content_delete_limit_seconds,
|
|
|
|
acting_user=user_profile,
|
|
|
|
)
|
|
|
|
data["message_content_delete_limit_seconds"] = message_content_delete_limit_seconds
|
2021-06-14 18:49:28 +02:00
|
|
|
|
2022-09-22 10:53:37 +02:00
|
|
|
message_content_edit_limit_seconds: Optional[int] = None
|
|
|
|
if message_content_edit_limit_seconds_raw is not None:
|
|
|
|
message_content_edit_limit_seconds = parse_message_content_edit_or_delete_limit(
|
|
|
|
message_content_edit_limit_seconds_raw,
|
|
|
|
Realm.MESSAGE_CONTENT_EDIT_OR_DELETE_LIMIT_SPECIAL_VALUES_MAP,
|
|
|
|
setting_name="message_content_edit_limit_seconds",
|
|
|
|
)
|
|
|
|
|
|
|
|
if (
|
|
|
|
message_content_edit_limit_seconds is None
|
|
|
|
and realm.message_content_edit_limit_seconds is not None
|
|
|
|
):
|
|
|
|
# We handle 'None' here separately, since in the loop below,
|
|
|
|
# do_set_realm_property is called only if setting value is
|
|
|
|
# not None.
|
|
|
|
do_set_realm_property(
|
|
|
|
realm,
|
|
|
|
"message_content_edit_limit_seconds",
|
|
|
|
message_content_edit_limit_seconds,
|
|
|
|
acting_user=user_profile,
|
|
|
|
)
|
|
|
|
data["message_content_edit_limit_seconds"] = message_content_edit_limit_seconds
|
|
|
|
|
2017-04-16 17:30:49 +02:00
|
|
|
# The user of `locals()` here is a bit of a code smell, but it's
|
|
|
|
# restricted to the elements present in realm.property_types.
|
|
|
|
#
|
|
|
|
# TODO: It should be possible to deduplicate this function up
|
|
|
|
# further by some more advanced usage of the
|
|
|
|
# `REQ/has_request_variables` extraction.
|
|
|
|
req_vars = {k: v for k, v in list(locals().items()) if k in realm.property_types}
|
|
|
|
|
|
|
|
for k, v in list(req_vars.items()):
|
2017-04-19 05:49:53 +02:00
|
|
|
if v is not None and getattr(realm, k) != v:
|
2020-06-29 15:34:19 +02:00
|
|
|
do_set_realm_property(realm, k, v, acting_user=user_profile)
|
2018-04-24 03:47:28 +02:00
|
|
|
if isinstance(v, str):
|
2021-02-12 08:20:45 +01:00
|
|
|
data[k] = "updated"
|
2017-04-16 17:30:49 +02:00
|
|
|
else:
|
|
|
|
data[k] = v
|
|
|
|
|
|
|
|
# The following realm properties do not fit the pattern above
|
2017-04-19 05:49:53 +02:00
|
|
|
# authentication_methods is not supported by the do_set_realm_property
|
|
|
|
# framework because of its bitfield.
|
2021-02-12 08:19:30 +01:00
|
|
|
if authentication_methods is not None and (
|
|
|
|
realm.authentication_methods_dict() != authentication_methods
|
|
|
|
):
|
2020-07-02 14:03:43 +02:00
|
|
|
do_set_realm_authentication_methods(realm, authentication_methods, acting_user=user_profile)
|
2021-02-12 08:20:45 +01:00
|
|
|
data["authentication_methods"] = authentication_methods
|
2022-04-12 13:13:02 +02:00
|
|
|
|
2017-10-20 16:55:04 +02:00
|
|
|
# Realm.notifications_stream and Realm.signup_notifications_stream are not boolean,
|
2018-04-24 03:47:28 +02:00
|
|
|
# str or integer field, and thus doesn't fit into the do_set_realm_property framework.
|
2017-06-09 20:50:38 +02:00
|
|
|
if notifications_stream_id is not None:
|
2021-02-12 08:19:30 +01:00
|
|
|
if realm.notifications_stream is None or (
|
|
|
|
realm.notifications_stream.id != notifications_stream_id
|
|
|
|
):
|
2017-06-09 20:50:38 +02:00
|
|
|
new_notifications_stream = None
|
|
|
|
if notifications_stream_id >= 0:
|
2020-10-16 17:25:48 +02:00
|
|
|
(new_notifications_stream, sub) = access_stream_by_id(
|
2021-02-12 08:19:30 +01:00
|
|
|
user_profile, notifications_stream_id
|
|
|
|
)
|
|
|
|
do_set_realm_notifications_stream(
|
|
|
|
realm, new_notifications_stream, notifications_stream_id, acting_user=user_profile
|
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
data["notifications_stream_id"] = notifications_stream_id
|
2017-06-09 20:50:38 +02:00
|
|
|
|
2017-10-20 16:55:04 +02:00
|
|
|
if signup_notifications_stream_id is not None:
|
2021-02-12 08:19:30 +01:00
|
|
|
if realm.signup_notifications_stream is None or (
|
|
|
|
realm.signup_notifications_stream.id != signup_notifications_stream_id
|
|
|
|
):
|
2017-10-20 16:55:04 +02:00
|
|
|
new_signup_notifications_stream = None
|
|
|
|
if signup_notifications_stream_id >= 0:
|
2020-10-16 17:25:48 +02:00
|
|
|
(new_signup_notifications_stream, sub) = access_stream_by_id(
|
2021-02-12 08:19:30 +01:00
|
|
|
user_profile, signup_notifications_stream_id
|
|
|
|
)
|
|
|
|
do_set_realm_signup_notifications_stream(
|
|
|
|
realm,
|
|
|
|
new_signup_notifications_stream,
|
|
|
|
signup_notifications_stream_id,
|
|
|
|
acting_user=user_profile,
|
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
data["signup_notifications_stream_id"] = signup_notifications_stream_id
|
2017-10-20 16:55:04 +02:00
|
|
|
|
2020-03-31 15:21:27 +02:00
|
|
|
if default_code_block_language is not None:
|
|
|
|
# Migrate '', used in the API to encode the default/None behavior of this feature.
|
2021-02-12 08:20:45 +01:00
|
|
|
if default_code_block_language == "":
|
|
|
|
data["default_code_block_language"] = None
|
2020-03-31 15:21:27 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
data["default_code_block_language"] = default_code_block_language
|
2020-03-31 15:21:27 +02:00
|
|
|
|
2021-09-13 20:01:35 +02:00
|
|
|
if string_id is not None:
|
|
|
|
if not user_profile.is_realm_owner:
|
2022-11-17 09:30:48 +01:00
|
|
|
raise OrganizationOwnerRequiredError()
|
2021-09-13 20:01:35 +02:00
|
|
|
|
|
|
|
if realm.demo_organization_scheduled_deletion_date is None:
|
|
|
|
raise JsonableError(_("Must be a demo organization."))
|
|
|
|
|
|
|
|
try:
|
|
|
|
check_subdomain(string_id)
|
|
|
|
except ValidationError as err:
|
|
|
|
raise JsonableError(str(err.message))
|
|
|
|
|
|
|
|
do_change_realm_subdomain(realm, string_id, acting_user=user_profile)
|
|
|
|
data["realm_uri"] = realm.uri
|
|
|
|
|
2022-04-11 19:26:16 +02:00
|
|
|
if org_type is not None:
|
|
|
|
do_change_realm_org_type(realm, org_type, acting_user=user_profile)
|
|
|
|
data["org_type"] = org_type
|
|
|
|
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request, data)
|
2018-01-30 14:58:50 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-06-11 00:26:49 +02:00
|
|
|
@require_realm_owner
|
2018-01-30 14:58:50 +01:00
|
|
|
@has_request_variables
|
2019-05-08 05:59:04 +02:00
|
|
|
def deactivate_realm(request: HttpRequest, user: UserProfile) -> HttpResponse:
|
|
|
|
realm = user.realm
|
2021-04-02 17:11:25 +02:00
|
|
|
do_deactivate_realm(realm, acting_user=user)
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|
2018-01-25 19:08:40 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-08-12 05:44:35 +02:00
|
|
|
@require_safe
|
2018-04-24 03:47:28 +02:00
|
|
|
def check_subdomain_available(request: HttpRequest, subdomain: str) -> HttpResponse:
|
2018-01-25 19:08:40 +01:00
|
|
|
try:
|
|
|
|
check_subdomain(subdomain)
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request, data={"msg": "available"})
|
2018-01-25 19:08:40 +01:00
|
|
|
except ValidationError as e:
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request, data={"msg": e.message})
|
2018-11-12 14:15:49 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-11-12 14:15:49 +01:00
|
|
|
def realm_reactivation(request: HttpRequest, confirmation_key: str) -> HttpResponse:
|
|
|
|
try:
|
2022-07-26 15:48:26 +02:00
|
|
|
obj = get_object_from_key(
|
|
|
|
confirmation_key, [Confirmation.REALM_REACTIVATION], mark_object_used=True
|
2022-07-19 21:13:32 +02:00
|
|
|
)
|
2022-11-17 09:30:48 +01:00
|
|
|
except ConfirmationKeyError:
|
2022-07-26 15:37:43 +02:00
|
|
|
return render(request, "zerver/realm_reactivation_link_error.html", status=404)
|
2022-07-26 15:48:26 +02:00
|
|
|
|
|
|
|
assert isinstance(obj, RealmReactivationStatus)
|
|
|
|
realm = obj.realm
|
|
|
|
|
2018-11-12 14:15:49 +01:00
|
|
|
do_reactivate_realm(realm)
|
2022-07-19 21:13:32 +02:00
|
|
|
|
2018-11-12 14:15:49 +01:00
|
|
|
context = {"realm": realm}
|
2021-02-12 08:20:45 +01:00
|
|
|
return render(request, "zerver/realm_reactivation.html", context)
|
2021-07-21 13:23:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
emojiset_choices = {emojiset["key"] for emojiset in RealmUserDefault.emojiset_choices()}
|
|
|
|
default_view_options = ["recent_topics", "all_messages"]
|
|
|
|
|
|
|
|
|
|
|
|
@require_realm_admin
|
|
|
|
@has_request_variables
|
|
|
|
def update_realm_user_settings_defaults(
|
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
|
|
|
dense_mode: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
starred_message_counts: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
fluid_layout_width: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
high_contrast_mode: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
color_scheme: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(UserProfile.COLOR_SCHEME_CHOICES), default=None
|
|
|
|
),
|
|
|
|
translate_emoticons: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2022-04-08 16:04:22 +02:00
|
|
|
display_emoji_reaction_users: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-07-21 13:23:23 +02:00
|
|
|
default_view: Optional[str] = REQ(
|
|
|
|
str_validator=check_string_in(default_view_options), default=None
|
|
|
|
),
|
2021-10-25 19:17:19 +02:00
|
|
|
escape_navigates_to_default_view: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-07-21 13:23:23 +02:00
|
|
|
left_side_userlist: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
emojiset: Optional[str] = REQ(str_validator=check_string_in(emojiset_choices), default=None),
|
|
|
|
demote_inactive_streams: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(UserProfile.DEMOTE_STREAMS_CHOICES), default=None
|
|
|
|
),
|
|
|
|
enable_stream_desktop_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
enable_stream_email_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
enable_stream_push_notifications: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enable_stream_audible_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
wildcard_mentions_notify: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
notification_sound: Optional[str] = REQ(default=None),
|
|
|
|
enable_desktop_notifications: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enable_sounds: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enable_offline_email_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
enable_offline_push_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
enable_online_push_notifications: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enable_digest_emails: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-09-28 10:03:43 +02:00
|
|
|
# enable_login_emails is not included here, because we don't want
|
|
|
|
# security-related settings to be controlled by organization administrators.
|
2021-07-21 13:23:23 +02:00
|
|
|
# enable_marketing_emails is not included here, since we don't at
|
|
|
|
# present allow organizations to customize this. (The user's selection
|
|
|
|
# in the signup form takes precedence over RealmUserDefault).
|
|
|
|
#
|
|
|
|
# We may want to change this model in the future, since some SSO signups
|
|
|
|
# do not offer an opportunity to prompt the user at all during signup.
|
|
|
|
message_content_in_email_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
pm_content_in_desktop_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
desktop_icon_count_display: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(UserProfile.DESKTOP_ICON_COUNT_DISPLAY_CHOICES), default=None
|
|
|
|
),
|
|
|
|
realm_name_in_notifications: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
presence_enabled: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enter_sends: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
enable_drafts_synchronization: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
|
|
|
email_notifications_batching_period_seconds: Optional[int] = REQ(
|
|
|
|
json_validator=check_int, default=None
|
|
|
|
),
|
2021-09-17 18:11:37 +02:00
|
|
|
twenty_four_hour_time: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-10-03 08:36:36 +02:00
|
|
|
send_stream_typing_notifications: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2021-10-03 08:53:35 +02:00
|
|
|
send_private_typing_notifications: Optional[bool] = REQ(
|
|
|
|
json_validator=check_bool, default=None
|
|
|
|
),
|
|
|
|
send_read_receipts: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
2022-08-12 22:41:06 +02:00
|
|
|
user_list_style: Optional[int] = REQ(
|
|
|
|
json_validator=check_int_in(UserProfile.USER_LIST_STYLE_CHOICES), default=None
|
|
|
|
),
|
2021-07-21 13:23:23 +02:00
|
|
|
) -> HttpResponse:
|
|
|
|
if notification_sound is not None or email_notifications_batching_period_seconds is not None:
|
|
|
|
check_settings_values(notification_sound, email_notifications_batching_period_seconds)
|
|
|
|
|
|
|
|
realm_user_default = RealmUserDefault.objects.get(realm=user_profile.realm)
|
|
|
|
request_settings = {
|
|
|
|
k: v for k, v in list(locals().items()) if (k in RealmUserDefault.property_types)
|
|
|
|
}
|
|
|
|
for k, v in list(request_settings.items()):
|
|
|
|
if v is not None and getattr(realm_user_default, k) != v:
|
|
|
|
do_set_realm_user_default_setting(realm_user_default, k, v, acting_user=user_profile)
|
|
|
|
|
|
|
|
# TODO: Extract `ignored_parameters_unsupported` to be a common feature of the REQ framework.
|
|
|
|
from zerver.lib.request import RequestNotes
|
|
|
|
|
|
|
|
request_notes = RequestNotes.get_notes(request)
|
|
|
|
for req_var in request.POST:
|
|
|
|
if req_var not in request_notes.processed_parameters:
|
|
|
|
request_notes.ignored_parameters.add(req_var)
|
|
|
|
|
|
|
|
result: Dict[str, Any] = {}
|
|
|
|
if len(request_notes.ignored_parameters) > 0:
|
|
|
|
result["ignored_parameters_unsupported"] = list(request_notes.ignored_parameters)
|
|
|
|
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request, data=result)
|