mirror of
https://github.com/bitwarden/server.git
synced 2025-07-07 02:52:50 -05:00
org repo
This commit is contained in:
@ -18,6 +18,7 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Cipher> Ciphers { get; set; }
|
||||
public DbSet<Organization> Organizations { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder builder)
|
||||
{
|
||||
@ -29,8 +30,14 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
|
||||
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<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)
|
||||
{
|
||||
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)
|
||||
.Skip(skip).Take(take)
|
||||
.ToListAsync();
|
||||
|
Reference in New Issue
Block a user