Skip to content

Commit

Permalink
Don't error if same invite accepted twice
Browse files Browse the repository at this point in the history
If a user clicks the same invitation link twice, he should not get an
error message, he should just be taken to his home page. He's already a
member of the project, so trying to join the project should not error
but just succeed silently.
  • Loading branch information
rmunn committed Sep 25, 2024
1 parent d253132 commit bb04079
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions backend/LexBoxApi/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,23 @@ private void UpdateUserMemberships(LexAuthUser? jwtUser, User userEntity)
// This audience check is redundant now because of [RequireAudience(LexboxAudience.RegisterAccount, true)], but let's leave it in for safety
if (jwtUser?.Audience == LexboxAudience.RegisterAccount && jwtUser.Projects.Length > 0)
{
userEntity.Projects.AddRange(jwtUser.Projects.Select(p => new ProjectUsers { Role = p.Role, ProjectId = p.ProjectId }));
foreach (var p in jwtUser.Projects)
{
if (!userEntity.Projects.Exists(proj => proj.Id == p.ProjectId))
{
userEntity.Projects.Add(new ProjectUsers { Role = p.Role, ProjectId = p.ProjectId });
}
}
}
if (jwtUser?.Audience == LexboxAudience.RegisterAccount && jwtUser.Orgs.Length > 0)
{
userEntity.Organizations.AddRange(jwtUser.Orgs.Select(o => new OrgMember { Role = o.Role, OrgId = o.OrgId }));
foreach (var o in jwtUser.Orgs)
{
if (!userEntity.Organizations.Exists(org => org.Id == o.OrgId))
{
userEntity.Organizations.Add(new OrgMember { Role = o.Role, OrgId = o.OrgId });
}
}
}
}

Expand Down

0 comments on commit bb04079

Please sign in to comment.