mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
[SG-998] Move files to Vault folders (#2724)
* Move Api files * Move Core files * Move Infrastructure files * Move Sql Files * Move Api Sync files to Vault * Move test vault files * Update Sql.sqlproj paths * Update Codeowners * Fix vault file paths in sqlproj * Update CipherDetails.sql path in sqlproj * Update Core models and entities namespaces * Update namespaces Core Services and Repositories * Missed service namespaces * Update Api namespaces * Update Infrastructure namespaces * Move infrastructure queries that were missed * Tests namespace updates * Admin and Events namespace updates * Remove unused usings * Remove extra CiphersController usings * Rename folder * Fix CipherDetails namespace * Sqlproj fixes * Move stored procs into folders by table * using order fix
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Repositories;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
public class Folder : Core.Entities.Folder
|
||||
{
|
||||
public virtual User User { get; set; }
|
||||
}
|
||||
|
||||
public class FolderMapperProfile : Profile
|
||||
{
|
||||
public FolderMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Entities.Folder, Folder>().ReverseMap();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Bit.Infrastructure.EntityFramework.Converters;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
@ -6,7 +6,7 @@ using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Cipher = Bit.Core.Entities.Cipher;
|
||||
using Cipher = Bit.Core.Vault.Entities.Cipher;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Vault.Entities;
|
||||
using Event = Bit.Infrastructure.EntityFramework.Models.Event;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Bit.Core.Enums;
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
@ -76,7 +77,7 @@ public class UserCipherDetailsQuery : IQuery<CipherDetails>
|
||||
return union;
|
||||
}
|
||||
|
||||
private static Guid? GetFolderId(Guid? userId, Models.Cipher cipher)
|
||||
private static Guid? GetFolderId(Guid? userId, Cipher cipher)
|
||||
{
|
||||
if (userId.HasValue && !string.IsNullOrWhiteSpace(cipher.Folders))
|
||||
{
|
||||
|
@ -1,8 +1,9 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
public class Cipher : Core.Entities.Cipher
|
||||
public class Cipher : Core.Vault.Entities.Cipher
|
||||
{
|
||||
public virtual User User { get; set; }
|
||||
public virtual Organization Organization { get; set; }
|
||||
@ -13,6 +14,6 @@ public class CipherMapperProfile : Profile
|
||||
{
|
||||
public CipherMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Entities.Cipher, Cipher>().ReverseMap();
|
||||
CreateMap<Core.Vault.Entities.Cipher, Cipher>().ReverseMap();
|
||||
}
|
||||
}
|
17
src/Infrastructure.EntityFramework/Vault/Models/Folder.cs
Normal file
17
src/Infrastructure.EntityFramework/Vault/Models/Folder.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
public class Folder : Core.Vault.Entities.Folder
|
||||
{
|
||||
public virtual User User { get; set; }
|
||||
}
|
||||
|
||||
public class FolderMapperProfile : Profile
|
||||
{
|
||||
public FolderMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Vault.Entities.Folder, Folder>().ReverseMap();
|
||||
}
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Vault.Enums;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using Core.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Vault.Queries;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -13,15 +17,15 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using User = Bit.Core.Entities.User;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories;
|
||||
|
||||
public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>, ICipherRepository
|
||||
public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, Guid>, ICipherRepository
|
||||
{
|
||||
public CipherRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Ciphers)
|
||||
{ }
|
||||
|
||||
public override async Task<Core.Entities.Cipher> CreateAsync(Core.Entities.Cipher cipher)
|
||||
public override async Task<Core.Vault.Entities.Cipher> CreateAsync(Core.Vault.Entities.Cipher cipher)
|
||||
{
|
||||
cipher = await base.CreateAsync(cipher);
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
@ -40,7 +44,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
return cipher;
|
||||
}
|
||||
|
||||
public override async Task DeleteAsync(Core.Entities.Cipher cipher)
|
||||
public override async Task DeleteAsync(Core.Vault.Entities.Cipher cipher)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
@ -74,7 +78,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(Core.Entities.Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
public async Task CreateAsync(Core.Vault.Entities.Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
cipher = await CreateAsync(cipher);
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
@ -105,7 +109,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
cipher.Folders = cipher.FolderId.HasValue ?
|
||||
$"{{{userIdKey}:\"{cipher.FolderId}\"}}" :
|
||||
null;
|
||||
var entity = Mapper.Map<Cipher>((Core.Entities.Cipher)cipher);
|
||||
var entity = Mapper.Map<Cipher>((Core.Vault.Entities.Cipher)cipher);
|
||||
await dbContext.AddAsync(entity);
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
@ -134,7 +138,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEnumerable<Core.Entities.Cipher> ciphers, IEnumerable<Core.Entities.Folder> folders)
|
||||
public async Task CreateAsync(IEnumerable<Core.Vault.Entities.Cipher> ciphers, IEnumerable<Core.Vault.Entities.Folder> folders)
|
||||
{
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
@ -153,7 +157,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEnumerable<Core.Entities.Cipher> ciphers, IEnumerable<Core.Entities.Collection> collections, IEnumerable<Core.Entities.CollectionCipher> collectionCiphers)
|
||||
public async Task CreateAsync(IEnumerable<Core.Vault.Entities.Cipher> ciphers, IEnumerable<Core.Entities.Collection> collections, IEnumerable<Core.Entities.CollectionCipher> collectionCiphers)
|
||||
{
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
@ -317,14 +321,14 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Cipher>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
public async Task<ICollection<Core.Vault.Entities.Cipher>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = dbContext.Ciphers.Where(x => !x.UserId.HasValue && x.OrganizationId == organizationId);
|
||||
var data = await query.ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Cipher>>(data);
|
||||
return Mapper.Map<List<Core.Vault.Entities.Cipher>>(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,7 +469,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
cipher.Favorites = JsonConvert.SerializeObject(folders);
|
||||
}
|
||||
}
|
||||
var mappedEntity = Mapper.Map<Cipher>((Core.Entities.Cipher)cipher);
|
||||
var mappedEntity = Mapper.Map<Cipher>((Core.Vault.Entities.Cipher)cipher);
|
||||
dbContext.Entry(entity).CurrentValues.SetValues(mappedEntity);
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
@ -545,7 +549,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
return 0;
|
||||
}
|
||||
|
||||
public async Task<bool> ReplaceAsync(Core.Entities.Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
public async Task<bool> ReplaceAsync(Core.Vault.Entities.Cipher cipher, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
@ -714,7 +718,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateCiphersAsync(Guid userId, IEnumerable<Core.Entities.Cipher> ciphers)
|
||||
public async Task UpdateCiphersAsync(Guid userId, IEnumerable<Core.Vault.Entities.Cipher> ciphers)
|
||||
{
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
@ -766,7 +770,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateUserKeysAndCiphersAsync(User user, IEnumerable<Core.Entities.Cipher> ciphers, IEnumerable<Core.Entities.Folder> folders, IEnumerable<Core.Entities.Send> sends)
|
||||
public async Task UpdateUserKeysAndCiphersAsync(User user, IEnumerable<Core.Vault.Entities.Cipher> ciphers, IEnumerable<Core.Vault.Entities.Folder> folders, IEnumerable<Core.Entities.Send> sends)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
@ -1,18 +1,19 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories;
|
||||
|
||||
public class FolderRepository : Repository<Core.Entities.Folder, Folder, Guid>, IFolderRepository
|
||||
public class FolderRepository : Repository<Core.Vault.Entities.Folder, Folder, Guid>, IFolderRepository
|
||||
{
|
||||
public FolderRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Folders)
|
||||
{ }
|
||||
|
||||
public async Task<Core.Entities.Folder> GetByIdAsync(Guid id, Guid userId)
|
||||
public async Task<Core.Vault.Entities.Folder> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
var folder = await base.GetByIdAsync(id);
|
||||
if (folder == null || folder.UserId != userId)
|
||||
@ -23,7 +24,7 @@ public class FolderRepository : Repository<Core.Entities.Folder, Folder, Guid>,
|
||||
return folder;
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Folder>> GetManyByUserIdAsync(Guid userId)
|
||||
public async Task<ICollection<Core.Vault.Entities.Folder>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
@ -32,7 +33,7 @@ public class FolderRepository : Repository<Core.Entities.Folder, Folder, Guid>,
|
||||
where f.UserId == userId
|
||||
select f;
|
||||
var folders = await query.ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Folder>>(folders);
|
||||
return Mapper.Map<List<Core.Vault.Entities.Folder>>(folders);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
|
||||
|
||||
public class CipherDetailsQuery : IQuery<CipherDetails>
|
||||
{
|
@ -1,6 +1,8 @@
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
|
||||
|
||||
public class CipherOrganizationDetailsReadByIdQuery : IQuery<CipherOrganizationDetails>
|
||||
{
|
@ -1,6 +1,7 @@
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Vault.Queries;
|
||||
|
||||
public class CipherOrganizationDetailsReadByOrganizationIdQuery : IQuery<CipherOrganizationDetails>
|
||||
{
|
@ -1,7 +1,9 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
namespace Bit.Infrastructure.EntityFramework.Vault.Repositories.Queries;
|
||||
|
||||
public class CipherReadCanEditByIdUserIdQuery : IQuery<Cipher>
|
||||
{
|
Reference in New Issue
Block a user