From 38dd2cd76bd46407ab7341e013e5dba2f7c79c4d Mon Sep 17 00:00:00 2001 From: xkopenreview <60613434+xkopenreview@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:54:15 -0400 Subject: [PATCH] Feature/ Remove calls to add and remove members endpoints from v2 client (#2277) * remove call to members from add_member and remove_member methods of v2 client * pass edit invitation to edit group * revert change, add members using an edit * add whole path * add signatures * use a group edit --------- Co-authored-by: Melisa Bok <545506+melisabok@users.noreply.github.com> --- openreview/api/client.py | 65 +++++++++++++------------------- tests/test_profile_management.py | 24 +++++++++++- tests/test_tools.py | 26 ++++++++++++- 3 files changed, 73 insertions(+), 42 deletions(-) diff --git a/openreview/api/client.py b/openreview/api/client.py index f6ec8eaeb..f4aed25bc 100644 --- a/openreview/api/client.py +++ b/openreview/api/client.py @@ -1839,24 +1839,18 @@ def add_members_to_group(self, group, members): """ def add_member(group, members): group = self.get_group(group) if type(group) in string_types else group - if group.invitations: - self.post_group_edit(invitation = f'{group.domain}/-/Edit', - signatures = group.signatures, - group = Group( - id = group.id, - members = { - 'append': list(set(members)) - } - ), - readers=group.signatures, - writers=group.signatures - ) - return self.get_group(group.id) - else: - if members: - response = self.session.put(self.groups_url + '/members', json = {'id': group.id, 'members': members}, headers = self.headers) - response = self.__handle_response(response) - return Group.from_json(response.json()) + self.post_group_edit(invitation = f'{group.domain}/-/Edit', + signatures = group.signatures, + group = Group( + id = group.id, + members = { + 'append': list(set(members)) + } + ), + readers=group.signatures, + writers=group.signatures + ) + return self.get_group(group.id) member_type = type(members) if member_type in string_types: @@ -1880,26 +1874,21 @@ def remove_members_from_group(self, group, members): def remove_member(group, members): members_to_remove = list(set(members)) group = self.get_group(group if type(group) in string_types else group.id) - if group.invitations: - - members_to_remove = group.transform_to_anon_ids(members_to_remove) - - self.post_group_edit(invitation = f'{group.domain}/-/Edit', - signatures = group.signatures, - group = Group( - id = group.id, - members = { - 'remove': members_to_remove - } - ), - readers=group.signatures, - writers=group.signatures - ) - return self.get_group(group.id) - else: - response = self.session.delete(self.groups_url + '/members', json = {'id': group.id, 'members': members}, headers = self.headers) - response = self.__handle_response(response) - return Group.from_json(response.json()) + + members_to_remove = group.transform_to_anon_ids(members_to_remove) + + self.post_group_edit(invitation = f'{group.domain}/-/Edit', + signatures = group.signatures, + group = Group( + id = group.id, + members = { + 'remove': members_to_remove + } + ), + readers=group.signatures, + writers=group.signatures + ) + return self.get_group(group.id) member_type = type(members) if member_type in string_types: diff --git a/tests/test_profile_management.py b/tests/test_profile_management.py index 722fedecb..ac58d0225 100644 --- a/tests/test_profile_management.py +++ b/tests/test_profile_management.py @@ -1915,8 +1915,28 @@ def test_remove_email_address(self, openreview_client, helpers): assert openreview_client.get_group('harold@profile.org').members == ['~Harold_Last1'] with pytest.raises(openreview.OpenReviewException, match=r'Group Not Found: alternate_harold@profile.org'): assert openreview_client.get_group('alternate_harold@profile.org').members == [] - openreview_client.add_members_to_group('~Harold_Last1', 'alternate_harold@profile.org') - openreview_client.add_members_to_group('alternate_harold@profile.org', '~Harold_Last1') + + openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit', + signatures = ['~Super_User1'], + group = openreview.api.Group( + id = '~Harold_Last1', + members = { + 'append': ['alternate_harold@profile.org'] + }, + signatures = ['~Super_User1'] + ) + ) + + openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit', + signatures = ['~Super_User1'], + group = openreview.api.Group( + id = 'alternate_harold@profile.org', + members = { + 'append': ['~Harold_Last1'] + }, + signatures = ['~Super_User1'] + ) + ) ## Try to remove the unexisting name and get an error with pytest.raises(openreview.OpenReviewException, match=r'Profile not found for ~Harold_Lastt1'): diff --git a/tests/test_tools.py b/tests/test_tools.py index 4ccf4d41f..4fcb4c235 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -649,8 +649,30 @@ def test_group(self, client): assert openReviewError.value.args[0].get('name') == 'ForbiddenError' def test_get_profiles_as_dict(self, openreview_client, test_client): - openreview_client.add_members_to_group(openreview_client.get_group('~SomeFirstName_User1'), 'alternate@mail.com') - openreview_client.add_members_to_group(openreview_client.get_group('alternate@mail.com'), '~SomeFirstName_User1') + + openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit', + signatures = ['~Super_User1'], + group = openreview.api.Group( + id = '~SomeFirstName_User1', + members = { + 'append': ['alternate@mail.com'] + }, + signatures = ['~Super_User1'] + ) + ) + + openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit', + signatures = ['~Super_User1'], + group = openreview.api.Group( + id = 'alternate@mail.com', + members = { + 'append': ['~SomeFirstName_User1'] + }, + signatures = ['~Super_User1'] + ) + ) + + profiles = openreview.tools.get_profiles( openreview_client, ids_or_emails=['~SomeFirstName_User1', '~Another_Name1', 'user@gmail.com', 'test_user@mail.com', 'test@mail.com', 'alternate@mail.com', '~Test_Name1'], as_dict=True )