Skip to content

Commit

Permalink
Fix: Preserve transitive membership (#2429)
Browse files Browse the repository at this point in the history
* Fix: Preserve transitive membership

* Update openreview/api/client.py

---------

Co-authored-by: celestemartinez <[email protected]>
  • Loading branch information
carlosmondra and celestemartinez authored Nov 20, 2024
1 parent ae2acb8 commit fcfc1f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
16 changes: 12 additions & 4 deletions openreview/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,18 @@ def update_relation_readers(self, update):
return response.json()


def get_groups(self, id=None, prefix=None, member=None, signatory=None, web=None, limit=None, offset=None, after=None, stream=None, sort=None, with_count=False):
def get_groups(self, id=None, prefix=None, member=None, members=None, signatory=None, web=None, limit=None, offset=None, after=None, stream=None, sort=None, with_count=False):
"""
Gets list of Group objects based on the filters provided. The Groups that will be returned match all the criteria passed in the parameters.
:param id: id of the Group
:type id: str, optional
:param prefix: Prefix that matches several Group ids
:type prefix: str, optional
:param member: Groups that contain this member
:param member: Groups that that are transitive members of the member value
:type member: str, optional
:param members: Groups that contain the value members in the members field
:type members: str, optional
:param signatory: Groups that contain this signatory
:type signatory: str, optional
:param web: Groups that contain a web field value
Expand All @@ -798,6 +800,8 @@ def get_groups(self, id=None, prefix=None, member=None, signatory=None, web=None
params['prefix'] = prefix
if member is not None:
params['member'] = member
if members is not None:
params['members'] = members
if signatory is not None:
params['signatory'] = signatory
if sort is not None:
Expand All @@ -822,7 +826,7 @@ def get_groups(self, id=None, prefix=None, member=None, signatory=None, web=None

return groups

def get_all_groups(self, id=None, parent=None, prefix=None, member=None, domain=None, signatory=None, web=None, sort=None, with_count=False):
def get_all_groups(self, id=None, parent=None, prefix=None, member=None, members=None, domain=None, signatory=None, web=None, sort=None, with_count=False):
"""
Gets list of Group objects based on the filters provided. The Groups that will be returned match all the criteria passed in the parameters.
Expand All @@ -832,8 +836,10 @@ def get_all_groups(self, id=None, parent=None, prefix=None, member=None, domain=
:type parent: str, optional
:param prefix: Prefix that matches several Group ids
:type prefix: str, optional
:param member: Groups that contain this member
:param member: Groups that that are trasitive members of the member value
:type member: str, optional
:param members: Groups that contain the value members in the members field
:type members: str, optional
:param signatory: Groups that contain this signatory
:type signatory: str, optional
:param web: Groups that contain a web field value
Expand All @@ -859,6 +865,8 @@ def get_all_groups(self, id=None, parent=None, prefix=None, member=None, domain=
params['prefix'] = prefix
if member is not None:
params['member'] = member
if members is not None:
params['members'] = members
if signatory is not None:
params['signatory'] = signatory
if domain is not None:
Expand Down
13 changes: 12 additions & 1 deletion openreview/profile/process/request_remove_email_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def process(client, edit, invitation):
profile = client.get_profile(profile_id)
preferred_id = profile.get_preferred_name()
preferred_name = profile.get_preferred_name(pretty=True)
preferred_email = profile.get_preferred_email()

if preferred_email == email:
print('Cannot remove preferred email')
raise openreview.OpenReviewException('Cannot remove preferred email')

baseurl_v1 = 'http://localhost:3000'

Expand Down Expand Up @@ -113,6 +118,13 @@ def replace_group_members(group, current_member, new_member):
tail_edges = client.get_edges(tail=email, limit=1)
if head_edges or tail_edges:
client.rename_edges(email, profile.id)

print('Preserve transitive members')
tilde_groups = [member for member in client.get_group(email).members if member.startswith('~')]
client.add_members_to_group(preferred_email, tilde_groups)
tilde_groups = [g for g in client.get_all_groups(members=email) if g.id.startswith('~')]
for tilde_group in tilde_groups:
client.add_members_to_group(tilde_group, [preferred_email])

print('Replace all the group members that contain the email to remove')
memberships = [ g for g in client.get_all_groups(member=email) if email in g.members ]
Expand All @@ -134,7 +146,6 @@ def replace_group_members(group, current_member, new_member):
replace_group_members(group, email, profile.id)

print('Post a profile reference to remove the email')

client.post_profile(openreview.Profile(
referent = profile.id,
invitation = '~/-/invitation',
Expand Down
30 changes: 30 additions & 0 deletions tests/test_profile_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,36 @@ def test_remove_email_address(self, openreview_client, helpers):
assert openreview_client.get_group('~Harold_Last1').members == ['[email protected]']
assert openreview_client.get_group('[email protected]').members == ['~Harold_Last1']

def test_remove_email_from_merged_profile(self, openreview_client, helpers):

tidus_client = helpers.create_user('[email protected]', 'Tidus', 'Mondragon', alternates=[], institution='google.com')

profile = tidus_client.get_profile()
profile.content['homepage'] = 'https://carlos.google.com'

tidus_client.post_profile(profile)

helpers.create_user('[email protected]', 'Tidus', 'Chapa', alternates=[], institution='deepmind.com')

openreview_client.merge_profiles('~Tidus_Mondragon1', '~Tidus_Chapa1')

edit = openreview_client.post_note_edit(
invitation = 'openreview.net/Support/-/Profile_Email_Removal',
signatures=['openreview.net/Support'],
note = openreview.api.Note(
content={
'email': { 'value': '[email protected]' },
'profile_id': { 'value':'~Tidus_Mondragon1' },
'comment': { 'value': 'email is silly' }
}
)
)

helpers.await_queue_edit(openreview_client, edit_id=edit['id'])

profile = tidus_client.get_profile()

tidus_client.post_profile(profile)

def test_update_relation_after_signup(self, helpers):

Expand Down

0 comments on commit fcfc1f6

Please sign in to comment.