mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PM-14376] Add GET tasks endpoint (#5089)
* Added CQRS pattern * Added the GetManyByUserIdAsync signature to the repositiory * Added sql sproc Created user defined type to hold status Created migration file * Added ef core query * Added absract and concrete implementation for GetManyByUserIdStatusAsync * Added integration tests * Updated params to status * Implemented new query to utilize repository method * Added controller for the security task endpoint * Fixed lint issues * Added documentation * simplified to require single status modified script to check for users with edit rights * Updated ef core query * Added new assertions * simplified to require single status * fixed formatting * Fixed sql script * Removed default null * Added security tasks feature flag
This commit is contained in:
40
src/Api/Vault/Controllers/SecurityTaskController.cs
Normal file
40
src/Api/Vault/Controllers/SecurityTaskController.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Bit.Api.Models.Response;
|
||||
using Bit.Api.Vault.Models.Response;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Vault.Enums;
|
||||
using Bit.Core.Vault.Queries;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bit.Api.Vault.Controllers;
|
||||
|
||||
[Route("tasks")]
|
||||
[Authorize("Application")]
|
||||
[RequireFeature(FeatureFlagKeys.SecurityTasks)]
|
||||
public class SecurityTaskController : Controller
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
private readonly IGetTaskDetailsForUserQuery _getTaskDetailsForUserQuery;
|
||||
|
||||
public SecurityTaskController(IUserService userService, IGetTaskDetailsForUserQuery getTaskDetailsForUserQuery)
|
||||
{
|
||||
_userService = userService;
|
||||
_getTaskDetailsForUserQuery = getTaskDetailsForUserQuery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves security tasks for the current user.
|
||||
/// </summary>
|
||||
/// <param name="status">Optional filter for task status. If not provided returns tasks of all statuses.</param>
|
||||
/// <returns>A list response model containing the security tasks for the user.</returns>
|
||||
[HttpGet("")]
|
||||
public async Task<ListResponseModel<SecurityTasksResponseModel>> Get([FromQuery] SecurityTaskStatus? status)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var securityTasks = await _getTaskDetailsForUserQuery.GetTaskDetailsForUserAsync(userId, status);
|
||||
var response = securityTasks.Select(x => new SecurityTasksResponseModel(x)).ToList();
|
||||
return new ListResponseModel<SecurityTasksResponseModel>(response);
|
||||
}
|
||||
}
|
30
src/Api/Vault/Models/Response/SecurityTasksResponseModel.cs
Normal file
30
src/Api/Vault/Models/Response/SecurityTasksResponseModel.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Core.Vault.Entities;
|
||||
using Bit.Core.Vault.Enums;
|
||||
|
||||
namespace Bit.Api.Vault.Models.Response;
|
||||
|
||||
public class SecurityTasksResponseModel : ResponseModel
|
||||
{
|
||||
public SecurityTasksResponseModel(SecurityTask securityTask, string obj = "securityTask")
|
||||
: base(obj)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(securityTask);
|
||||
|
||||
Id = securityTask.Id;
|
||||
OrganizationId = securityTask.OrganizationId;
|
||||
CipherId = securityTask.CipherId;
|
||||
Type = securityTask.Type;
|
||||
Status = securityTask.Status;
|
||||
CreationDate = securityTask.CreationDate;
|
||||
RevisionDate = securityTask.RevisionDate;
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public SecurityTaskType Type { get; set; }
|
||||
public SecurityTaskStatus Status { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
Reference in New Issue
Block a user