Skip to content

Commit a468900

Browse files
authored
Merge pull request #3675 from athenianco/duplicated-team-members
Duplicated team members
2 parents 42484eb + a0f9bd5 commit a468900

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

server/athenian/api/controllers/settings_controller.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from bisect import bisect_left, bisect_right
2+
from collections import defaultdict
23
from datetime import datetime, timezone
34
import logging
45
import re
@@ -253,21 +254,27 @@ async def set_jira_identities(request: AthenianWebRequest, body: dict) -> web.Re
253254
),
254255
]
255256
github_id_rows, jira_id_rows = await gather(*tasks)
256-
github_id_map = {r[GitHubUser.login.name]: r[GitHubUser.node_id.name] for r in github_id_rows}
257-
jira_id_map = {r[JIRAUser.display_name.name]: r[JIRAUser.id.name] for r in jira_id_rows}
257+
github_id_map = defaultdict(list)
258+
for r in github_id_rows:
259+
github_id_map[r[GitHubUser.login.name]].append(
260+
r[GitHubUser.node_id.name])
261+
262+
jira_id_map = {
263+
r[JIRAUser.display_name.name]: r[JIRAUser.id.name]
264+
for r in jira_id_rows
265+
}
258266
cleared_github_ids = set()
259267
updated_maps = []
260268
for i, change in enumerate(request_model.changes):
261-
try:
262-
github_id = github_id_map[change.developer_id.rsplit("/", 1)[1]]
263-
except KeyError:
269+
github_ids = github_id_map[change.developer_id.rsplit("/", 1)[1]]
270+
if len(github_ids) == 0:
264271
raise ResponseError(
265272
InvalidRequestError(
266273
detail="Developer was not found.", pointer=f".changes[{i}].developer_id",
267274
),
268275
)
269276
if change.jira_name is None:
270-
cleared_github_ids.add(github_id)
277+
cleared_github_ids.update(github_ids)
271278
continue
272279
if not change.jira_name:
273280
raise ResponseError(
@@ -283,7 +290,9 @@ async def set_jira_identities(request: AthenianWebRequest, body: dict) -> web.Re
283290
detail="JIRA user was not found.", pointer=f".changes[{i}].jira_name",
284291
),
285292
)
286-
updated_maps.append((github_id, jira_id))
293+
294+
for github_id in github_ids:
295+
updated_maps.append((github_id, jira_id))
287296

288297
try:
289298
async with sdb.connection() as sdb_conn:

server/athenian/api/internal/jira.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,18 @@ async def _load_mapped_jira_users(
348348
get_jira_id(account, sdb, cache),
349349
]
350350
map_rows, jira_id = await gather(*tasks)
351-
jira_user_ids = {r[1]: r[0] for r in map_rows}
351+
gh_uid_to_jira_uid = {r["github_user_id"]: r["jira_user_id"] for r in map_rows}
352352
name_rows = await mdb.fetch_all(
353353
select(JIRAUser.id, JIRAUser.display_name).where(
354-
JIRAUser.acc_id == jira_id, JIRAUser.id.in_(jira_user_ids),
354+
JIRAUser.acc_id == jira_id, JIRAUser.id.in_(
355+
gh_uid_to_jira_uid.values()),
355356
),
356357
)
357-
return {jira_user_ids[row[0]]: row[1] for row in name_rows}
358+
jira_uid_to_jira_name = {r["id"]: r["display_name"] for r in name_rows}
359+
return {
360+
gh_uid: jira_uid_to_jira_name[jira_uid]
361+
for gh_uid, jira_uid in gh_uid_to_jira_uid.items()
362+
}
358363

359364

360365
@cached(

0 commit comments

Comments
 (0)