mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
PM-16261 move ImportCiphersAsync to the tools team (#5245)
* PM-16261 move ImportCiphersAsync to the tools team and create services using CQRS design pattern * PM-16261 fix renaming methods and add unit tests for succes and bad request exception * PM-16261 clean up old code from test
This commit is contained in:
@ -29,6 +29,7 @@ using Bit.Core.Vault.Entities;
|
||||
using Bit.Api.Auth.Models.Request.WebAuthn;
|
||||
using Bit.Core.Auth.Models.Data;
|
||||
using Bit.Core.Auth.Identity.TokenProviders;
|
||||
using Bit.Core.Tools.ImportFeatures;
|
||||
using Bit.Core.Tools.ReportFeatures;
|
||||
|
||||
|
||||
@ -175,6 +176,7 @@ public class Startup
|
||||
services.AddCoreLocalizationServices();
|
||||
services.AddBillingOperations();
|
||||
services.AddReportingServices();
|
||||
services.AddImportServices();
|
||||
|
||||
// Authorization Handlers
|
||||
services.AddAuthorizationHandlers();
|
||||
|
@ -7,7 +7,7 @@ using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Vault.Services;
|
||||
using Bit.Core.Tools.ImportFeatures.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@ -17,31 +17,30 @@ namespace Bit.Api.Tools.Controllers;
|
||||
[Authorize("Application")]
|
||||
public class ImportCiphersController : Controller
|
||||
{
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly ILogger<ImportCiphersController> _logger;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IImportCiphersCommand _importCiphersCommand;
|
||||
|
||||
public ImportCiphersController(
|
||||
ICipherService cipherService,
|
||||
IUserService userService,
|
||||
ICurrentContext currentContext,
|
||||
ILogger<ImportCiphersController> logger,
|
||||
GlobalSettings globalSettings,
|
||||
ICollectionRepository collectionRepository,
|
||||
IAuthorizationService authorizationService,
|
||||
IOrganizationRepository organizationRepository)
|
||||
IImportCiphersCommand importCiphersCommand)
|
||||
{
|
||||
_cipherService = cipherService;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_collectionRepository = collectionRepository;
|
||||
_authorizationService = authorizationService;
|
||||
_importCiphersCommand = importCiphersCommand;
|
||||
}
|
||||
|
||||
[HttpPost("import")]
|
||||
@ -57,7 +56,7 @@ public class ImportCiphersController : Controller
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var folders = model.Folders.Select(f => f.ToFolder(userId)).ToList();
|
||||
var ciphers = model.Ciphers.Select(c => c.ToCipherDetails(userId, false)).ToList();
|
||||
await _cipherService.ImportCiphersAsync(folders, ciphers, model.FolderRelationships);
|
||||
await _importCiphersCommand.ImportIntoIndividualVaultAsync(folders, ciphers, model.FolderRelationships);
|
||||
}
|
||||
|
||||
[HttpPost("import-organization")]
|
||||
@ -85,7 +84,7 @@ public class ImportCiphersController : Controller
|
||||
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var ciphers = model.Ciphers.Select(l => l.ToOrganizationCipherDetails(orgId)).ToList();
|
||||
await _cipherService.ImportCiphersAsync(collections, ciphers, model.CollectionRelationships, userId);
|
||||
await _importCiphersCommand.ImportIntoOrganizationalVaultAsync(collections, ciphers, model.CollectionRelationships, userId);
|
||||
}
|
||||
|
||||
private async Task<bool> CheckOrgImportPermission(List<Collection> collections, Guid orgId)
|
||||
|
Reference in New Issue
Block a user