refactor: Extract email_for_user_settings.

We want to be able to unit test this value,
since it's conditional on several factors:

    - am I an admin?
    - can non-admins view emails?
    - do we have delivery_email for the user?

I'm mocking show_email in the tests, since the
show_email code is in `settings_org` and
kind of hard to unit test.  It's not impossible,
but it's too much for this commit.  (Either
we need to extract it out to a nice file or
deal with mocking jQuery.  That module is
mostly data-oriented, so it would be nice
to have something like `settings_config` that
is actually pure data.)
This commit is contained in:
Steve Howell
2019-12-28 16:41:20 +00:00
committed by Tim Abbott
parent 3a95be2f2f
commit 3e4326afda
4 changed files with 44 additions and 9 deletions

View File

@@ -995,6 +995,18 @@ exports.matches_user_settings_search = function (person, value) {
);
};
exports.email_for_user_settings = function (person) {
if (!settings_org.show_email()) {
return;
}
if (page_params.is_admin && person.delivery_email) {
return person.delivery_email;
}
return person.email;
};
exports.maybe_incr_recipient_count = function (message) {
if (message.type !== 'private') {
return;