compose: Display error for non-admin trying to post to announce_only stream.

Partially fixes #4708.
Implements a first version (v1) for the feature. The next step would be
to allow admins to toggle `is_announcement_only` in the UI.
This commit is contained in:
Shubham Padia
2018-05-14 15:36:56 +05:30
committed by Tim Abbott
parent 9ad292cf2a
commit 10a65a62db
4 changed files with 53 additions and 0 deletions

View File

@@ -511,6 +511,16 @@ function validate_stream_message_announce(stream_name) {
return true;
}
function validate_stream_message_announcement_only(stream_name) {
// Only allow realm admins to post to announcement_only streams.
var is_announcement_only = stream_data.get_announcement_only(stream_name);
if (is_announcement_only && !page_params.is_admin) {
compose_error(i18n.t("Only organization admins are allowed to post to this stream."));
return false;
}
return true;
}
exports.validation_error = function (error_type, stream_name) {
var response;
@@ -557,6 +567,10 @@ function validate_stream_message() {
}
}
if (!validate_stream_message_announcement_only(stream_name)) {
return false;
}
// If both `@all` is mentioned and it's in `#announce`, just validate
// for `@all`. Users shouldn't have to hit "yes" more than once.
if (util.is_all_or_everyone_mentioned(compose_state.message_content()) &&