Skip to content

Commit

Permalink
Prevent adding the same user multiple times to a project
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Jul 16, 2024
1 parent 0ae8882 commit cf9aa67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/IPA.Bcfier.App/Controllers/ProjectUsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public async Task<IActionResult> AddUserToProjectAsync(Guid projectId, [FromBody
UserId = dbUser.Id,
ProjectId = projectId
};

identifierExistsAlready = await _context.ProjectUsers.AnyAsync(pu => pu.ProjectId == projectId
&& pu.UserId == projectUser.UserId);
if (identifierExistsAlready)
{
return BadRequest(new ApiError("This user assignment already exists."));
}

_context.ProjectUsers.Add(projectUser);
await _context.SaveChangesAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export class ProjectDetailsComponent implements OnDestroy {
},
error: () => {
this.notificationsService.error('Failed to add the user');
this.users$ = this.getProjectUsers(this.data.id);
this.filterUsers();
this.cdr.detectChanges();
},
})
);
Expand Down

0 comments on commit cf9aa67

Please sign in to comment.