compose: Show error for wildcard messages according to settings.

This commit changes UI to show /error for sending message with
wildcard mention according to wildcard mention policy of organization.

Fixes #16211.
This commit is contained in:
sahil839
2020-09-11 19:37:06 +05:30
committed by Tim Abbott
parent 1d5aa2e514
commit 465122b0df
2 changed files with 110 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ const render_compose_private_stream_alert = require("../templates/compose_privat
const people = require("./people");
const rendered_markdown = require("./rendered_markdown");
const settings_config = require("./settings_config");
const util = require("./util");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
@@ -481,14 +482,66 @@ function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
return result;
}
exports.wildcard_mention_allowed = function () {
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_everyone.code
) {
return true;
}
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.nobody.code
) {
return false;
}
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_stream_admins_only.code
) {
// TODO: Check the user's stream-level role once stream-level admins exist.
return page_params.is_admin;
}
// TODO: Uncomment when we add support for stream-level administrators.
// if (
// page_params.realm_wildcard_mention_policy ===
// settings_config.wildcard_mention_policy_values.by_admins_only.code
// ) {
// return page_params.is_admin;
// }
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_full_members.code
) {
if (page_params.is_admin) {
return true;
}
const person = people.get_by_user_id(page_params.user_id);
const current_datetime = new Date(Date.now());
const person_date_joined = new Date(person.date_joined);
const days = (current_datetime - person_date_joined) / 1000 / 86400;
return days >= page_params.realm_waiting_period_threshold && !page_params.is_guest;
}
return !page_params.is_guest;
};
function validate_stream_message_mentions(stream_id) {
const stream_count = stream_data.get_subscriber_count(stream_id) || 0;
// check if wildcard_mention has any mention and henceforth execute the warning message.
// If the user is attempting to do a wildcard mention in a large
// stream, check if they permission to do so.
if (
wildcard_mention !== null &&
stream_count > exports.wildcard_mention_large_stream_threshold
) {
if (!exports.wildcard_mention_allowed()) {
compose_error(
i18n.t("You do not have permission to use wildcard mentions in this stream."),
);
return false;
}
if (
user_acknowledged_all_everyone === undefined ||
user_acknowledged_all_everyone === false