def get_teamlead_specialtext(self, user: User) -> str: """Return special text for team leads.""" teams: List[Team] = self.facade.query_or( Team, [("team_leads", user.github_id)]) ctx: Dict[str, str] = {} for team in teams: # Find a random member in the team and use them to replace you. If # we cannot another random member, just say that we deleted the # team. members = list(team.members - team.team_leads) if members: random.shuffle(members) for gh_id in members: # Try all members until we exhaust the pool and then quit # trying users = get_users_by_ghid(self.facade, [gh_id]) if len(users) == 0: continue ctx[team.github_team_name] =\ f"replacing you with <@{users[0].slack_id}>" break if team.github_team_name not in ctx: ctx[team.github_team_name] =\ "cannot find your replacement; deleting team" else: ctx[team.github_team_name] =\ "cannot find your replacement; deleting team" return "\n".join(map(lambda i: f"*Team {i[0]}*: {i[1]}", ctx.items()))
def get_leads(self, user: User) -> List[User]: """Return a list of team leads user is in a team with.""" teams: List[Team] = self.facade.query(Team) leads: List[User] = [] for team in teams: if len(team.team_leads) > 0 and team.has_member(user.github_id): leads.extend( get_users_by_ghid(self.facade, list(team.team_leads))) if team.github_team_name != "all" and\ team.has_member(user.github_id): # Some teams aren't up to date and don't have team leads, so we # have to add them manually. Just don't add the 'all' team and # we'll be fine. members = get_users_by_ghid(self.facade, list(team.members)) for m in members: if m.permissions_level == Permissions.team_lead or\ m.permissions_level == Permissions.admin: leads.append(m) return leads
def test_get_users_by_ghid(self): self.assertCountEqual( get_users_by_ghid( self.db, [self.u0.github_id, self.u1.github_id, self.u2.github_id]), [self.u0, self.u1, self.u2])
def test_get_users_by_ghid_empty_list(self): self.assertEqual(get_users_by_ghid(self.db, []), [])