user_groups: Swap parameter order in is_direct_member_of function.

This commit swaps the parameter order in is_direct_member_of
function to have user_id followed by user_group_id since user_id
is a member of user_group_id and not the other way around.
This commit is contained in:
Sahil Batra 2022-05-05 13:34:57 +05:30 committed by Tim Abbott
parent 6bca2453cf
commit c52a135eb3
7 changed files with 11 additions and 11 deletions

View File

@ -52,7 +52,7 @@ function get_user_group_from_name(name) {
return user_group_map.get(name);
}
function is_member_of_user_group(user_group_id, user_id) {
function is_member_of_user_group(user_id, user_group_id) {
assert.equal(user_group_id, staff_group.id);
assert.equal(user_id, my_id);
return true;

View File

@ -55,7 +55,7 @@ test_ui("can_edit", () => {
assert.ok(!settings_user_groups.can_edit(1));
settings_data.user_can_edit_user_groups = () => true;
user_groups.is_direct_member_of = (group_id, user_id) => {
user_groups.is_direct_member_of = (user_id, group_id) => {
assert.equal(group_id, 1);
assert.equal(user_id, undefined);
return false;
@ -71,7 +71,7 @@ test_ui("can_edit", () => {
page_params.is_admin = false;
page_params.is_moderator = false;
user_groups.is_direct_member_of = (group_id, user_id) => {
user_groups.is_direct_member_of = (user_id, group_id) => {
assert.equal(group_id, 1);
assert.equal(user_id, undefined);
return true;

View File

@ -90,8 +90,8 @@ run_test("user_groups", () => {
const groups_of_users_nomatch = user_groups.get_user_groups_of_user(user_id_not_in_any_group);
assert.equal(groups_of_users_nomatch.length, 0);
assert.ok(!user_groups.is_direct_member_of(admins.id, 4));
assert.ok(user_groups.is_direct_member_of(admins.id, 3));
assert.ok(!user_groups.is_direct_member_of(4, admins.id));
assert.ok(user_groups.is_direct_member_of(3, admins.id));
user_groups.add_members(all.id, [5, 4]);
assert.deepEqual(user_groups.get_user_group_from_id(all.id).members, new Set([1, 2, 3, 5, 4]));
@ -119,7 +119,7 @@ run_test("user_groups", () => {
assert.equal(user_groups.get_realm_user_groups().length, 0);
blueslip.expect("error", "Could not find user group with ID -1");
assert.equal(user_groups.is_direct_member_of(-1, 15), false);
assert.equal(user_groups.is_direct_member_of(15, -1), false);
blueslip.expect("error", "Could not find user group with ID -9999", 4);
user_groups.add_members(-9999);

View File

@ -217,7 +217,7 @@ function parse_with_options({raw_content, helper_config, options}) {
display_text = "@" + group.name;
classes = "user-group-mention";
if (
helper_config.is_member_of_user_group(group.id, helper_config.my_user_id())
helper_config.is_member_of_user_group(helper_config.my_user_id(), group.id)
) {
// Mentioned the current user's group.
mentioned_group = true;

View File

@ -113,7 +113,7 @@ export const update_elements = ($content) => {
const my_user_id = people.my_current_user_id();
// Mark user group you're a member of.
if (user_groups.is_direct_member_of(user_group_id, my_user_id)) {
if (user_groups.is_direct_member_of(my_user_id, user_group_id)) {
$(this).addClass("user-mention-me");
}

View File

@ -47,7 +47,7 @@ export function can_edit(group_id) {
return true;
}
return user_groups.is_direct_member_of(group_id, people.my_current_user_id());
return user_groups.is_direct_member_of(people.my_current_user_id(), group_id);
}
export function populate_user_groups() {

View File

@ -79,7 +79,7 @@ export function get_realm_user_groups(): UserGroup[] {
return user_groups.filter((group) => !group.is_system_group);
}
export function is_direct_member_of(user_group_id: number, user_id: number): boolean {
export function is_direct_member_of(user_id: number, user_group_id: number): boolean {
const user_group = user_group_by_id_dict.get(user_group_id);
if (user_group === undefined) {
blueslip.error(`Could not find user group with ID ${user_group_id}`);
@ -149,7 +149,7 @@ export function is_user_group(item: User | UserGroup): item is UserGroup {
export function get_user_groups_of_user(user_id: number): UserGroup[] {
const user_groups_realm = get_realm_user_groups();
const groups_of_user = user_groups_realm.filter((group) =>
is_direct_member_of(group.id, user_id),
is_direct_member_of(user_id, group.id),
);
return groups_of_user;
}