Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invite fix #100

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Blueprint.Api/Blueprint.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<TargetFramework>net6.0</TargetFramework>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>CS1591</NoWarn>
Expand Down
38 changes: 29 additions & 9 deletions Blueprint.Api/Controllers/MselController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,25 @@ public async Task<IActionResult> Archive(Guid id, CancellationToken ct)
/// Joins the user to the msel based on a valid invitation
/// <para />
/// </remarks>
/// <param name="id"></param>
/// <param name="mselId"></param>
/// <param name="teamId"></param>
/// <param name="ct"></param>
[HttpPost("msels/{id}/join")]
[HttpPost("msels/{mselId}/join")]
[ProducesResponseType(typeof(Msel), (int)HttpStatusCode.Created)]
[SwaggerOperation(OperationId = "joinMselByInvitation")]
public async Task<IActionResult> JoinMsel(Guid id, CancellationToken ct)
public async Task<IActionResult> JoinMsel(Guid mselId, [FromQuery] string teamId, CancellationToken ct)
{
var msel = await _mselService.JoinMselByInvitationAsync(id, ct);
return Ok(msel);
Guid playerViewId;
Guid teamIdGuid;
if (Guid.TryParse(teamId, out teamIdGuid))
{
playerViewId = await _mselService.JoinMselByInvitationAsync(mselId, teamIdGuid, ct);
}
else
{
playerViewId = await _mselService.JoinMselByInvitationAsync(mselId, null, ct);
}
return Ok(playerViewId);
}

/// <summary>
Expand All @@ -431,14 +441,24 @@ public async Task<IActionResult> JoinMsel(Guid id, CancellationToken ct)
/// <para />
/// Returns the Player View ID that is being created
/// </remarks>
/// <param name="id"></param>
/// <param name="mselId"></param>
/// <param name="teamId"></param>
/// <param name="ct"></param>
[HttpPost("msels/{id}/launch")]
[HttpPost("msels/{mselId}/launch")]
[ProducesResponseType(typeof(Msel), (int)HttpStatusCode.Created)]
[SwaggerOperation(OperationId = "launchMselByInvitation")]
public async Task<IActionResult> LaunchMsel(Guid id, CancellationToken ct)
public async Task<IActionResult> LaunchMsel(Guid mselId, [FromQuery] string teamId, CancellationToken ct)
{
var launchedMsel = await _mselService.LaunchMselByInvitationAsync(id, ct);
Msel launchedMsel;
Guid teamIdGuid;
if (Guid.TryParse(teamId, out teamIdGuid))
{
launchedMsel = await _mselService.LaunchMselByInvitationAsync(mselId, teamIdGuid, ct);
}
else
{
launchedMsel = await _mselService.LaunchMselByInvitationAsync(mselId, null, ct);
}
return Ok(launchedMsel);
}

Expand Down
33 changes: 15 additions & 18 deletions Blueprint.Api/Services/MselService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public interface IMselService
Task<ViewModels.Msel> ArchiveAsync(Guid mselId, CancellationToken ct);
Task<IEnumerable<ViewModels.Msel>> GetMyJoinInvitationMselsAsync(CancellationToken ct);
Task<IEnumerable<ViewModels.Msel>> GetMyLaunchInvitationMselsAsync(CancellationToken ct);
Task<Guid> JoinMselByInvitationAsync(Guid mselId, CancellationToken ct); // returns the Player View ID
Task<Msel> LaunchMselByInvitationAsync(Guid mselId, CancellationToken ct); // returns the Player View ID
Task<Guid> JoinMselByInvitationAsync(Guid mselId, Guid? teamId, CancellationToken ct); // returns the Player View ID
Task<Msel> LaunchMselByInvitationAsync(Guid mselId, Guid? teamId, CancellationToken ct); // returns the newly created MSEL
}

public class MselService : IMselService
Expand Down Expand Up @@ -1735,12 +1735,9 @@ private async Task<string> FindDuplicateMselUsersAsync(Guid mselId, Cancellation
.ToListAsync(ct);
var mselIdList = invitationList
.Where(i =>
i.EmailDomain == null ||
i.EmailDomain.Length == 0 ||
(
i.EmailDomain.Contains('@') &&
email.EndsWith(i.EmailDomain)
)
i.EmailDomain != null &&
i.EmailDomain.Contains('@') &&
email.EndsWith(i.EmailDomain)
)
.Select(i => i.MselId);
var inviteMselList = await _context.Msels
Expand Down Expand Up @@ -1771,12 +1768,9 @@ private async Task<string> FindDuplicateMselUsersAsync(Guid mselId, Cancellation
.ToListAsync(ct);
var mselIdList = invitationList
.Where(i =>
i.EmailDomain == null ||
i.EmailDomain.Length == 0 ||
(
i.EmailDomain.Contains('@') &&
email.EndsWith(i.EmailDomain)
)
i.EmailDomain != null &&
i.EmailDomain.Contains('@') &&
email.EndsWith(i.EmailDomain)
)
.Select(i => i.MselId);
var mselList = await _context.Msels
Expand All @@ -1790,9 +1784,10 @@ private async Task<string> FindDuplicateMselUsersAsync(Guid mselId, Cancellation
/// Joins the current user to a MSEL that has already been launched
/// </summary>
/// <param name="mselId"></param>
/// <param name="teamId"></param>
/// <param name="ct"></param>
/// <returns>The Player View ID</returns>
public async Task<Guid> JoinMselByInvitationAsync(Guid mselId, CancellationToken ct)
public async Task<Guid> JoinMselByInvitationAsync(Guid mselId, Guid? teamId, CancellationToken ct)
{
var msel = await _context.Msels.SingleOrDefaultAsync(m => m.Id == mselId);
if (msel == null)
Expand All @@ -1816,7 +1811,8 @@ public async Task<Guid> JoinMselByInvitationAsync(Guid mselId, CancellationToken
i.ExpirationDateTime > now &&
i.UserCount < i.MaxUsersAllowed &&
i.Msel.Status == ItemStatus.Deployed &&
i.MselId == mselId)
i.MselId == mselId &&
(teamId == null || teamId == i.TeamId))
.Include(i => i.Team)
.ToListAsync(ct);
var invitation = invitationList
Expand Down Expand Up @@ -1846,7 +1842,7 @@ public async Task<Guid> JoinMselByInvitationAsync(Guid mselId, CancellationToken
return (Guid)msel.PlayerViewId;
}

public async Task<Msel> LaunchMselByInvitationAsync(Guid mselId, CancellationToken ct)
public async Task<Msel> LaunchMselByInvitationAsync(Guid mselId, Guid? teamId, CancellationToken ct)
{
//check to see if the MSEL exists
var exists = await _context.Msels.AnyAsync(m => m.Id == mselId);
Expand All @@ -1862,7 +1858,8 @@ public async Task<Msel> LaunchMselByInvitationAsync(Guid mselId, CancellationTok
i.ExpirationDateTime > now &&
i.UserCount < i.MaxUsersAllowed &&
i.Msel.IsTemplate &&
i.MselId == mselId)
i.MselId == mselId &&
(teamId == null || i.TeamId == teamId))
.ToListAsync(ct);
var invitation = invitationList
.SingleOrDefault(i =>
Expand Down
Loading