mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00
org repo
This commit is contained in:
parent
46c258428e
commit
9fa7f335bd
@ -50,6 +50,7 @@
|
|||||||
<PackageReference Include="IdentityServer4" Version="2.5.3" />
|
<PackageReference Include="IdentityServer4" Version="2.5.3" />
|
||||||
<PackageReference Include="Dapper" Version="1.60.6" />
|
<PackageReference Include="Dapper" Version="1.60.6" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
|
<PackageReference Include="System.Text.Json" Version="4.7.0" />
|
||||||
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
|
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
|
||||||
<PackageReference Include="AspNetCoreRateLimit" Version="2.1.0" />
|
<PackageReference Include="AspNetCoreRateLimit" Version="2.1.0" />
|
||||||
<PackageReference Include="Braintree" Version="4.15.0" />
|
<PackageReference Include="Braintree" Version="4.15.0" />
|
||||||
|
@ -1,17 +1,40 @@
|
|||||||
using AutoMapper;
|
using System.Text.Json;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
namespace Bit.Core.Models.EntityFramework
|
namespace Bit.Core.Models.EntityFramework
|
||||||
{
|
{
|
||||||
public class Cipher : Table.Cipher
|
public class Cipher : Table.Cipher
|
||||||
{
|
{
|
||||||
|
private JsonDocument _dataJson;
|
||||||
|
private JsonDocument _attachmentsJson;
|
||||||
|
|
||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
|
public Organization Organization { get; set; }
|
||||||
|
public JsonDocument DataJson
|
||||||
|
{
|
||||||
|
get => _dataJson;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Data = value.ToString();
|
||||||
|
_dataJson = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public JsonDocument AttachmentsJson
|
||||||
|
{
|
||||||
|
get => _attachmentsJson;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Attachments = value.ToString();
|
||||||
|
_attachmentsJson = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CipherMapperProfile : Profile
|
public class CipherMapperProfile : Profile
|
||||||
{
|
{
|
||||||
public CipherMapperProfile()
|
public CipherMapperProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Table.Cipher, Cipher>();
|
CreateMap<Table.Cipher, Cipher>().ReverseMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
src/Core/Models/EntityFramework/Organization.cs
Normal file
18
src/Core/Models/EntityFramework/Organization.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.EntityFramework
|
||||||
|
{
|
||||||
|
public class Organization : Table.Organization
|
||||||
|
{
|
||||||
|
public ICollection<Cipher> Ciphers { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OrganizationMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public OrganizationMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<Table.Organization, Organization>().ReverseMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.EntityFramework
|
|||||||
{
|
{
|
||||||
public UserMapperProfile()
|
public UserMapperProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Table.User, User>();
|
CreateMap<Table.User, User>().ReverseMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
|||||||
|
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
public DbSet<Cipher> Ciphers { get; set; }
|
public DbSet<Cipher> Ciphers { get; set; }
|
||||||
|
public DbSet<Organization> Organizations { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder builder)
|
protected override void OnConfiguring(DbContextOptionsBuilder builder)
|
||||||
{
|
{
|
||||||
@ -29,8 +30,14 @@ namespace Bit.Core.Repositories.EntityFramework
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
|
builder.Entity<Cipher>().Ignore(e => e.Data);
|
||||||
|
builder.Entity<Cipher>().Property(e => e.Data).HasColumnName("Data");
|
||||||
|
builder.Entity<Cipher>().Ignore(e => e.Attachments);
|
||||||
|
builder.Entity<Cipher>().Property(e => e.Attachments).HasColumnName("Attachments");
|
||||||
|
|
||||||
builder.Entity<User>().ToTable(nameof(User));
|
builder.Entity<User>().ToTable(nameof(User));
|
||||||
builder.Entity<Cipher>().ToTable(nameof(Cipher));
|
builder.Entity<Cipher>().ToTable(nameof(Cipher));
|
||||||
|
builder.Entity<Organization>().ToTable(nameof(Organization));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TableModel = Bit.Core.Models.Table;
|
||||||
|
using DataModel = Bit.Core.Models.Data;
|
||||||
|
using EFModel = Bit.Core.Models.EntityFramework;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories.EntityFramework
|
||||||
|
{
|
||||||
|
public class OrganizationRepository : Repository<TableModel.Organization, EFModel.Organization, Guid>, IOrganizationRepository
|
||||||
|
{
|
||||||
|
public OrganizationRepository(DatabaseContext databaseContext, IMapper mapper)
|
||||||
|
: base(databaseContext, mapper, () => databaseContext.Organizations)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public async Task<ICollection<TableModel.Organization>> GetManyByEnabledAsync()
|
||||||
|
{
|
||||||
|
var organizations = await GetDbSet().Where(e => e.Enabled).ToListAsync();
|
||||||
|
return Mapper.Map<List<TableModel.Organization>>(organizations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<TableModel.Organization>> GetManyByUserIdAsync(Guid userId)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return await Task.FromResult(null as ICollection<TableModel.Organization>);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<TableModel.Organization>> SearchAsync(string name, string userEmail, bool? paid,
|
||||||
|
int skip, int take)
|
||||||
|
{
|
||||||
|
// TODO: more filters
|
||||||
|
var organizations = await GetDbSet()
|
||||||
|
.Where(e => name == null || e.Name.StartsWith(name))
|
||||||
|
.OrderBy(e => e.Name)
|
||||||
|
.Skip(skip).Take(take)
|
||||||
|
.ToListAsync();
|
||||||
|
return Mapper.Map<List<TableModel.Organization>>(organizations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateStorageAsync(Guid id)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<DataModel.OrganizationAbility>> GetManyAbilitiesAsync()
|
||||||
|
{
|
||||||
|
return await GetDbSet()
|
||||||
|
.Select(e => new DataModel.OrganizationAbility
|
||||||
|
{
|
||||||
|
Enabled = e.Enabled,
|
||||||
|
Id = e.Id,
|
||||||
|
Use2fa = e.Use2fa,
|
||||||
|
UseEvents = e.UseEvents,
|
||||||
|
UsersGetPremium = e.UsersGetPremium,
|
||||||
|
Using2fa = e.Use2fa && e.TwoFactorProviders != null && e.TwoFactorProviders != "{}",
|
||||||
|
}).ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -34,7 +34,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
|||||||
public async Task<ICollection<TableModel.User>> SearchAsync(string email, int skip, int take)
|
public async Task<ICollection<TableModel.User>> SearchAsync(string email, int skip, int take)
|
||||||
{
|
{
|
||||||
var users = await GetDbSet()
|
var users = await GetDbSet()
|
||||||
.Where(e => e.Email == null || e.Email.StartsWith(email))
|
.Where(e => email == null || e.Email.StartsWith(email))
|
||||||
.OrderBy(e => e.Email)
|
.OrderBy(e => e.Email)
|
||||||
.Skip(skip).Take(take)
|
.Skip(skip).Take(take)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user