org_settings: Fix error with undefined profile_field in bot settings.

This is a small patch to fix the error message an admin would receive if
they tried to change bot info and owner from the "bots" setting of the
organization settings panel.
This commit is contained in:
Hemanth V. Alluri 2019-04-07 20:59:53 +05:30 committed by Tim Abbott
parent c192327a37
commit 34db469700
3 changed files with 29 additions and 1 deletions

View File

@ -145,6 +145,20 @@ run_test('my_custom_profile_data', () => {
assert.equal(people.my_custom_profile_data(undefined), undefined); assert.equal(people.my_custom_profile_data(undefined), undefined);
}); });
run_test('bot_custom_profile_data', () => {
// If this test fails, then try opening organization settings > bots
// http://localhost:9991/#organization/bot-list-admin
// and then try to edit any of the bots.
var bot = {
email: 'bot@example.com',
user_id: 31,
full_name: 'Bot',
is_bot: true,
};
people.add_in_realm(bot);
assert.equal(people.get_custom_profile_data(31, 3), null);
});
run_test('user_timezone', () => { run_test('user_timezone', () => {
var expected_pref = { var expected_pref = {
timezone: 'US/Pacific', timezone: 'US/Pacific',

View File

@ -1028,7 +1028,11 @@ exports.my_custom_profile_data = function (field_id) {
}; };
exports.get_custom_profile_data = function (user_id, field_id) { exports.get_custom_profile_data = function (user_id, field_id) {
return people_by_user_id_dict.get(user_id).profile_data[field_id]; var profile_data = people_by_user_id_dict.get(user_id).profile_data;
if (profile_data === undefined) {
return null;
}
return profile_data[field_id];
}; };
exports.is_my_user_id = function (user_id) { exports.is_my_user_id = function (user_id) {

View File

@ -64,6 +64,10 @@ function update_user_custom_profile_fields(fields, method) {
} }
exports.append_custom_profile_fields = function (element_id, user_id) { exports.append_custom_profile_fields = function (element_id, user_id) {
var person = people.get_person_from_user_id(user_id);
if (person.is_bot) {
return;
}
var all_custom_fields = page_params.custom_profile_fields; var all_custom_fields = page_params.custom_profile_fields;
var field_types = page_params.custom_profile_field_types; var field_types = page_params.custom_profile_field_types;
@ -129,6 +133,11 @@ exports.initialize_custom_user_type_fields = function (element_id, user_id, is_e
var field_types = page_params.custom_profile_field_types; var field_types = page_params.custom_profile_field_types;
var user_pills = {}; var user_pills = {};
var person = people.get_person_from_user_id(user_id);
if (person.is_bot) {
return [];
}
page_params.custom_profile_fields.forEach(function (field) { page_params.custom_profile_fields.forEach(function (field) {
var field_value_raw = people.get_custom_profile_data(user_id, field.id); var field_value_raw = people.get_custom_profile_data(user_id, field.id);
@ -179,6 +188,7 @@ exports.initialize_custom_user_type_fields = function (element_id, user_id, is_e
user_pills[field.id] = pills; user_pills[field.id] = pills;
} }
}); });
return user_pills; return user_pills;
}; };