Commit f2809fb7 authored by Petar Hristov's avatar Petar Hristov 💬
Browse files

Merge branch 'Product/1548-projectInviteMngmnt' into 'Sprint/2021-12'

Product/1548 project invite mngmnt

See merge request !159
parents 8d904fcd 96be7d0c
...@@ -600,7 +600,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -600,7 +600,7 @@ namespace Coscine.Api.Project.Controllers
return Unauthorized($"You are not an owner of the project."); return Unauthorized($"You are not an owner of the project.");
} }
var invitations = _invitationModel.GetAllWhere(x => x.Project == projectId && x.Expiration > DateTime.UtcNow) var invitations = _invitationModel.GetAllWhere(x => x.Project == projectId)
.Select(x => new InvitationReturnObject .Select(x => new InvitationReturnObject
{ {
Id = x.Id, Id = x.Id,
...@@ -652,11 +652,22 @@ namespace Coscine.Api.Project.Controllers ...@@ -652,11 +652,22 @@ namespace Coscine.Api.Project.Controllers
x.Expiration > DateTime.UtcNow x.Expiration > DateTime.UtcNow
); );
if (invitations != null && invitations.Any()) if (invitations.Any())
{ {
return BadRequest("This invitee already has a valid invitation to this project."); return BadRequest("This invitee already has a valid invitation to this project.");
} }
var expiredInvitations = _invitationModel.GetAllWhere(
x => x.Project == sendInvitationObject.Project &&
x.InviteeEmail == sendInvitationObject.Email &&
x.Expiration <= DateTime.UtcNow
);
foreach (var expiredInvitation in expiredInvitations)
{
_invitationModel.Delete(expiredInvitation);
}
var token = _invitationModel.CreateInvitation(sendInvitationObject.Project, user.Id, sendInvitationObject.Role, sendInvitationObject.Email); var token = _invitationModel.CreateInvitation(sendInvitationObject.Project, user.Id, sendInvitationObject.Role, sendInvitationObject.Email);
var body = new JObject var body = new JObject
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment