Skip to content

Commit

Permalink
added teamuser endpoints (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-tspencer committed Apr 12, 2024
1 parent 298d5f8 commit 6c8f46a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
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.0.4</Version>
<Version>1.0.5</Version>
<TargetFramework>net6.0</TargetFramework>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>CS1591</NoWarn>
Expand Down
32 changes: 25 additions & 7 deletions Blueprint.Api/Controllers/TeamUserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,38 @@ public TeamUserController(ITeamUserService teamUserService, IAuthorizationServic
}

/// <summary>
/// Gets all TeamUsers in the system
/// Gets TeamUsers for the specified msel
/// </summary>
/// <remarks>
/// Returns a list of all of the TeamUsers in the system.
/// Returns a list of the specified msel's TeamUsers.
/// <para />
/// Only accessible to a SuperUser
/// Only accessible to an msel user
/// </remarks>
/// <returns></returns>
[HttpGet("msels/{mselId}/teamusers")]
[ProducesResponseType(typeof(IEnumerable<TeamUser>), (int)HttpStatusCode.OK)]
[SwaggerOperation(OperationId = "getMselTeamUsers")]
public async Task<IActionResult> GetByMsel([FromRoute] Guid mselId, CancellationToken ct)
{
var list = await _teamUserService.GetByMselAsync(mselId, ct);
return Ok(list);
}

/// <summary>
/// Gets TeamUsers for the specified team
/// </summary>
/// <remarks>
/// Returns a list of the specified team's TeamUsers.
/// <para />
/// Only accessible to an msel user
/// </remarks>
/// <returns></returns>
[HttpGet("teamusers")]
[HttpGet("teams/{teamId}/teamusers")]
[ProducesResponseType(typeof(IEnumerable<TeamUser>), (int)HttpStatusCode.OK)]
[SwaggerOperation(OperationId = "getTeamUsers")]
public async Task<IActionResult> Get(CancellationToken ct)
[SwaggerOperation(OperationId = "getTeamTeamUsers")]
public async Task<IActionResult> GetByTeam([FromRoute] Guid teamId, CancellationToken ct)
{
var list = await _teamUserService.GetAsync(ct);
var list = await _teamUserService.GetByTeamAsync(teamId, ct);
return Ok(list);
}

Expand Down
31 changes: 28 additions & 3 deletions Blueprint.Api/Services/TeamUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace Blueprint.Api.Services
{
public interface ITeamUserService
{
Task<IEnumerable<ViewModels.TeamUser>> GetAsync(CancellationToken ct);
Task<IEnumerable<ViewModels.TeamUser>> GetByMselAsync(Guid mselId, CancellationToken ct);
Task<IEnumerable<ViewModels.TeamUser>> GetByTeamAsync(Guid teamId, CancellationToken ct);
Task<ViewModels.TeamUser> GetAsync(Guid id, CancellationToken ct);
Task<ViewModels.TeamUser> CreateAsync(ViewModels.TeamUser teamUser, CancellationToken ct);
Task<bool> DeleteAsync(Guid id, CancellationToken ct);
Expand All @@ -47,12 +48,36 @@ public TeamUserService(BlueprintContext context, IAuthorizationService authoriza
_logger = logger;
}

public async Task<IEnumerable<ViewModels.TeamUser>> GetAsync(CancellationToken ct)
public async Task<IEnumerable<ViewModels.TeamUser>> GetByMselAsync(Guid mselId, CancellationToken ct)
{
if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded)
if (
!(await MselUserRequirement.IsMet(_user.GetId(), mselId, _context)) &&
!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded
)
throw new ForbiddenException();

var items = await _context.TeamUsers
.Where(tu => tu.Team.MselId == mselId)
.ToListAsync(ct);

return _mapper.Map<IEnumerable<TeamUser>>(items);
}

public async Task<IEnumerable<ViewModels.TeamUser>> GetByTeamAsync(Guid teamId, CancellationToken ct)
{
var team = await _context.Teams.SingleOrDefaultAsync(t => t.Id == teamId);
if (team == null)
throw new EntityNotFoundException<Team>();

if (
!(await MselUserRequirement.IsMet(_user.GetId(), team.MselId, _context)) &&
!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded
)
throw new ForbiddenException();

var items = await _context.TeamUsers
.Where(tu => tu.TeamId == teamId)
.Include(tu => tu.User)
.ToListAsync(ct);

return _mapper.Map<IEnumerable<TeamUser>>(items);
Expand Down

0 comments on commit 6c8f46a

Please sign in to comment.