1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-13 13:47:30 -05:00

add api support for updating org identifier (#861)

* add api support for updating org identifier

* add identifier to response as well

* implement in EF repo
This commit is contained in:
Kyle Spearrin
2020-08-12 16:38:22 -04:00
committed by GitHub
parent c8220fdfa6
commit 056b4b9bf4
8 changed files with 72 additions and 0 deletions

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Bit.Core.Models.Table;
namespace Bit.Core.Repositories.EntityFramework
{
@ -17,6 +18,17 @@ namespace Bit.Core.Repositories.EntityFramework
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Organizations)
{ }
public async Task<Organization> GetByIdentifierAsync(string identifier)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var organization = await GetDbSet(dbContext).Where(e => e.Identifier == identifier)
.FirstOrDefaultAsync();
return organization;
}
}
public async Task<ICollection<TableModel.Organization>> GetManyByEnabledAsync()
{
using (var scope = ServiceScopeFactory.CreateScope())

View File

@ -8,6 +8,7 @@ namespace Bit.Core.Repositories
{
public interface IOrganizationRepository : IRepository<Organization, Guid>
{
Task<Organization> GetByIdentifierAsync(string identifier);
Task<ICollection<Organization>> GetManyByEnabledAsync();
Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId);
Task<ICollection<Organization>> SearchAsync(string name, string userEmail, bool? paid, int skip, int take);

View File

@ -20,6 +20,18 @@ namespace Bit.Core.Repositories.SqlServer
: base(connectionString, readOnlyConnectionString)
{ }
public async Task<Organization> GetByIdentifierAsync(string identifier)
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Organization>(
"[dbo].[Organization_ReadByIdentifier]",
commandType: CommandType.StoredProcedure);
return results.SingleOrDefault();
}
}
public async Task<ICollection<Organization>> GetManyByEnabledAsync()
{
using (var connection = new SqlConnection(ConnectionString))