settings: Rename can_edit_all_user_groups to use `manage`.

Having both `manage` and `edit` terminologies was confusing, so
this commit ensures that we use `manage` wherever applicable.
This commit is contained in:
Shubham Padia 2024-09-18 08:54:19 +00:00 committed by Tim Abbott
parent 4d06626b6f
commit 91edf59873
6 changed files with 32 additions and 32 deletions

View File

@ -188,7 +188,7 @@ export function user_can_move_messages_between_streams(): boolean {
return user_has_permission(realm.realm_move_messages_between_streams_policy); return user_has_permission(realm.realm_move_messages_between_streams_policy);
} }
export function user_can_edit_all_user_groups(): boolean { export function user_can_manage_all_groups(): boolean {
if (page_params.is_spectator) { if (page_params.is_spectator) {
return false; return false;
} }
@ -199,12 +199,12 @@ export function user_can_edit_all_user_groups(): boolean {
); );
} }
export function can_edit_user_group(group_id: number): boolean { export function can_manage_user_group(group_id: number): boolean {
if (page_params.is_spectator) { if (page_params.is_spectator) {
return false; return false;
} }
let can_edit_all_user_groups = user_can_edit_all_user_groups(); let can_manage_all_groups = user_can_manage_all_groups();
const group = user_groups.get_user_group_from_id(group_id); const group = user_groups.get_user_group_from_id(group_id);
@ -221,10 +221,10 @@ export function can_edit_user_group(group_id: number): boolean {
!current_user.is_moderator && !current_user.is_moderator &&
!user_groups.is_direct_member_of(current_user.user_id, group_id) !user_groups.is_direct_member_of(current_user.user_id, group_id)
) { ) {
can_edit_all_user_groups = false; can_manage_all_groups = false;
} }
if (can_edit_all_user_groups) { if (can_manage_all_groups) {
return true; return true;
} }

View File

@ -87,7 +87,7 @@ function update_add_members_elements(group) {
const $input_element = $add_members_container.find(".input").expectOne(); const $input_element = $add_members_container.find(".input").expectOne();
const $button_element = $add_members_container.find('button[name="add_member"]').expectOne(); const $button_element = $add_members_container.find('button[name="add_member"]').expectOne();
if (settings_data.can_edit_user_group(group.id)) { if (settings_data.can_manage_user_group(group.id)) {
$input_element.prop("contenteditable", true); $input_element.prop("contenteditable", true);
$button_element.prop("disabled", false); $button_element.prop("disabled", false);
$button_element.css("pointer-events", ""); $button_element.css("pointer-events", "");
@ -120,7 +120,7 @@ function update_group_permission_settings_elements(group) {
const $permission_pill_container_elements = $group_permission_settings.find(".pill-container"); const $permission_pill_container_elements = $group_permission_settings.find(".pill-container");
if (settings_data.can_edit_user_group(group.id)) { if (settings_data.can_manage_user_group(group.id)) {
$permission_dropdown_elements.prop("disabled", false); $permission_dropdown_elements.prop("disabled", false);
$permission_pill_container_elements.find(".input").prop("contenteditable", true); $permission_pill_container_elements.find(".input").prop("contenteditable", true);
$permission_pill_container_elements.removeClass("group_setting_disabled"); $permission_pill_container_elements.removeClass("group_setting_disabled");
@ -187,7 +187,7 @@ function show_general_settings(group) {
function update_general_panel_ui(group) { function update_general_panel_ui(group) {
const $edit_container = get_edit_container(group); const $edit_container = get_edit_container(group);
if (settings_data.can_edit_user_group(group.id)) { if (settings_data.can_manage_user_group(group.id)) {
$edit_container.find(".group-header .button-group").show(); $edit_container.find(".group-header .button-group").show();
$(`.group_settings_header[data-group-id='${CSS.escape(group.id)}'] .deactivate`).show(); $(`.group_settings_header[data-group-id='${CSS.escape(group.id)}'] .deactivate`).show();
} else { } else {
@ -258,7 +258,7 @@ function update_group_membership_button(group_id) {
$group_settings_button.text($t({defaultMessage: "Join group"})); $group_settings_button.text($t({defaultMessage: "Join group"}));
} }
if (settings_data.can_edit_user_group(group_id)) { if (settings_data.can_manage_user_group(group_id)) {
$group_settings_button.prop("disabled", false); $group_settings_button.prop("disabled", false);
$group_settings_button.css("pointer-events", ""); $group_settings_button.css("pointer-events", "");
const $group_settings_button_wrapper = $group_settings_button.closest( const $group_settings_button_wrapper = $group_settings_button.closest(
@ -298,7 +298,7 @@ export function handle_member_edit_event(group_id, user_ids) {
// is added to it. The whole list is redrawed to // is added to it. The whole list is redrawed to
// maintain the sorted order of groups. // maintain the sorted order of groups.
redraw_user_group_list(); redraw_user_group_list();
} else if (!settings_data.can_edit_user_group(group_id)) { } else if (!settings_data.can_manage_user_group(group_id)) {
// We remove the group row immediately only if the // We remove the group row immediately only if the
// user cannot join the group again themselves. // user cannot join the group again themselves.
const group_row = row_for_group_id(group_id); const group_row = row_for_group_id(group_id);
@ -315,7 +315,7 @@ export function handle_member_edit_event(group_id, user_ids) {
const item = group; const item = group;
item.is_member = user_groups.is_user_in_group(group_id, people.my_current_user_id()); item.is_member = user_groups.is_user_in_group(group_id, people.my_current_user_id());
item.can_edit = settings_data.can_edit_user_group(item.id); item.can_edit = settings_data.can_manage_user_group(item.id);
const html = render_browse_user_groups_list_item(item); const html = render_browse_user_groups_list_item(item);
const $new_row = $(html); const $new_row = $(html);
@ -831,7 +831,7 @@ export function setup_page(callback) {
people.my_current_user_id(), people.my_current_user_id(),
item.id, item.id,
); );
item.can_edit = settings_data.can_edit_user_group(item.id); item.can_edit = settings_data.can_manage_user_group(item.id);
return render_browse_user_groups_list_item(item); return render_browse_user_groups_list_item(item);
}, },
filter: { filter: {
@ -956,7 +956,7 @@ export function initialize() {
const group_id = active_group_data.id; const group_id = active_group_data.id;
const user_group = user_groups.get_user_group_from_id(group_id); const user_group = user_groups.get_user_group_from_id(group_id);
if (!user_group || !settings_data.can_edit_user_group(group_id)) { if (!user_group || !settings_data.can_manage_user_group(group_id)) {
return; return;
} }
function deactivate_user_group() { function deactivate_user_group() {

View File

@ -61,7 +61,7 @@ function format_member_list_elem(person: User): string {
user_id: person.user_id, user_id: person.user_id,
is_current_user: person.user_id === current_user.user_id, is_current_user: person.user_id === current_user.user_id,
email: person.delivery_email, email: person.delivery_email,
can_remove_subscribers: settings_data.can_edit_user_group(current_group_id), can_remove_subscribers: settings_data.can_manage_user_group(current_group_id),
for_user_group_members: true, for_user_group_members: true,
img_src: people.small_avatar_url_for_person(person), img_src: people.small_avatar_url_for_person(person),
}); });
@ -147,7 +147,7 @@ export function rerender_members_list({
}): void { }): void {
$parent_container.find(".member-list-box").html( $parent_container.find(".member-list-box").html(
render_user_group_members_table({ render_user_group_members_table({
can_edit: settings_data.can_edit_user_group(group.id), can_edit: settings_data.can_manage_user_group(group.id),
}), }),
); );
member_list_widget = make_list_widget({ member_list_widget = make_list_widget({
@ -356,7 +356,7 @@ function remove_member({
}); });
} }
if (people.is_my_user_id(target_user_id) && !settings_data.can_edit_user_group(group_id)) { if (people.is_my_user_id(target_user_id) && !settings_data.can_manage_user_group(group_id)) {
const html_body = render_leave_user_group_modal({ const html_body = render_leave_user_group_modal({
message: $t({ message: $t({
defaultMessage: "Once you leave this group, you will not be able to rejoin.", defaultMessage: "Once you leave this group, you will not be able to rejoin.",

View File

@ -339,7 +339,7 @@ run_test("user_can_create_multiuse_invite", () => {
); );
}); });
run_test("can_edit_user_group", () => { run_test("can_manage_user_group", () => {
const admins = { const admins = {
description: "Administrators", description: "Administrators",
name: "role:administrators", name: "role:administrators",
@ -396,12 +396,12 @@ run_test("can_edit_user_group", () => {
}); });
page_params.is_spectator = true; page_params.is_spectator = true;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_manage_user_group(students.id));
page_params.is_spectator = false; page_params.is_spectator = false;
realm.realm_can_manage_all_groups = admins.id; realm.realm_can_manage_all_groups = admins.id;
current_user.user_id = 3; current_user.user_id = 3;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_manage_user_group(students.id));
// non-admin group_creator // non-admin group_creator
current_user.user_id = 4; current_user.user_id = 4;
@ -409,22 +409,22 @@ run_test("can_edit_user_group", () => {
// admin user // admin user
current_user.user_id = 1; current_user.user_id = 1;
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_manage_user_group(students.id));
// moderator user // moderator user
current_user.user_id = 2; current_user.user_id = 2;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_manage_user_group(students.id));
realm.realm_can_manage_all_groups = members.id; realm.realm_can_manage_all_groups = members.id;
current_user.user_id = 3; current_user.user_id = 3;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_manage_user_group(students.id));
current_user.user_id = 2; current_user.user_id = 2;
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_manage_user_group(students.id));
realm.realm_can_manage_all_groups = admins.id; realm.realm_can_manage_all_groups = admins.id;
current_user.user_id = 2; current_user.user_id = 2;
assert.ok(!settings_data.can_edit_user_group(students.id)); assert.ok(!settings_data.can_manage_user_group(students.id));
const event = { const event = {
group_id: students.id, group_id: students.id,
@ -433,10 +433,10 @@ run_test("can_edit_user_group", () => {
}, },
}; };
user_groups.update(event); user_groups.update(event);
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_manage_user_group(students.id));
current_user.user_id = 3; current_user.user_id = 3;
assert.ok(settings_data.can_edit_user_group(students.id)); assert.ok(settings_data.can_manage_user_group(students.id));
}); });
run_test("type_id_to_string", () => { run_test("type_id_to_string", () => {
@ -506,10 +506,10 @@ run_test("user_can_create_user_groups", () => {
test_realm_group_settings("realm_can_create_groups", settings_data.user_can_create_user_groups); test_realm_group_settings("realm_can_create_groups", settings_data.user_can_create_user_groups);
}); });
run_test("user_can_edit_all_user_groups", () => { run_test("user_can_manage_all_groups", () => {
test_realm_group_settings( test_realm_group_settings(
"realm_can_manage_all_groups", "realm_can_manage_all_groups",
settings_data.user_can_edit_all_user_groups, settings_data.user_can_manage_all_groups,
); );
}); });

View File

@ -135,7 +135,7 @@ def check_permission_for_managing_all_groups(
) -> bool: ) -> bool:
""" """
Given a user and a group in the same realm, checks if the user Given a user and a group in the same realm, checks if the user
can manage the group through the legacy can_edit_all_user_groups can manage the group through the legacy can_manage_all_groups
permission, which is a permission that requires either certain roles permission, which is a permission that requires either certain roles
or membership in the group itself to be used. or membership in the group itself to be used.
""" """
@ -146,8 +146,8 @@ def check_permission_for_managing_all_groups(
if user_group.creator and user_group.creator.id == user_profile.id: if user_group.creator and user_group.creator.id == user_profile.id:
return True return True
can_edit_all_user_groups = user_profile.can_edit_all_user_groups() can_manage_all_groups = user_profile.can_manage_all_groups()
if can_edit_all_user_groups: if can_manage_all_groups:
if user_profile.is_realm_admin or user_profile.is_moderator: if user_profile.is_realm_admin or user_profile.is_moderator:
return True return True

View File

@ -874,7 +874,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
def can_create_user_groups(self) -> bool: def can_create_user_groups(self) -> bool:
return self.has_permission("can_create_groups") return self.has_permission("can_create_groups")
def can_edit_all_user_groups(self) -> bool: def can_manage_all_groups(self) -> bool:
return self.has_permission("can_manage_all_groups") return self.has_permission("can_manage_all_groups")
def can_move_messages_to_another_topic(self) -> bool: def can_move_messages_to_another_topic(self) -> bool: