From 4571a0ad711e4314557994090381f8647644fed5 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 19 Aug 2011 12:07:46 -0400 Subject: [PATCH] Fix Bug 825344 - Only set project watches once Fixed a logic bug caused by implied group membership where users were having project watches re-added for project they had implied membership in. Also added openstack-release to the set of teams polled. Change-Id: Ibeb97519427fe1a461ebe74228e9f75d31d518d7 --- gerrit/update_gerrit_users.py | 41 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/gerrit/update_gerrit_users.py b/gerrit/update_gerrit_users.py index 980a72ba..3279f79c 100755 --- a/gerrit/update_gerrit_users.py +++ b/gerrit/update_gerrit_users.py @@ -309,24 +309,29 @@ for (username, user_details) in users.items(): if account_id is not None: # account_group_members for group in user_details['add_groups']: - if not cur.execute("""select account_id from account_group_members - where account_id = %s and group_id = %s""", - (account_id, group_ids[group])): - cur.execute("""insert into account_group_members - (account_id, group_id) - values (%s, %s)""", (account_id, group_ids[group])) - os_project_name = "openstack/%s" % group - if os_project_name in projects: - for current_group in group_implies_groups[group_ids[group]]: - cur.execute("""insert into account_project_watches - select "Y", "N", "N", g.account_id, %s, "*" - from account_group_members g - where g.group_id = %s and g.account_id not in - (select w.account_id from - account_project_watches w - where g.account_id = w.account_id and - w.project_name = %s)""", - (os_project_name, current_group, os_project_name)) + os_project_name = "openstack/%s" % group + add_groups = group_implies_groups[group_ids[group]] + add_groups.append(group_ids[group]) + for current_group in add_groups: + if not cur.execute("""select account_id from account_group_members + where account_id = %s and group_id = %s""", + (account_id, current_group)): + # The current user does not exist in the group. Add it. + cur.execute("""insert into account_group_members + (account_id, group_id) + values (%s, %s)""", (account_id, current_group)) + if os_project_name.endswith("-core"): + os_project_name = os_project_name[:-5] + if os_project_name in projects: + if not cur.execute("""select account_id + from account_project_watches + where account_id = %s + and project_name = %s""", + (account_id, os_project_name)): + cur.execute("""insert into account_project_watches + VALUES + ("Y", "N", "N", %s, %s, "*")""", + (account_id, os_project_name)) for group in user_details['rm_groups']: cur.execute("""delete from account_group_members where account_id = %s and group_id = %s""",