2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-04-28 20:54:03 +02:00
|
|
|
import * as people from "./people";
|
2021-02-10 17:14:20 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2020-02-25 12:46:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
This is a close cousin of settings_config,
|
|
|
|
but this has a bit more logic, and we
|
|
|
|
ensure 100% line coverage on it.
|
|
|
|
|
|
|
|
Our main goal with this code is to isolate
|
|
|
|
some key modules from having to know
|
|
|
|
about page_params and settings_config details.
|
|
|
|
*/
|
|
|
|
|
2021-02-10 17:14:20 +01:00
|
|
|
export function show_email() {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_email_address_visibility ===
|
|
|
|
settings_config.email_address_visibility_values.everyone.code
|
|
|
|
) {
|
2020-02-25 12:46:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.realm_email_address_visibility ===
|
|
|
|
settings_config.email_address_visibility_values.admins_only.code
|
|
|
|
) {
|
2020-02-25 12:46:14 +01:00
|
|
|
return page_params.is_admin;
|
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2021-02-10 17:14:20 +01:00
|
|
|
}
|
2020-02-25 12:46:14 +01:00
|
|
|
|
2021-02-10 17:14:20 +01:00
|
|
|
export function email_for_user_settings(person) {
|
|
|
|
if (!show_email()) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-02-25 12:46:14 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
page_params.is_admin &&
|
|
|
|
person.delivery_email &&
|
|
|
|
page_params.realm_email_address_visibility ===
|
|
|
|
settings_config.email_address_visibility_values.admins_only.code
|
|
|
|
) {
|
2020-02-25 12:46:14 +01:00
|
|
|
return person.delivery_email;
|
|
|
|
}
|
|
|
|
|
|
|
|
return person.email;
|
2021-02-10 17:14:20 +01:00
|
|
|
}
|
2020-02-25 12:46:14 +01:00
|
|
|
|
2021-02-10 17:14:20 +01:00
|
|
|
export function get_time_preferences(user_timezone) {
|
2020-02-25 12:46:14 +01:00
|
|
|
if (page_params.twenty_four_hour_time) {
|
|
|
|
return {
|
|
|
|
timezone: user_timezone,
|
|
|
|
format: "H:mm",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
timezone: user_timezone,
|
2020-09-29 22:20:46 +02:00
|
|
|
format: "h:mm a",
|
2020-02-25 12:46:14 +01:00
|
|
|
};
|
2021-02-10 17:14:20 +01:00
|
|
|
}
|
2020-06-17 07:43:53 +02:00
|
|
|
|
2021-03-21 16:46:13 +01:00
|
|
|
export function user_can_change_name() {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (page_params.realm_name_changes_disabled || page_params.server_name_changes_disabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function user_can_change_avatar() {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (page_params.realm_avatar_changes_disabled || page_params.server_avatar_changes_disabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:14:20 +01:00
|
|
|
export function user_can_change_logo() {
|
2020-06-17 07:43:53 +02:00
|
|
|
return page_params.is_admin && page_params.zulip_plan_is_not_limited;
|
2021-02-10 17:14:20 +01:00
|
|
|
}
|
2021-04-28 20:54:03 +02:00
|
|
|
|
|
|
|
function user_has_permission(policy_value) {
|
|
|
|
if (page_params.is_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page_params.is_guest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (policy_value === settings_config.common_policy_values.by_admins_only.code) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-21 21:43:27 +02:00
|
|
|
if (page_params.is_moderator) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (policy_value === settings_config.common_policy_values.by_moderators_only.code) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-28 20:54:03 +02:00
|
|
|
if (policy_value === settings_config.common_policy_values.by_members.code) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function user_can_invite_others_to_realm() {
|
|
|
|
return user_has_permission(page_params.realm_invite_to_realm_policy);
|
|
|
|
}
|
2021-04-28 21:29:12 +02:00
|
|
|
|
|
|
|
export function user_can_subscribe_other_users() {
|
|
|
|
return user_has_permission(page_params.realm_invite_to_stream_policy);
|
|
|
|
}
|
2021-04-28 21:58:33 +02:00
|
|
|
|
|
|
|
export function user_can_create_streams() {
|
|
|
|
return user_has_permission(page_params.realm_create_stream_policy);
|
|
|
|
}
|