message_edit: Add "Nobody" option for edit_topic_policy setting.

This commit is contained in:
Sahil Batra 2022-09-28 20:00:10 +05:30 committed by Tim Abbott
parent de4ae16989
commit 02eee3a04f
12 changed files with 64 additions and 13 deletions

View File

@ -116,9 +116,13 @@ run_test("is_topic_editable", ({override}) => {
message.sent_by_me = false; message.sent_by_me = false;
page_params.is_admin = true; page_params.is_admin = true;
assert.equal(message_edit.is_topic_editable(message), true); override(settings_data, "user_can_edit_topic_of_any_message", () => false);
assert.equal(message_edit.is_topic_editable(message), false);
page_params.is_admin = false; page_params.is_admin = false;
message.sent_by_me = false;
assert.equal(message_edit.is_topic_editable(message), false);
message.topic = "translated: (no topic)"; message.topic = "translated: (no topic)";
assert.equal(message_edit.is_topic_editable(message), true); assert.equal(message_edit.is_topic_editable(message), true);

View File

@ -248,6 +248,14 @@ test_message_policy(
settings_data.user_can_edit_topic_of_any_message, settings_data.user_can_edit_topic_of_any_message,
); );
run_test("user_can_edit_topic_of_any_message_nobody_case", () => {
page_params.is_admin = true;
page_params.is_guest = false;
page_params.realm_edit_topic_policy =
settings_config.edit_topic_policy_values.nobody.code;
assert.equal(settings_data.user_can_edit_topic_of_any_message(), false);
});
test_message_policy( test_message_policy(
"user_can_delete_own_message", "user_can_delete_own_message",
"realm_delete_own_message_policy", "realm_delete_own_message_policy",

View File

@ -65,10 +65,8 @@ export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
// If message editing is disabled, so is topic editing. // If message editing is disabled, so is topic editing.
return false; return false;
} }
// Organization admins and message senders can edit message topics indefinitely.
if (page_params.is_admin) { // message senders can edit message topics indefinitely.
return true;
}
if (message.sent_by_me) { if (message.sent_by_me) {
return true; return true;
} }
@ -81,9 +79,10 @@ export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
return false; return false;
} }
// moderators can edit the topic if edit_topic_policy allows them to do so, // Organization admins and moderators can edit message topics indefinitely,
// irrespective of the topic editing deadline. // irrespective of the topic editing deadline, if edit_topic_policy allows
if (page_params.is_moderator) { // them to do so.
if (page_params.is_admin || page_params.is_moderator) {
return true; return true;
} }

View File

