-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ac/pm-16812/shortcut-duplicate-group-patch-r…
…equests
- Loading branch information
Showing
31 changed files
with
576 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Api/Vault/Models/Request/BulkCreateSecurityTasksRequestModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Bit.Core.Vault.Models.Api; | ||
|
||
namespace Bit.Api.Vault.Models.Request; | ||
|
||
public class BulkCreateSecurityTasksRequestModel | ||
{ | ||
public IEnumerable<SecurityTaskCreateRequest> Tasks { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Bit.Core.Context; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Utilities; | ||
using Bit.Core.Vault.Authorization.SecurityTasks; | ||
using Bit.Core.Vault.Commands.Interfaces; | ||
using Bit.Core.Vault.Entities; | ||
using Bit.Core.Vault.Enums; | ||
using Bit.Core.Vault.Models.Api; | ||
using Bit.Core.Vault.Repositories; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace Bit.Core.Vault.Commands; | ||
|
||
public class CreateManyTasksCommand : ICreateManyTasksCommand | ||
{ | ||
private readonly IAuthorizationService _authorizationService; | ||
private readonly ICurrentContext _currentContext; | ||
private readonly ISecurityTaskRepository _securityTaskRepository; | ||
|
||
public CreateManyTasksCommand( | ||
ISecurityTaskRepository securityTaskRepository, | ||
IAuthorizationService authorizationService, | ||
ICurrentContext currentContext) | ||
{ | ||
_securityTaskRepository = securityTaskRepository; | ||
_authorizationService = authorizationService; | ||
_currentContext = currentContext; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<ICollection<SecurityTask>> CreateAsync(Guid organizationId, | ||
IEnumerable<SecurityTaskCreateRequest> tasks) | ||
{ | ||
if (!_currentContext.UserId.HasValue) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
var tasksList = tasks?.ToList(); | ||
|
||
if (tasksList is null || tasksList.Count == 0) | ||
{ | ||
throw new BadRequestException("No tasks provided."); | ||
} | ||
|
||
var securityTasks = tasksList.Select(t => new SecurityTask | ||
{ | ||
OrganizationId = organizationId, | ||
CipherId = t.CipherId, | ||
Type = t.Type, | ||
Status = SecurityTaskStatus.Pending | ||
}).ToList(); | ||
|
||
// Verify authorization for each task | ||
foreach (var task in securityTasks) | ||
{ | ||
await _authorizationService.AuthorizeOrThrowAsync( | ||
_currentContext.HttpContext.User, | ||
task, | ||
SecurityTaskOperations.Create); | ||
} | ||
|
||
return await _securityTaskRepository.CreateManyAsync(securityTasks); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Core/Vault/Commands/Interfaces/ICreateManyTasksCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Bit.Core.Vault.Entities; | ||
using Bit.Core.Vault.Models.Api; | ||
|
||
namespace Bit.Core.Vault.Commands.Interfaces; | ||
|
||
public interface ICreateManyTasksCommand | ||
{ | ||
/// <summary> | ||
/// Creates multiple security tasks for an organization. | ||
/// Each task must be authorized and the user must have the Create permission | ||
/// and associated ciphers must belong to the organization. | ||
/// </summary> | ||
/// <param name="organizationId">The </param> | ||
/// <param name="tasks"></param> | ||
/// <returns>Collection of created security tasks</returns> | ||
Task<ICollection<SecurityTask>> CreateAsync(Guid organizationId, IEnumerable<SecurityTaskCreateRequest> tasks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Bit.Core.Vault.Enums; | ||
|
||
namespace Bit.Core.Vault.Models.Api; | ||
|
||
public class SecurityTaskCreateRequest | ||
{ | ||
public SecurityTaskType Type { get; set; } | ||
public Guid? CipherId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.