diff --git a/frontend_tests/node_tests/message_edit.js b/frontend_tests/node_tests/message_edit.js
index 4bfcf6b925..95b1941f67 100644
--- a/frontend_tests/node_tests/message_edit.js
+++ b/frontend_tests/node_tests/message_edit.js
@@ -9,6 +9,7 @@ const {page_params} = require("../zjsunit/zpage_params");
page_params.realm_community_topic_editing_limit_seconds = 259200;
const message_edit = zrequire("message_edit");
+const settings_config = zrequire("settings_config");
const get_editability = message_edit.get_editability;
const editability_types = message_edit.editability_types;
@@ -81,7 +82,8 @@ run_test("get_editability", () => {
sent_by_me: false,
type: "stream",
};
- page_params.realm_allow_community_topic_editing = true;
+ page_params.realm_edit_topic_policy =
+ settings_config.common_message_policy_values.by_everyone.code;
page_params.realm_allow_message_editing = true;
page_params.realm_message_content_edit_limit_seconds = 0;
page_params.realm_community_topic_editing_limit_seconds = 259200;
@@ -93,15 +95,18 @@ run_test("get_editability", () => {
assert.equal(message_edit.is_topic_editable(message), true);
message.sent_by_me = true;
- page_params.realm_allow_community_topic_editing = false;
+ page_params.realm_edit_topic_policy =
+ settings_config.common_message_policy_values.by_admins_only.code;
assert.equal(message_edit.is_topic_editable(message), true);
message.sent_by_me = false;
- page_params.realm_allow_community_topic_editing = false;
+ page_params.realm_edit_topic_policy =
+ settings_config.common_message_policy_values.by_admins_only.code;
assert.equal(message_edit.is_topic_editable(message), false);
message.sent_by_me = false;
- page_params.realm_allow_community_topic_editing = false;
+ page_params.realm_edit_topic_policy =
+ settings_config.common_message_policy_values.by_admins_only.code;
page_params.is_admin = true;
assert.equal(message_edit.is_topic_editable(message), true);
diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js
index 093e0b97a3..63e82b7dd6 100644
--- a/frontend_tests/node_tests/settings_org.js
+++ b/frontend_tests/node_tests/settings_org.js
@@ -583,16 +583,16 @@ function test_discard_changes_button(discard_changes) {
};
page_params.realm_allow_edit_history = true;
- page_params.realm_allow_community_topic_editing = true;
+ page_params.realm_edit_topic_policy =
+ settings_config.common_message_policy_values.by_everyone.code;
page_params.realm_allow_message_editing = true;
page_params.realm_message_content_edit_limit_seconds = 3600;
page_params.realm_allow_message_deleting = true;
page_params.realm_message_content_delete_limit_seconds = 120;
const allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
- const allow_community_topic_editing = $("#id_realm_allow_community_topic_editing").prop(
- "checked",
- true,
+ const edit_topic_policy = $("#id_realm_edit_topic_policy").val(
+ settings_config.common_message_policy_values.by_admins_only.code,
);
const msg_edit_limit_setting = $("#id_realm_msg_edit_limit_setting").val("custom_limit");
const message_content_edit_limit_minutes = $(
@@ -606,7 +606,7 @@ function test_discard_changes_button(discard_changes) {
allow_edit_history.attr("id", "id_realm_allow_edit_history");
msg_edit_limit_setting.attr("id", "id_realm_msg_edit_limit_setting");
msg_delete_limit_setting.attr("id", "id_realm_msg_delete_limit_setting");
- allow_community_topic_editing.attr("id", "id_realm_allow_community_topic_editing");
+ edit_topic_policy.attr("id", "id_realm_edit_topic_policy");
message_content_edit_limit_minutes.attr("id", "id_realm_message_content_edit_limit_minutes");
message_content_delete_limit_minutes.attr(
"id",
@@ -618,7 +618,7 @@ function test_discard_changes_button(discard_changes) {
allow_edit_history,
msg_edit_limit_setting,
msg_delete_limit_setting,
- allow_community_topic_editing,
+ edit_topic_policy,
message_content_edit_limit_minutes,
message_content_delete_limit_minutes,
];
@@ -633,7 +633,10 @@ function test_discard_changes_button(discard_changes) {
discard_changes(ev);
assert.equal(allow_edit_history.prop("checked"), true);
- assert.equal(allow_community_topic_editing.prop("checked"), true);
+ assert.equal(
+ edit_topic_policy.val(),
+ settings_config.common_message_policy_values.by_everyone.code,
+ );
assert.equal(msg_edit_limit_setting.val(), "upto_one_hour");
assert.equal(message_content_edit_limit_minutes.val(), "60");
assert.equal(msg_delete_limit_setting.val(), "upto_two_min");
@@ -685,9 +688,6 @@ test("set_up", ({override}) => {
const waiting_period_parent_elem = $.create("waiting-period-parent-stub");
$("#id_realm_waiting_period_threshold").set_parent(waiting_period_parent_elem);
- const allow_topic_edit_label_parent = $.create("allow-topic-edit-label-parent");
- $("#id_realm_allow_community_topic_editing_label").set_parent(allow_topic_edit_label_parent);
-
// TEST set_up() here, but this mostly just allows us to
// get access to the click handlers.
override(settings_org, "maybe_disable_widgets", noop);
diff --git a/static/js/admin.js b/static/js/admin.js
index ba940b3fbc..1c7fefc45b 100644
--- a/static/js/admin.js
+++ b/static/js/admin.js
@@ -18,9 +18,6 @@ import * as settings_toggle from "./settings_toggle";
const admin_settings_label = {
// Organization settings
- realm_allow_community_topic_editing: $t({
- defaultMessage: "Users can edit the topic of any message",
- }),
realm_allow_edit_history: $t({defaultMessage: "Enable message edit history"}),
realm_mandatory_topics: $t({defaultMessage: "Require topics in stream messages"}),
realm_notifications_stream: $t({defaultMessage: "New stream notifications:"}),
@@ -82,7 +79,6 @@ export function build_page() {
realm_avatar_changes_disabled: page_params.realm_avatar_changes_disabled,
realm_add_emoji_by_admins_only: page_params.realm_add_emoji_by_admins_only,
can_add_emojis: settings_emoji.can_add_emoji(),
- realm_allow_community_topic_editing: page_params.realm_allow_community_topic_editing,
realm_message_content_edit_limit_minutes: settings_org.get_realm_time_limits_in_minutes(
"realm_message_content_edit_limit_seconds",
),
diff --git a/static/js/message_edit.js b/static/js/message_edit.js
index f95797d8a5..4e9e094405 100644
--- a/static/js/message_edit.js
+++ b/static/js/message_edit.js
@@ -24,6 +24,7 @@ import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as resize from "./resize";
import * as rows from "./rows";
+import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data";
import * as stream_bar from "./stream_bar";
import * as stream_data from "./stream_data";
@@ -68,7 +69,10 @@ export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
return true;
}
- if (!page_params.realm_allow_community_topic_editing) {
+ if (
+ page_params.realm_edit_topic_policy ===
+ settings_config.common_message_policy_values.by_admins_only.code
+ ) {
// If you're another non-admin user, you need community topic editing enabled.
return false;
}
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index 83e8afdb9b..4462fa0b16 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -179,7 +179,7 @@ export function dispatch_normal_event(event) {
allow_edit_history: noop,
allow_message_deleting: noop,
allow_message_editing: noop,
- allow_community_topic_editing: noop,
+ edit_topic_policy: noop,
user_group_edit_policy: noop,
avatar_changes_disabled: settings_account.update_avatar_change_display,
bot_creation_policy: settings_bots.update_bot_permissions_ui,
diff --git a/static/js/settings_config.js b/static/js/settings_config.js
index ed5578a393..6cd4f62b26 100644
--- a/static/js/settings_config.js
+++ b/static/js/settings_config.js
@@ -198,6 +198,19 @@ export const wildcard_mention_policy_values = {
},
};
+export const common_message_policy_values = {
+ by_everyone: {
+ order: 1,
+ code: 5,
+ description: $t({defaultMessage: "Admins, members and guests"}),
+ },
+ by_admins_only: {
+ order: 2,
+ code: 2,
+ description: $t({defaultMessage: "Admins only"}),
+ },
+};
+
const time_limit_dropdown_values = new Map([
[
"any_time",
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index c3566d79be..ea4e371570 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -104,6 +104,9 @@ export function get_organization_settings_options() {
options.wildcard_mention_policy_values = get_sorted_options_list(
settings_config.wildcard_mention_policy_values,
);
+ options.common_message_policy_values = get_sorted_options_list(
+ settings_config.common_message_policy_values,
+ );
return options;
}
@@ -207,6 +210,7 @@ const simple_dropdown_properties = [
"realm_invite_to_realm_policy",
"realm_wildcard_mention_policy",
"realm_move_messages_between_streams_policy",
+ "realm_edit_topic_policy",
];
function set_property_dropdown_value(property_name) {
@@ -248,11 +252,7 @@ function set_msg_edit_limit_dropdown() {
"id_realm_message_content_edit_limit_minutes",
value === "custom_limit",
);
- settings_ui.disable_sub_setting_onchange(
- value !== "never",
- "id_realm_allow_community_topic_editing",
- true,
- );
+ settings_ui.disable_sub_setting_onchange(value !== "never", "id_realm_edit_topic_policy", true);
}
function set_msg_delete_limit_dropdown() {
diff --git a/static/js/settings_ui.js b/static/js/settings_ui.js
index 10952281ee..91e96f7d65 100644
--- a/static/js/settings_ui.js
+++ b/static/js/settings_ui.js
@@ -76,13 +76,7 @@ export function do_settings_change(
export function disable_sub_setting_onchange(is_checked, sub_setting_id, disable_on_uncheck) {
if ((is_checked && disable_on_uncheck) || (!is_checked && !disable_on_uncheck)) {
$(`#${CSS.escape(sub_setting_id)}`).prop("disabled", false);
- $(`#${CSS.escape(sub_setting_id)}_label`)
- .parent()
- .removeClass("control-label-disabled");
} else if ((is_checked && !disable_on_uncheck) || (!is_checked && disable_on_uncheck)) {
$(`#${CSS.escape(sub_setting_id)}`).prop("disabled", true);
- $(`#${CSS.escape(sub_setting_id)}_label`)
- .parent()
- .addClass("control-label-disabled");
}
}
diff --git a/static/templates/settings/organization_permissions_admin.hbs b/static/templates/settings/organization_permissions_admin.hbs
index 87d9964a65..fcbdada2bb 100644
--- a/static/templates/settings/organization_permissions_admin.hbs
+++ b/static/templates/settings/organization_permissions_admin.hbs
@@ -143,11 +143,12 @@
- {{> settings_checkbox
- setting_name="realm_allow_community_topic_editing"
- prefix="id_"
- is_checked=realm_allow_community_topic_editing
- label=admin_settings_label.realm_allow_community_topic_editing}}
+
+
+
+
{{> settings_checkbox
setting_name="realm_allow_edit_history"
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index f669059a8e..e3e8bd02a1 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -11,6 +11,11 @@ below features are supported.
## Changes in Zulip 5.0
+**Feature level 75**
+
+* [`POST /register`](/api/register-queue), `PATCH /realm`: Replaced `allow_community_topic_editing`
+ field with an integer field `edit_topic_policy`.
+
**Feature level 74**
* [`POST /register`](/api/register-queue): Added `server_needs_upgrade`
diff --git a/version.py b/version.py
index 183e0a4328..a4614dea0e 100644
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3"
# Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md, as well as
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 74
+API_FEATURE_LEVEL = 75
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index fb1bc0be54..f327a850e1 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -874,25 +874,25 @@ def do_set_realm_message_editing(
realm: Realm,
allow_message_editing: bool,
message_content_edit_limit_seconds: int,
- allow_community_topic_editing: bool,
+ edit_topic_policy: int,
*,
acting_user: Optional[UserProfile],
) -> None:
old_values = dict(
allow_message_editing=realm.allow_message_editing,
message_content_edit_limit_seconds=realm.message_content_edit_limit_seconds,
- allow_community_topic_editing=realm.allow_community_topic_editing,
+ edit_topic_policy=realm.edit_topic_policy,
)
realm.allow_message_editing = allow_message_editing
realm.message_content_edit_limit_seconds = message_content_edit_limit_seconds
- realm.allow_community_topic_editing = allow_community_topic_editing
+ realm.edit_topic_policy = edit_topic_policy
event_time = timezone_now()
updated_properties = dict(
allow_message_editing=allow_message_editing,
message_content_edit_limit_seconds=message_content_edit_limit_seconds,
- allow_community_topic_editing=allow_community_topic_editing,
+ edit_topic_policy=edit_topic_policy,
)
for updated_property, updated_value in updated_properties.items():
@@ -2823,8 +2823,8 @@ def can_edit_content_or_topic(
if user_profile.is_realm_admin:
return True
- # The community_topic_editing setting controls normal users editing topics.
- if user_profile.realm.allow_community_topic_editing:
+ # The edit_topic_policy setting controls which users can edit topics.
+ if user_profile.realm.edit_topic_policy == Realm.POLICY_EVERYONE:
return True
return False
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index 6df982bb01..6ac4fa9247 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -931,7 +931,7 @@ message_edit_data = DictType(
required_keys=[
("allow_message_editing", bool),
("message_content_edit_limit_seconds", int),
- ("allow_community_topic_editing", bool),
+ ("edit_topic_policy", int),
]
)
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index c9cdc740f8..c3d296d5d3 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -218,8 +218,8 @@ def fetch_initial_state_data(
state["realm_allow_message_editing"] = (
False if user_profile is None else realm.allow_message_editing
)
- state["realm_allow_community_topic_editing"] = (
- False if user_profile is None else realm.allow_community_topic_editing
+ state["realm_edit_topic_policy"] = (
+ Realm.POLICY_ADMINS_ONLY if user_profile is None else realm.edit_topic_policy
)
state["realm_allow_message_deleting"] = (
False if user_profile is None else realm.allow_message_deleting
diff --git a/zerver/migrations/0327_realm_edit_topic_policy.py b/zerver/migrations/0327_realm_edit_topic_policy.py
new file mode 100644
index 0000000000..c1803c8383
--- /dev/null
+++ b/zerver/migrations/0327_realm_edit_topic_policy.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.2 on 2021-05-26 09:39
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("zerver", "0326_alter_realm_authentication_methods"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="realm",
+ name="edit_topic_policy",
+ field=models.PositiveSmallIntegerField(default=5),
+ ),
+ ]
diff --git a/zerver/migrations/0328_migrate_to_edit_topic_policy.py b/zerver/migrations/0328_migrate_to_edit_topic_policy.py
new file mode 100644
index 0000000000..8ed74de769
--- /dev/null
+++ b/zerver/migrations/0328_migrate_to_edit_topic_policy.py
@@ -0,0 +1,46 @@
+# Generated by Django 3.2.2 on 2021-05-26 09:43
+
+from django.db import migrations
+from django.db.backends.postgresql.schema import DatabaseSchemaEditor
+from django.db.migrations.state import StateApps
+
+
+def migrate_to_edit_topic_policy(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
+ Realm = apps.get_model("zerver", "Realm")
+ Realm.POLICY_EVERYONE = 5
+ Realm.POLICY_ADMINS_ONLY = 2
+ Realm.objects.filter(allow_community_topic_editing=False).update(
+ edit_topic_policy=Realm.POLICY_ADMINS_ONLY
+ )
+ Realm.objects.filter(allow_community_topic_editing=True).update(
+ edit_topic_policy=Realm.POLICY_EVERYONE
+ )
+
+
+def reverse_migrate_to_edit_topic_policy(
+ apps: StateApps, schema_editor: DatabaseSchemaEditor
+) -> None:
+ Realm = apps.get_model("zerver", "Realm")
+ Realm.POLICY_EVERYONE = 5
+ Realm.POLICY_ADMINS_ONLY = 2
+ Realm.objects.filter(edit_topic_policy=Realm.POLICY_ADMINS_ONLY).update(
+ allow_community_topic_editing=False
+ )
+ Realm.objects.filter(edit_topic_policy=Realm.POLICY_EVERYONE).update(
+ allow_community_topic_editing=True
+ )
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("zerver", "0327_realm_edit_topic_policy"),
+ ]
+
+ operations = [
+ migrations.RunPython(
+ migrate_to_edit_topic_policy,
+ reverse_code=reverse_migrate_to_edit_topic_policy,
+ elidable=True,
+ ),
+ ]
diff --git a/zerver/migrations/0329_remove_realm_allow_community_topic_editing.py b/zerver/migrations/0329_remove_realm_allow_community_topic_editing.py
new file mode 100644
index 0000000000..0346634703
--- /dev/null
+++ b/zerver/migrations/0329_remove_realm_allow_community_topic_editing.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.2.2 on 2021-05-26 09:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("zerver", "0328_migrate_to_edit_topic_policy"),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name="realm",
+ name="allow_community_topic_editing",
+ ),
+ ]
diff --git a/zerver/models.py b/zerver/models.py
index e5511acef2..7c7591251d 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -254,6 +254,7 @@ class Realm(models.Model):
POLICY_ADMINS_ONLY = 2
POLICY_FULL_MEMBERS_ONLY = 3
POLICY_MODERATORS_ONLY = 4
+ POLICY_EVERYONE = 5
COMMON_POLICY_TYPES = [
POLICY_MEMBERS_ONLY,
@@ -262,9 +263,19 @@ class Realm(models.Model):
POLICY_MODERATORS_ONLY,
]
+ COMMON_MESSAGE_POLICY_TYPES = [
+ POLICY_ADMINS_ONLY,
+ POLICY_EVERYONE,
+ ]
+
+ DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS = 259200
+
# Who in the organization is allowed to create streams.
create_stream_policy: int = models.PositiveSmallIntegerField(default=POLICY_MEMBERS_ONLY)
+ # Who in the organization is allowed to edit topics of any message.
+ edit_topic_policy: int = models.PositiveSmallIntegerField(default=POLICY_EVERYONE)
+
# Who in the organization is allowed to invite other users to organization.
invite_to_realm_policy: int = models.PositiveSmallIntegerField(default=POLICY_MEMBERS_ONLY)
@@ -362,9 +373,6 @@ class Realm(models.Model):
# Whether users have access to message edit history
allow_edit_history: bool = models.BooleanField(default=True)
- DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS = 259200
- allow_community_topic_editing: bool = models.BooleanField(default=True)
-
# Defaults for new users
default_twenty_four_hour_time: bool = models.BooleanField(default=False)
default_language: str = models.CharField(default="en", max_length=MAX_LANGUAGE_ID_LENGTH)
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 2082e3f794..51ba8a3ab2 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -3483,11 +3483,16 @@ paths:
description: |
Whether this organizations [message edit policy](/help/configure-message-editing-and-deletion)
allows editing the content of messages.
- allow_community_topic_editing:
- type: boolean
+ edit_topic_policy:
+ type: integer
description: |
- Whether [community topic editing](/help/community-topic-edits) is enabled
- in this organization.
+ The policy for which users can edit topics of any message.
+
+ * 2 = admins only
+ * 5 = everyone
+
+ **Changes**: New in Zulip 5.0 (feature level 75), replacing the
+ previous `allow_community_topic_editing` boolean.
message_content_edit_limit_seconds:
type: integer
description: |
@@ -3780,7 +3785,7 @@ paths:
{
"allow_message_editing": false,
"message_content_edit_limit_seconds": 0,
- "allow_community_topic_editing": false,
+ "edit_topic_policy": 2,
},
"id": 0,
}
@@ -8733,13 +8738,18 @@ paths:
Whether this organizations [message edit policy](/help/configure-message-editing-and-deletion)
allows editing the content of messages.
- realm_allow_community_topic_editing:
- type: boolean
+ realm_edit_topic_policy:
+ type: integer
description: |
Present if `realm` is present in `fetch_event_types`.
- Whether [community topic editing](/help/community-topic-edits) is enabled
- in this organization.
+ The policy for which users can edit topics of any message.
+
+ * 2 = admins only
+ * 5 = everyone
+
+ **Changes**: New in Zulip 5.0 (feature level 75), replacing the
+ previous `allow_community_topic_editing` boolean.
realm_message_content_edit_limit_seconds:
type: integer
description: |
diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py
index 1813383481..0fb3933dc7 100644
--- a/zerver/tests/test_audit_log.py
+++ b/zerver/tests/test_audit_log.py
@@ -41,6 +41,7 @@ from zerver.lib.streams import create_stream_if_needed
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import (
Message,
+ Realm,
RealmAuditLog,
Recipient,
Subscription,
@@ -412,13 +413,13 @@ class TestRealmAuditLog(ZulipTestCase):
RealmAuditLog.NEW_VALUE: 1000,
},
{
- "property": "allow_community_topic_editing",
- RealmAuditLog.OLD_VALUE: True,
- RealmAuditLog.NEW_VALUE: False,
+ "property": "edit_topic_policy",
+ RealmAuditLog.OLD_VALUE: Realm.POLICY_EVERYONE,
+ RealmAuditLog.NEW_VALUE: Realm.POLICY_ADMINS_ONLY,
},
]
- do_set_realm_message_editing(realm, True, 1000, False, acting_user=user)
+ do_set_realm_message_editing(realm, True, 1000, Realm.POLICY_ADMINS_ONLY, acting_user=user)
realm_audit_logs = RealmAuditLog.objects.filter(
realm=realm,
event_type=RealmAuditLog.REALM_PROPERTY_CHANGED,
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 44f7726d57..0a46b97133 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -1241,7 +1241,7 @@ class NormalActionsTest(BaseAction):
self.user_profile.realm,
allow_message_editing,
message_content_edit_limit_seconds,
- False,
+ Realm.POLICY_ADMINS_ONLY,
acting_user=None,
)
)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 3d354e0945..fb7f349cc6 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -138,7 +138,6 @@ class HomeTest(ZulipTestCase):
"prompt_for_invites",
"queue_id",
"realm_add_emoji_by_admins_only",
- "realm_allow_community_topic_editing",
"realm_allow_edit_history",
"realm_allow_message_deleting",
"realm_allow_message_editing",
@@ -161,6 +160,7 @@ class HomeTest(ZulipTestCase):
"realm_digest_weekday",
"realm_disallow_disposable_email_addresses",
"realm_domains",
+ "realm_edit_topic_policy",
"realm_email_address_visibility",
"realm_email_auth_enabled",
"realm_email_changes_disabled",
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index 58e18856c2..288fd090e6 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -722,16 +722,14 @@ class EditMessageTest(EditMessageTestCase):
def set_message_editing_params(
allow_message_editing: bool,
message_content_edit_limit_seconds: int,
- allow_community_topic_editing: bool,
+ edit_topic_policy: int,
) -> None:
result = self.client_patch(
"/json/realm",
{
"allow_message_editing": orjson.dumps(allow_message_editing).decode(),
"message_content_edit_limit_seconds": message_content_edit_limit_seconds,
- "allow_community_topic_editing": orjson.dumps(
- allow_community_topic_editing
- ).decode(),
+ "edit_topic_policy": edit_topic_policy,
},
)
self.assert_json_success(result)
@@ -781,46 +779,44 @@ class EditMessageTest(EditMessageTestCase):
# test the various possible message editing settings
# high enough time limit, all edits allowed
- set_message_editing_params(True, 240, False)
+ set_message_editing_params(True, 240, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_success(id_, "A")
# out of time, only topic editing allowed
- set_message_editing_params(True, 120, False)
+ set_message_editing_params(True, 120, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_success(id_, "B", True)
do_edit_message_assert_error(id_, "C", "The time limit for editing this message has passed")
# infinite time, all edits allowed
- set_message_editing_params(True, 0, False)
+ set_message_editing_params(True, 0, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_success(id_, "D")
# without allow_message_editing, nothing is allowed
- set_message_editing_params(False, 240, False)
+ set_message_editing_params(False, 240, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error(
id_, "E", "Your organization has turned off message editing", True
)
- set_message_editing_params(False, 120, False)
+ set_message_editing_params(False, 120, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error(
id_, "F", "Your organization has turned off message editing", True
)
- set_message_editing_params(False, 0, False)
+ set_message_editing_params(False, 0, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error(
id_, "G", "Your organization has turned off message editing", True
)
- def test_allow_community_topic_editing(self) -> None:
+ def test_edit_topic_policy(self) -> None:
def set_message_editing_params(
allow_message_editing: bool,
message_content_edit_limit_seconds: int,
- allow_community_topic_editing: bool,
+ edit_topic_policy: int,
) -> None:
result = self.client_patch(
"/json/realm",
{
"allow_message_editing": orjson.dumps(allow_message_editing).decode(),
"message_content_edit_limit_seconds": message_content_edit_limit_seconds,
- "allow_community_topic_editing": orjson.dumps(
- allow_community_topic_editing
- ).decode(),
+ "edit_topic_policy": edit_topic_policy,
},
)
self.assert_json_success(result)
@@ -855,21 +851,21 @@ class EditMessageTest(EditMessageTestCase):
message.save()
# any user can edit the topic of a message
- set_message_editing_params(True, 0, True)
+ set_message_editing_params(True, 0, Realm.POLICY_EVERYONE)
# log in as a new user
self.login("cordelia")
do_edit_message_assert_success(id_, "A")
# only admins can edit the topics of messages
self.login("iago")
- set_message_editing_params(True, 0, False)
+ set_message_editing_params(True, 0, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_success(id_, "B")
self.login("cordelia")
do_edit_message_assert_error(id_, "C", "You don't have permission to edit this message")
# users cannot edit topics if allow_message_editing is False
self.login("iago")
- set_message_editing_params(False, 0, True)
+ set_message_editing_params(False, 0, Realm.POLICY_EVERYONE)
self.login("cordelia")
do_edit_message_assert_error(id_, "D", "Your organization has turned off message editing")
@@ -877,7 +873,7 @@ class EditMessageTest(EditMessageTestCase):
message.date_sent = message.date_sent - datetime.timedelta(seconds=290000)
message.save()
self.login("iago")
- set_message_editing_params(True, 0, True)
+ set_message_editing_params(True, 0, Realm.POLICY_EVERYONE)
do_edit_message_assert_success(id_, "E")
self.login("cordelia")
do_edit_message_assert_error(
@@ -1537,7 +1533,7 @@ class EditMessageTest(EditMessageTestCase):
)
realm = user_profile.realm
- realm.allow_community_topic_editing = False
+ realm.edit_topic_policy = Realm.POLICY_ADMINS_ONLY
realm.save()
self.login("cordelia")
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index cf3bad953a..6c04a24c4b 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -910,25 +910,31 @@ class RealmAPITest(ZulipTestCase):
"""Tests updating the realm property 'allow_message_editing'."""
self.set_up_db("allow_message_editing", False)
self.set_up_db("message_content_edit_limit_seconds", 0)
- self.set_up_db("allow_community_topic_editing", False)
+ self.set_up_db("edit_topic_policy", Realm.POLICY_ADMINS_ONLY)
realm = self.update_with_api("allow_message_editing", True)
realm = self.update_with_api("message_content_edit_limit_seconds", 100)
- realm = self.update_with_api("allow_community_topic_editing", True)
+ realm = self.update_with_api("edit_topic_policy", Realm.POLICY_EVERYONE)
self.assertEqual(realm.allow_message_editing, True)
self.assertEqual(realm.message_content_edit_limit_seconds, 100)
- self.assertEqual(realm.allow_community_topic_editing, True)
+ self.assertEqual(realm.edit_topic_policy, Realm.POLICY_EVERYONE)
realm = self.update_with_api("allow_message_editing", False)
self.assertEqual(realm.allow_message_editing, False)
self.assertEqual(realm.message_content_edit_limit_seconds, 100)
- self.assertEqual(realm.allow_community_topic_editing, True)
+ self.assertEqual(realm.edit_topic_policy, Realm.POLICY_EVERYONE)
realm = self.update_with_api("message_content_edit_limit_seconds", 200)
self.assertEqual(realm.allow_message_editing, False)
self.assertEqual(realm.message_content_edit_limit_seconds, 200)
- self.assertEqual(realm.allow_community_topic_editing, True)
- realm = self.update_with_api("allow_community_topic_editing", False)
+ self.assertEqual(realm.edit_topic_policy, Realm.POLICY_EVERYONE)
+ realm = self.update_with_api("edit_topic_policy", Realm.POLICY_ADMINS_ONLY)
self.assertEqual(realm.allow_message_editing, False)
self.assertEqual(realm.message_content_edit_limit_seconds, 200)
- self.assertEqual(realm.allow_community_topic_editing, False)
+ self.assertEqual(realm.edit_topic_policy, Realm.POLICY_ADMINS_ONLY)
+
+ # Test an invalid value for edit_topic_policy
+ invalid_edit_topic_policy_value = 10
+ req = {"edit_topic_policy": orjson.dumps(invalid_edit_topic_policy_value).decode()}
+ result = self.client_patch("/json/realm", req)
+ self.assert_json_error(result, "Invalid edit_topic_policy")
def test_update_realm_allow_message_deleting(self) -> None:
"""Tests updating the realm property 'allow_message_deleting'."""
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
index cd77971989..db4a922f52 100644
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -66,7 +66,9 @@ def update_realm(
converter=to_non_negative_int, default=None
),
allow_message_editing: Optional[bool] = REQ(json_validator=check_bool, default=None),
- allow_community_topic_editing: Optional[bool] = REQ(json_validator=check_bool, default=None),
+ edit_topic_policy: Optional[int] = REQ(
+ json_validator=check_int_in(Realm.COMMON_MESSAGE_POLICY_TYPES), default=None
+ ),
mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None),
message_content_edit_limit_seconds: Optional[int] = REQ(
converter=to_non_negative_int, default=None
@@ -181,27 +183,24 @@ def update_realm(
message_content_edit_limit_seconds is not None
and realm.message_content_edit_limit_seconds != message_content_edit_limit_seconds
)
- or (
- allow_community_topic_editing is not None
- and realm.allow_community_topic_editing != allow_community_topic_editing
- )
+ or (edit_topic_policy is not None and realm.edit_topic_policy != edit_topic_policy)
):
if allow_message_editing is None:
allow_message_editing = realm.allow_message_editing
if message_content_edit_limit_seconds is None:
message_content_edit_limit_seconds = realm.message_content_edit_limit_seconds
- if allow_community_topic_editing is None:
- allow_community_topic_editing = realm.allow_community_topic_editing
+ if edit_topic_policy is None:
+ edit_topic_policy = realm.edit_topic_policy
do_set_realm_message_editing(
realm,
allow_message_editing,
message_content_edit_limit_seconds,
- allow_community_topic_editing,
+ edit_topic_policy,
acting_user=user_profile,
)
data["allow_message_editing"] = allow_message_editing
data["message_content_edit_limit_seconds"] = message_content_edit_limit_seconds
- data["allow_community_topic_editing"] = allow_community_topic_editing
+ data["edit_topic_policy"] = edit_topic_policy
# Realm.notifications_stream and Realm.signup_notifications_stream are not boolean,
# str or integer field, and thus doesn't fit into the do_set_realm_property framework.