user_events: Add code to live update is_moderator on role change.

This commit adds code to live update page_params.is_moderator and
person.is_moderator on receiving role change event.
The code for changing role to moderator and from moderator to any
other role was added in previous commit.
This commit is contained in:
sahil839 2021-04-23 01:07:04 +05:30 committed by Tim Abbott
parent 730c0493b3
commit 253a935cb2
2 changed files with 16 additions and 0 deletions

View File

@ -90,12 +90,20 @@ run_test("updates", () => {
person = people.get_by_email(isaac.email);
assert(!person.is_guest);
user_events.update_person({
user_id: isaac.user_id,
role: settings_config.user_role_values.moderator.code,
});
person = people.get_by_email(isaac.email);
assert.equal(person.is_moderator, true);
user_events.update_person({
user_id: isaac.user_id,
role: settings_config.user_role_values.admin.code,
});
person = people.get_by_email(isaac.email);
assert.equal(person.full_name, "Isaac Newton");
assert.equal(person.is_moderator, false);
assert.equal(person.is_admin, true);
user_events.update_person({

View File

@ -70,6 +70,7 @@ export const update_person = function update(person) {
person_obj.is_admin =
person.role === settings_config.user_role_values.admin.code || person_obj.is_owner;
person_obj.is_guest = person.role === settings_config.user_role_values.guest.code;
person_obj.is_moderator = person.role === settings_config.user_role_values.moderator.code;
settings_users.update_user_data(person.user_id, person);
if (people.is_my_user_id(person.user_id) && page_params.is_owner !== person_obj.is_owner) {
@ -85,6 +86,13 @@ export const update_person = function update(person) {
settings_profile_fields.maybe_disable_widgets();
settings_streams.maybe_disable_widgets();
}
if (
people.is_my_user_id(person.user_id) &&
page_params.is_moderator !== person_obj.is_moderator
) {
page_params.is_moderator = person_obj.is_moderator;
}
}
if (Object.prototype.hasOwnProperty.call(person, "avatar_url")) {