mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
This extracts a new module with three
functions, which we will test with 100%
line coverage:
- show_email
- email_for_user_settings
- get_time_preferences
The first two break several dependencies
in the codebase on `settings_org.js`. The
`get_time_preferences` breaks an annoying
dependency on `page_params` within people.
The module is pretty cohesive, in terms that
all three functions are just light wrappers
around `page_params` and/or `settings_config`.
Now all the modules that want to call show_email()
only have to require `settings_data`, instead of
having a dependency on the much heavier
`settings_org.js` module.
I also make some of the unit tests here be more
full-stack, where instead of stubbing show_email,
I basically just toggle `page_params.is_admin`.
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const settings_config = require("./settings_config");
|
|
|
|
/*
|
|
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.
|
|
*/
|
|
|
|
exports.show_email = function () {
|
|
if (page_params.realm_email_address_visibility ===
|
|
settings_config.email_address_visibility_values.everyone.code) {
|
|
return true;
|
|
}
|
|
if (page_params.realm_email_address_visibility ===
|
|
settings_config.email_address_visibility_values.admins_only.code) {
|
|
return page_params.is_admin;
|
|
}
|
|
};
|
|
|
|
exports.email_for_user_settings = function (person) {
|
|
if (!exports.show_email()) {
|
|
return;
|
|
}
|
|
|
|
if (page_params.is_admin && person.delivery_email) {
|
|
return person.delivery_email;
|
|
}
|
|
|
|
return person.email;
|
|
};
|
|
|
|
exports.get_time_preferences = function (user_timezone) {
|
|
if (page_params.twenty_four_hour_time) {
|
|
return {
|
|
timezone: user_timezone,
|
|
format: "H:mm",
|
|
};
|
|
}
|
|
return {
|
|
timezone: user_timezone,
|
|
format: "h:mm A",
|
|
};
|
|
};
|