@ -290,6 +290,15 @@ export const common_message_policy_values = {
}, },
}; };
export const edit_topic_policy_values = {
...common_message_policy_values,
nobody: {
order: 6,
code: 6,
description: $t({defaultMessage: "Nobody"}),
},
};
export const time_limit_dropdown_values = [ export const time_limit_dropdown_values = [
{ {
text: $t({defaultMessage: "Any time"}), text: $t({defaultMessage: "Any time"}),

View File

@ -114,6 +114,9 @@ export function get_organization_settings_options() {
options.invite_to_realm_policy_values = get_sorted_options_list( options.invite_to_realm_policy_values = get_sorted_options_list(
settings_config.invite_to_realm_policy_values, settings_config.invite_to_realm_policy_values,
); );
options.edit_topic_policy_values = get_sorted_options_list(
settings_config.edit_topic_policy_values,
);
return options; return options;
} }

View File

@ -177,7 +177,7 @@
<div class="input-group"> <div class="input-group">
<label for="realm_edit_topic_policy" class="dropdown-title">{{t "Who can edit the topic of any message" }}</label> <label for="realm_edit_topic_policy" class="dropdown-title">{{t "Who can edit the topic of any message" }}</label>
<select name="realm_edit_topic_policy" id="id_realm_edit_topic_policy" class="prop-element" data-setting-widget-type="number" {{#unless realm_allow_message_editing}}disabled{{/unless}}> <select name="realm_edit_topic_policy" id="id_realm_edit_topic_policy" class="prop-element" data-setting-widget-type="number" {{#unless realm_allow_message_editing}}disabled{{/unless}}>
{{> dropdown_options_widget option_values=common_message_policy_values}} {{> dropdown_options_widget option_values=edit_topic_policy_values}}
</select> </select>
</div> </div>

View File

@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 7.0 ## Changes in Zulip 7.0
**Feature level 159**
* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
`PATCH /realm`: Nobody added as an option for the realm setting
`edit_topic_policy`.
Feature levels 157-158 are reserved for future use in 6.x maintenance Feature levels 157-158 are reserved for future use in 6.x maintenance
releases. releases.

View File

@ -365,6 +365,15 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
POLICY_NOBODY, POLICY_NOBODY,
] ]
EDIT_TOPIC_POLICY_TYPES = [
POLICY_MEMBERS_ONLY,
POLICY_ADMINS_ONLY,
POLICY_FULL_MEMBERS_ONLY,
POLICY_MODERATORS_ONLY,
POLICY_EVERYONE,
POLICY_NOBODY,
]
DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS = 259200 DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS = 259200
# Who in the organization is allowed to add custom emojis. # Who in the organization is allowed to add custom emojis.

View File

@ -3890,9 +3890,11 @@ paths:
- 3 = [full members][calc-full-member] only - 3 = [full members][calc-full-member] only
- 4 = moderators only - 4 = moderators only
- 5 = everyone - 5 = everyone
- 6 = nobody
**Changes**: New in Zulip 5.0 (feature level 75), replacing the **Changes**: New in Zulip 5.0 (feature level 75), replacing the
previous `allow_community_topic_editing` boolean. previous `allow_community_topic_editing` boolean. Nobody added
as an option in Zulip 7.0 (feature level 159).
[permission-level]: /api/roles-and-permissions#permission-levels [permission-level]: /api/roles-and-permissions#permission-levels
[calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member [calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member
@ -12155,9 +12157,11 @@ paths:
- 3 = [full members][calc-full-member] only - 3 = [full members][calc-full-member] only
- 4 = moderators only - 4 = moderators only
- 5 = everyone - 5 = everyone
- 6 = nobody
**Changes**: New in Zulip 5.0 (feature level 75), replacing the **Changes**: New in Zulip 5.0 (feature level 75), replacing the
previous `allow_community_topic_editing` boolean. previous `allow_community_topic_editing` boolean. Nobody added as
an option in Zulip 7.0 (feature level 159).
[permission-level]: /api/roles-and-permissions#permission-levels [permission-level]: /api/roles-and-permissions#permission-levels
[calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member [calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member

View File

@ -1153,6 +1153,15 @@ class EditMessageTest(EditMessageTestCase):
) )
do_edit_message_assert_success(id_, "E", "iago") do_edit_message_assert_success(id_, "E", "iago")
# even owners and admins cannot edit the topics of messages
set_message_editing_params(True, "unlimited", Realm.POLICY_NOBODY)
do_edit_message_assert_error(
id_, "H", "You don't have permission to edit this message", "desdemona"
)
do_edit_message_assert_error(
id_, "H", "You don't have permission to edit this message", "iago"
)
# users cannot edit topics if allow_message_editing is False # users cannot edit topics if allow_message_editing is False
set_message_editing_params(False, "unlimited", Realm.POLICY_EVERYONE) set_message_editing_params(False, "unlimited", Realm.POLICY_EVERYONE)
do_edit_message_assert_error( do_edit_message_assert_error(

View File

@ -1176,7 +1176,7 @@ class RealmAPITest(ZulipTestCase):
move_messages_between_streams_policy=Realm.COMMON_POLICY_TYPES, move_messages_between_streams_policy=Realm.COMMON_POLICY_TYPES,
add_custom_emoji_policy=Realm.COMMON_POLICY_TYPES, add_custom_emoji_policy=Realm.COMMON_POLICY_TYPES,
delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES, delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES,
edit_topic_policy=Realm.COMMON_MESSAGE_POLICY_TYPES, edit_topic_policy=Realm.EDIT_TOPIC_POLICY_TYPES,
message_content_edit_limit_seconds=[1000, 1100, 1200], message_content_edit_limit_seconds=[1000, 1100, 1200],
) )

View File

@ -78,7 +78,7 @@ def update_realm(
), ),
allow_message_editing: Optional[bool] = REQ(json_validator=check_bool, default=None), allow_message_editing: Optional[bool] = REQ(json_validator=check_bool, default=None),
edit_topic_policy: Optional[int] = REQ( edit_topic_policy: Optional[int] = REQ(
json_validator=check_int_in(Realm.COMMON_MESSAGE_POLICY_TYPES), default=None json_validator=check_int_in(Realm.EDIT_TOPIC_POLICY_TYPES), default=None
), ),
mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None), mandatory_topics: Optional[bool] = REQ(json_validator=check_bool, default=None),
message_content_edit_limit_seconds_raw: Optional[Union[int, str]] = REQ( message_content_edit_limit_seconds_raw: Optional[Union[int, str]] = REQ(