mirror of
https://github.com/bitwarden/server.git
synced 2025-04-04 20:50:21 -05:00

* [PM-14378] Introduce GetCipherPermissionsForOrganization query for Dapper CipherRepository * [PM-14378] Introduce GetCipherPermissionsForOrganization method for Entity Framework * [PM-14378] Add integration tests for new repository method * [PM-14378] Introduce IGetCipherPermissionsForUserQuery CQRS query * [PM-14378] Introduce SecurityTaskOperationRequirement * [PM-14378] Introduce SecurityTaskAuthorizationHandler.cs * [PM-14378] Introduce SecurityTaskOrganizationAuthorizationHandler.cs * [PM-14378] Register new authorization handlers * [PM-14378] Formatting * [PM-14378] Add unit tests for GetCipherPermissionsForUserQuery * [PM-15378] Cleanup SecurityTaskAuthorizationHandler and add tests * [PM-14378] Add tests for SecurityTaskOrganizationAuthorizationHandler * [PM-14378] Formatting * [PM-14378] Update date in migration file * [PM-14378] Add missing awaits * Added bulk create request model * Created sproc to create bulk security tasks * Renamed tasks to SecurityTasksInput * Added create many implementation for sqlserver and ef core * removed trailing comma * created ef implementatin for create many and added integration test * Refactored request model * Refactored request model * created create many tasks command interface and class * added security authorization handler work temp * Added the implementation for the create manys tasks command * Added comment * Changed return to return list of created security tasks * Registered command * Completed bulk create action * Added unit tests for the command * removed hard coded table name * Fixed lint issue * Added JsonConverter attribute to allow enum value to be passed as string * Removed makshift security task operations * Fixed references * Removed old migration * Rebased * [PM-14378] Introduce GetCipherPermissionsForOrganization query for Dapper CipherRepository * [PM-14378] Introduce GetCipherPermissionsForOrganization method for Entity Framework * [PM-14378] Add unit tests for GetCipherPermissionsForUserQuery * Completed bulk create action * bumped migration version * Fixed lint issue * Removed complex sql data type in favour of json string * Register IGetTasksForOrganizationQuery * Fixed lint issue * Removed tasks grouping * Fixed linting * Removed unused code * Removed unused code * Aligned with client change * Fixed linting --------- Co-authored-by: Shane Melton <smelton@bitwarden.com>
80 lines
3.1 KiB
C#
80 lines
3.1 KiB
C#
using AutoMapper;
|
|
using Bit.Core.Vault.Enums;
|
|
using Bit.Core.Vault.Repositories;
|
|
using Bit.Infrastructure.EntityFramework.Repositories;
|
|
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
|
using Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories;
|
|
|
|
public class SecurityTaskRepository : Repository<Core.Vault.Entities.SecurityTask, SecurityTask, Guid>, ISecurityTaskRepository
|
|
{
|
|
public SecurityTaskRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
|
: base(serviceScopeFactory, mapper, (context) => context.SecurityTasks)
|
|
{ }
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ICollection<Core.Vault.Entities.SecurityTask>> GetManyByUserIdStatusAsync(Guid userId,
|
|
SecurityTaskStatus? status = null)
|
|
{
|
|
using var scope = ServiceScopeFactory.CreateScope();
|
|
var dbContext = GetDatabaseContext(scope);
|
|
var query = new SecurityTaskReadByUserIdStatusQuery(userId, status);
|
|
var data = await query.Run(dbContext).ToListAsync();
|
|
return data;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ICollection<Core.Vault.Entities.SecurityTask>> GetManyByOrganizationIdStatusAsync(Guid organizationId,
|
|
SecurityTaskStatus? status = null)
|
|
{
|
|
using var scope = ServiceScopeFactory.CreateScope();
|
|
var dbContext = GetDatabaseContext(scope);
|
|
var query = from st in dbContext.SecurityTasks
|
|
join o in dbContext.Organizations
|
|
on st.OrganizationId equals o.Id
|
|
where
|
|
o.Enabled &&
|
|
st.OrganizationId == organizationId &&
|
|
(status == null || st.Status == status)
|
|
select new Core.Vault.Entities.SecurityTask
|
|
{
|
|
Id = st.Id,
|
|
OrganizationId = st.OrganizationId,
|
|
CipherId = st.CipherId,
|
|
Status = st.Status,
|
|
Type = st.Type,
|
|
CreationDate = st.CreationDate,
|
|
RevisionDate = st.RevisionDate,
|
|
};
|
|
|
|
return await query.OrderByDescending(st => st.CreationDate).ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ICollection<Core.Vault.Entities.SecurityTask>> CreateManyAsync(
|
|
IEnumerable<Core.Vault.Entities.SecurityTask> tasks)
|
|
{
|
|
var tasksList = tasks?.ToList();
|
|
if (tasksList is null || tasksList.Count == 0)
|
|
{
|
|
return Array.Empty<SecurityTask>();
|
|
}
|
|
|
|
foreach (var task in tasksList)
|
|
{
|
|
task.SetNewId();
|
|
}
|
|
|
|
using var scope = ServiceScopeFactory.CreateScope();
|
|
var dbContext = GetDatabaseContext(scope);
|
|
var entities = Mapper.Map<List<SecurityTask>>(tasksList);
|
|
await dbContext.AddRangeAsync(entities);
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
return tasksList;
|
|
}
|
|
}
|