Skip to content

Commit 2599ad6

Browse files
authored
Merge pull request #1560 from Northeastern-Electric-Racing/1517-leads-of-teams-should-be-able-to-add-members
#1517 updated teamsRouter to check if user is lead of team before edi…
2 parents 9f3c785 + c945e15 commit 2599ad6

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/backend/src/services/teams.services.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class TeamsService {
4747
* @param teamId a id of team to be updated
4848
* @param userIds a array of user Ids that replaces team's old members
4949
* @returns a updated team
50-
* @throws if the team is not found, the submitter has no priviledge, or any user from the given userIds does not exist
50+
* @throws if the team is not found, the submitter has no privilege, or any user from the given userIds does not exist
5151
*/
5252
static async setTeamMembers(submitter: User, teamId: string, userIds: number[]): Promise<Team> {
5353
// find and verify the given teamId exist
@@ -56,9 +56,14 @@ export default class TeamsService {
5656
...teamQueryArgs
5757
});
5858

59-
if (!team) throw new NotFoundException('Team', teamId);
60-
if (!isAdmin(submitter.role) && submitter.userId !== team.headId)
61-
throw new AccessDeniedException('you must be an admin or the team head to update the members!');
59+
if (!team) {
60+
throw new NotFoundException('Team', teamId);
61+
}
62+
63+
const isTeamLead = team.leads.some((lead) => lead.userId === submitter.userId);
64+
65+
if (!isAdmin(submitter.role) && submitter.userId !== team.headId && !isTeamLead)
66+
throw new AccessDeniedException('you must be an admin, the team head, or a team lead to update the members!');
6267

6368
// this throws if any of the users aren't found
6469
const users = await getUsers(userIds);

src/frontend/src/pages/TeamsPage/TeamMembersPageBlock.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const TeamMembersPageBlock: React.FC<TeamMembersPageBlockProps> = ({ team }) =>
4343
return <LoadingIndicator />;
4444

4545
const hasPerms = isAdmin(user.role) || user.userId === team.head.userId;
46+
const editMembersPerms = hasPerms || team.leads.map((lead) => lead.userId).includes(user.userId);
4647

4748
const memberOptions = users
4849
.filter((user) => user.userId !== team.head.userId && !team.leads.map((lead) => lead.userId).includes(user.userId))
@@ -205,7 +206,7 @@ const TeamMembersPageBlock: React.FC<TeamMembersPageBlockProps> = ({ team }) =>
205206
<DetailDisplay label="Members" content={team.members.map((member) => fullNamePipe(member)).join(', ')} />
206207
</Grid>
207208
<Grid item xs={1} mt={-1} display={'flex'} justifyContent={'flex-end'}>
208-
{hasPerms && <IconButton children={<Edit />} onClick={() => setIsEditingMembers(true)} />}
209+
{editMembersPerms && <IconButton children={<Edit />} onClick={() => setIsEditingMembers(true)} />}
209210
</Grid>
210211
</Grid>
211212
);

0 commit comments

Comments
 (0)