Skip to content

Commit

Permalink
Feature/ Remove calls to add and remove members endpoints from v2 cli…
Browse files Browse the repository at this point in the history
…ent (#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 <[email protected]>
  • Loading branch information
xkopenreview and melisabok authored Jul 23, 2024
1 parent 43140e3 commit 38dd2cd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 42 deletions.
65 changes: 27 additions & 38 deletions openreview/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
24 changes: 22 additions & 2 deletions tests/test_profile_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,8 +1915,28 @@ def test_remove_email_address(self, openreview_client, helpers):
assert openreview_client.get_group('[email protected]').members == ['~Harold_Last1']
with pytest.raises(openreview.OpenReviewException, match=r'Group Not Found: [email protected]'):
assert openreview_client.get_group('[email protected]').members == []
openreview_client.add_members_to_group('~Harold_Last1', '[email protected]')
openreview_client.add_members_to_group('[email protected]', '~Harold_Last1')

openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit',
signatures = ['~Super_User1'],
group = openreview.api.Group(
id = '~Harold_Last1',
members = {
'append': ['[email protected]']
},
signatures = ['~Super_User1']
)
)

openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit',
signatures = ['~Super_User1'],
group = openreview.api.Group(
id = '[email protected]',
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'):
Expand Down
26 changes: 24 additions & 2 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '[email protected]')
openreview_client.add_members_to_group(openreview_client.get_group('[email protected]'), '~SomeFirstName_User1')

openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit',
signatures = ['~Super_User1'],
group = openreview.api.Group(
id = '~SomeFirstName_User1',
members = {
'append': ['[email protected]']
},
signatures = ['~Super_User1']
)
)

openreview_client.post_group_edit(invitation = 'openreview.net/-/Edit',
signatures = ['~Super_User1'],
group = openreview.api.Group(
id = '[email protected]',
members = {
'append': ['~SomeFirstName_User1']
},
signatures = ['~Super_User1']
)
)


profiles = openreview.tools.get_profiles(
openreview_client, ids_or_emails=['~SomeFirstName_User1', '~Another_Name1', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '~Test_Name1'], as_dict=True
)
Expand Down

0 comments on commit 38dd2cd

Please sign in to comment.