-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[PM-14381] Add POST /tasks/bulk-create endpoint #5188
Open
gbubemismith
wants to merge
51
commits into
main
Choose a base branch
from
vault/PM-14381
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
69da981
[PM-14378] Introduce GetCipherPermissionsForOrganization query for Daโฆ
shane-melton c85a930
[PM-14378] Introduce GetCipherPermissionsForOrganization method for Eโฆ
shane-melton db5bd64
[PM-14378] Add integration tests for new repository method
shane-melton a03ddee
[PM-14378] Introduce IGetCipherPermissionsForUserQuery CQRS query
shane-melton 532dd07
[PM-14378] Introduce SecurityTaskOperationRequirement
shane-melton 5c38328
[PM-14378] Introduce SecurityTaskAuthorizationHandler.cs
shane-melton 19a1814
[PM-14378] Introduce SecurityTaskOrganizationAuthorizationHandler.cs
shane-melton df3e424
[PM-14378] Register new authorization handlers
shane-melton 78ea8b5
[PM-14378] Formatting
shane-melton 4d80238
[PM-14378] Add unit tests for GetCipherPermissionsForUserQuery
shane-melton b40d144
[PM-15378] Cleanup SecurityTaskAuthorizationHandler and add tests
shane-melton ca15550
[PM-14378] Add tests for SecurityTaskOrganizationAuthorizationHandler
shane-melton bcf3210
[PM-14378] Formatting
shane-melton 021634c
[PM-14378] Update date in migration file
shane-melton d222923
Merge branch 'main' into vault/pm-14378/security-task-auth-handler
shane-melton 6eb33cf
Merge branch 'main' into vault/pm-14378/security-task-auth-handler
shane-melton b10df9b
[PM-14378] Add missing awaits
shane-melton 3a04e88
Added bulk create request model
gbubemismith 9cef90b
Merge branch 'main' into vault/pm-14378/security-task-auth-handler
shane-melton d00b25b
Created sproc to create bulk security tasks
gbubemismith 3198ea7
Renamed tasks to SecurityTasksInput
gbubemismith 4fabb8a
Added create many implementation for sqlserver and ef core
gbubemismith ef37e9d
removed trailing comma
gbubemismith 0edb923
created ef implementatin for create many and added integration test
gbubemismith 2684901
Refactored request model
gbubemismith 0adb3e3
Refactored request model
gbubemismith ba848ce
created create many tasks command interface and class
gbubemismith 74b25da
Merge commit 'refs/pull/5039/head' of https://github.com/bitwarden/seโฆ
gbubemismith 7738ce4
added security authorization handler work temp
gbubemismith 67f3215
Added the implementation for the create manys tasks command
gbubemismith d2bed09
Added comment
gbubemismith 6aaba7e
Changed return to return list of created security tasks
gbubemismith 04c7c56
Registered command
gbubemismith 6df6132
Completed bulk create action
gbubemismith e3352f4
Added unit tests for the command
gbubemismith e7abb09
removed hard coded table name
gbubemismith 8868b3c
Fixed lint issue
gbubemismith 72b121d
Added JsonConverter attribute to allow enum value to be passed as string
gbubemismith fff7707
Fixed merge conflicts
gbubemismith 770fa34
Removed makshift security task operations
gbubemismith 239a191
Fixed references
gbubemismith 714666b
Removed old migration
gbubemismith a3ffb5f
Rebased
gbubemismith a99afb6
[PM-14378] Introduce GetCipherPermissionsForOrganization query for Daโฆ
shane-melton 4cfbd3d
[PM-14378] Introduce GetCipherPermissionsForOrganization method for Eโฆ
shane-melton 2481ca1
[PM-14378] Add unit tests for GetCipherPermissionsForUserQuery
shane-melton b4e890a
Completed bulk create action
gbubemismith c1c7f3f
Fixed conflicts
gbubemismith 6740471
Merge branch 'main' into vault/PM-14381
gbubemismith 897285f
bumped migration version
gbubemismith e6c7722
Fixed lint issue
gbubemismith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 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,11 @@ | ||
๏ปฟusing System.Text.Json.Serialization; | ||
using Bit.Core.Vault.Enums; | ||
|
||
namespace Bit.Core.Vault.Models.Api; | ||
|
||
public class SecurityTaskCreateRequest | ||
{ | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
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
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
27 changes: 27 additions & 0 deletions
27
src/Sql/Vault/dbo/Stored Procedures/SecurityTask/SecurityTask_CreateMany.sql
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,27 @@ | ||
CREATE PROCEDURE [dbo].[SecurityTask_CreateMany] | ||
@SecurityTasksInput AS [dbo].[SecurityTaskType] READONLY | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON | ||
|
||
INSERT INTO [dbo].[SecurityTask] | ||
( | ||
[Id], | ||
[OrganizationId], | ||
[CipherId], | ||
[Type], | ||
[Status], | ||
[CreationDate], | ||
[RevisionDate] | ||
) | ||
SELECT | ||
ST.[Id], | ||
ST.[OrganizationId], | ||
ST.[CipherId], | ||
ST.[Type], | ||
ST.[Status], | ||
ST.[CreationDate], | ||
ST.[RevisionDate] | ||
FROM | ||
@SecurityTasksInput ST | ||
END |
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 @@ | ||
CREATE TYPE [dbo].[SecurityTaskType] AS TABLE( | ||
[Id] UNIQUEIDENTIFIER NOT NULL, | ||
[OrganizationId] UNIQUEIDENTIFIER NOT NULL, | ||
[CipherId] UNIQUEIDENTIFIER NOT NULL, | ||
[Type] TINYINT NOT NULL, | ||
[Status] TINYINT NOT NULL, | ||
[CreationDate] DATETIME2(7) NOT NULL, | ||
[RevisionDate] DATETIME2(7) NOT NULL | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to avoid custom data types that will need sql changes per schema changes.
The preference is to use the existing generic guidarray for bulk operations
CREATE TYPE [dbo].[GuidIdArray] AS TABLE(
[Id] [uniqueidentifier] NOT NULL
)