statis/js/people.js: Add function `get_user_type`.

Add function `get_user_type`, which returns user
type-"Administrator", "Guest", "Bot" or "Member"
depending on what they are.
This commit is contained in:
Yashashvi Dave 2018-11-03 00:38:24 +05:30 committed by Tim Abbott
parent bb959acbaf
commit 53201c5411
2 changed files with 49 additions and 0 deletions

View File

@ -8,12 +8,16 @@ set_global('page_params', {});
set_global('md5', function (s) {
return 'md5-' + s;
});
set_global('i18n', global.stub_i18n);
var me = {
email: 'me@example.com',
user_id: 30,
full_name: 'Me Myself',
timezone: 'US/Pacific',
is_admin: false,
is_guest: false,
is_bot: false,
};
var isaac = {
@ -165,6 +169,38 @@ run_test('user_timezone', () => {
assert.equal(people.get_user_time(me.user_id), '12:09 AM');
});
run_test('user_type', () => {
var realm_admin = {
email: 'realm_admin@example.com',
user_id: 32,
is_admin: true,
is_guest: false,
is_bot: false,
};
var guest = {
email: 'guest@example.com',
user_id: 33,
is_admin: false,
is_guest: true,
is_bot: false,
};
var bot = {
email: 'bot@example.com',
user_id: 34,
is_admin: false,
is_guest: false,
is_bot: true,
};
people.add(realm_admin);
people.add(guest);
people.add(bot);
assert.equal(people.get_user_type(me.user_id), i18n.t('Member'));
assert.equal(people.get_user_type(realm_admin.user_id), i18n.t('Administrator'));
assert.equal(people.get_user_type(guest.user_id), i18n.t('Guest'));
assert.equal(people.get_user_type(bot.user_id), i18n.t('Bot'));
});
run_test('updates', () => {
var person = people.get_by_email('me@example.com');
people.set_full_name(person, 'Me the Third');

View File

@ -223,6 +223,19 @@ exports.get_user_time = function (user_id) {
}
};
exports.get_user_type = function (user_id) {
var user_profile = exports.get_person_from_user_id(user_id);
if (user_profile.is_admin) {
return i18n.t("Administrator");
} else if (user_profile.is_guest) {
return i18n.t("Guest");
} else if (user_profile.is_bot) {
return i18n.t("Bot");
}
return i18n.t("Member");
};
exports.emails_strings_to_user_ids_string = function (emails_string) {
var emails = emails_string.split(',');
return exports.email_list_to_user_ids_string(emails);