mirror of https://github.com/zulip/zulip.git
settings: Rename helper function to check who can edit topics.
This commit renames "can_edit_topic_of_any_message" function in models.py to "can_move_messages_to_another_topic" and "user_can_edit_topic_of_any_message" function in settings_data.js to "user_can_move_messages_to_another_topic". This change is done since topic editing permission does not depend on message sender now and messages are considered same irrespective of whether the user who is editing the topic had sent the message or not. This also makes the naming consistent with what we use for the label of this setting in webapp and how we describe this action in help documentation.
This commit is contained in:
parent
ac96db2d95
commit
939a6edf0f
|
@ -742,7 +742,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, mock_template}) => {
|
||||||
test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {
|
test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {
|
||||||
mock_banners();
|
mock_banners();
|
||||||
$("#compose_banners .topic_resolved").length = 0;
|
$("#compose_banners .topic_resolved").length = 0;
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => true);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||||
|
|
||||||
let error_shown = false;
|
let error_shown = false;
|
||||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||||
|
|
|
@ -17,7 +17,7 @@ const editability_types = message_edit.editability_types;
|
||||||
const settings_data = mock_esm("../../static/js/settings_data");
|
const settings_data = mock_esm("../../static/js/settings_data");
|
||||||
|
|
||||||
run_test("get_editability", ({override}) => {
|
run_test("get_editability", ({override}) => {
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => true);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||||
// You can't edit a null message
|
// You can't edit a null message
|
||||||
assert.equal(get_editability(null), editability_types.NO);
|
assert.equal(get_editability(null), editability_types.NO);
|
||||||
// You can't edit a message you didn't send
|
// You can't edit a message you didn't send
|
||||||
|
@ -119,7 +119,7 @@ run_test("is_topic_editable", ({override}) => {
|
||||||
type: "stream",
|
type: "stream",
|
||||||
};
|
};
|
||||||
page_params.realm_allow_message_editing = true;
|
page_params.realm_allow_message_editing = true;
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => true);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||||
page_params.is_admin = true;
|
page_params.is_admin = true;
|
||||||
|
|
||||||
assert.equal(message_edit.is_topic_editable(message), false);
|
assert.equal(message_edit.is_topic_editable(message), false);
|
||||||
|
@ -134,7 +134,7 @@ run_test("is_topic_editable", ({override}) => {
|
||||||
page_params.sent_by_me = false;
|
page_params.sent_by_me = false;
|
||||||
assert.equal(message_edit.is_topic_editable(message), true);
|
assert.equal(message_edit.is_topic_editable(message), true);
|
||||||
|
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => false);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => false);
|
||||||
assert.equal(message_edit.is_topic_editable(message), false);
|
assert.equal(message_edit.is_topic_editable(message), false);
|
||||||
|
|
||||||
page_params.is_admin = false;
|
page_params.is_admin = false;
|
||||||
|
@ -144,13 +144,13 @@ run_test("is_topic_editable", ({override}) => {
|
||||||
assert.equal(message_edit.is_topic_editable(message), true);
|
assert.equal(message_edit.is_topic_editable(message), true);
|
||||||
|
|
||||||
message.topic = "test topic";
|
message.topic = "test topic";
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => false);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => false);
|
||||||
assert.equal(message_edit.is_topic_editable(message), false);
|
assert.equal(message_edit.is_topic_editable(message), false);
|
||||||
|
|
||||||
page_params.realm_community_topic_editing_limit_seconds = 259200;
|
page_params.realm_community_topic_editing_limit_seconds = 259200;
|
||||||
message.timestamp = current_timestamp - 60;
|
message.timestamp = current_timestamp - 60;
|
||||||
|
|
||||||
override(settings_data, "user_can_edit_topic_of_any_message", () => true);
|
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||||
assert.equal(message_edit.is_topic_editable(message), true);
|
assert.equal(message_edit.is_topic_editable(message), true);
|
||||||
|
|
||||||
message.timestamp = current_timestamp - 600000;
|
message.timestamp = current_timestamp - 600000;
|
||||||
|
|
|
@ -243,16 +243,16 @@ function test_message_policy(label, policy, validation_func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_message_policy(
|
test_message_policy(
|
||||||
"user_can_edit_topic_of_any_message",
|
"user_can_move_messages_to_another_topic",
|
||||||
"realm_edit_topic_policy",
|
"realm_edit_topic_policy",
|
||||||
settings_data.user_can_edit_topic_of_any_message,
|
settings_data.user_can_move_messages_to_another_topic,
|
||||||
);
|
);
|
||||||
|
|
||||||
run_test("user_can_edit_topic_of_any_message_nobody_case", () => {
|
run_test("user_can_move_messages_to_another_topic_nobody_case", () => {
|
||||||
page_params.is_admin = true;
|
page_params.is_admin = true;
|
||||||
page_params.is_guest = false;
|
page_params.is_guest = false;
|
||||||
page_params.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code;
|
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);
|
assert.equal(settings_data.user_can_move_messages_to_another_topic(), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("user_can_move_messages_between_streams_nobody_case", () => {
|
run_test("user_can_move_messages_between_streams_nobody_case", () => {
|
||||||
|
|
|
@ -201,7 +201,7 @@ export function warn_if_topic_resolved(topic_changed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const button_text = settings_data.user_can_edit_topic_of_any_message()
|
const button_text = settings_data.user_can_move_messages_to_another_topic()
|
||||||
? $t({defaultMessage: "Unresolve topic"})
|
? $t({defaultMessage: "Unresolve topic"})
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ export function is_topic_editable(message, edit_limit_seconds_buffer = 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings_data.user_can_edit_topic_of_any_message()) {
|
if (!settings_data.user_can_move_messages_to_another_topic()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ export function user_can_add_custom_emoji(): boolean {
|
||||||
return user_has_permission(page_params.realm_add_custom_emoji_policy);
|
return user_has_permission(page_params.realm_add_custom_emoji_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function user_can_edit_topic_of_any_message(): boolean {
|
export function user_can_move_messages_to_another_topic(): boolean {
|
||||||
return user_has_permission(page_params.realm_edit_topic_policy);
|
return user_has_permission(page_params.realm_edit_topic_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,9 +112,9 @@ def can_edit_topic(
|
||||||
if is_no_topic_msg:
|
if is_no_topic_msg:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# The can_edit_topic_of_any_message helper returns whether the user can edit the topic
|
# The can_move_messages_to_another_topic helper returns whether the user can edit
|
||||||
# or not based on edit_topic_policy setting and the user's role.
|
# the topic or not based on edit_topic_policy setting and the user's role.
|
||||||
if user_profile.can_edit_topic_of_any_message():
|
if user_profile.can_move_messages_to_another_topic():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -2121,7 +2121,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings): # type
|
||||||
def can_edit_user_groups(self) -> bool:
|
def can_edit_user_groups(self) -> bool:
|
||||||
return self.has_permission("user_group_edit_policy")
|
return self.has_permission("user_group_edit_policy")
|
||||||
|
|
||||||
def can_edit_topic_of_any_message(self) -> bool:
|
def can_move_messages_to_another_topic(self) -> bool:
|
||||||
return self.has_permission("edit_topic_policy")
|
return self.has_permission("edit_topic_policy")
|
||||||
|
|
||||||
def can_add_custom_emoji(self) -> bool:
|
def can_add_custom_emoji(self) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue