mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
Add BuildConfirmOrganizationUserAction method to IOrganizationUserRepository and implementations in OrganizationUserRepository classes
- Introduced a new method in IOrganizationUserRepository to build an action for confirming an organization user. - Implemented the method in both Dapper and Entity Framework OrganizationUserRepository classes to handle user confirmation and status updates. - Enhanced the functionality to support transaction execution for database operations.
This commit is contained in:
@@ -6,6 +6,7 @@ using Bit.Core.Enums;
|
||||
using Bit.Core.KeyManagement.UserKey;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@@ -108,4 +109,11 @@ public interface IOrganizationUserRepository : IRepository<OrganizationUser, Gui
|
||||
/// Similar to GetByOrganizationAsync, but returns the user details.
|
||||
/// </remarks>
|
||||
Task<OrganizationUserUserDetails?> GetDetailsByOrganizationIdUserIdAsync(Guid organizationId, Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// Builds an action that confirms an organization user (sets status to Confirmed, links to user, sets key).
|
||||
/// </summary>
|
||||
/// <param name="organizationUser">The organization user entity with updated properties</param>
|
||||
/// <returns>An action that can be executed within a transaction</returns>
|
||||
OrganizationInitializationUpdateAction BuildConfirmOrganizationUserAction(OrganizationUser organizationUser);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Bit.Core.Enums;
|
||||
using Bit.Core.KeyManagement.UserKey;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
@@ -709,4 +710,16 @@ public class OrganizationUserRepository : Repository<OrganizationUser, Guid>, IO
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public OrganizationInitializationUpdateAction BuildConfirmOrganizationUserAction(OrganizationUser organizationUser)
|
||||
{
|
||||
return async (SqlConnection? connection, SqlTransaction? transaction, object? context) =>
|
||||
{
|
||||
await connection!.ExecuteAsync(
|
||||
"[dbo].[OrganizationUser_Update]",
|
||||
organizationUser,
|
||||
commandType: CommandType.StoredProcedure,
|
||||
transaction: transaction);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ using Bit.Core.Exceptions;
|
||||
using Bit.Core.KeyManagement.UserKey;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -978,6 +980,25 @@ public class OrganizationUserRepository : Repository<Core.Entities.OrganizationU
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
public OrganizationInitializationUpdateAction BuildConfirmOrganizationUserAction(Core.Entities.OrganizationUser organizationUser)
|
||||
{
|
||||
return async (SqlConnection? _, SqlTransaction? _, object? context) =>
|
||||
{
|
||||
var dbContext = (DatabaseContext)context!;
|
||||
|
||||
var efOrganizationUser = await dbContext.OrganizationUsers.FindAsync(organizationUser.Id);
|
||||
if (efOrganizationUser != null)
|
||||
{
|
||||
efOrganizationUser.Status = organizationUser.Status;
|
||||
efOrganizationUser.UserId = organizationUser.UserId;
|
||||
efOrganizationUser.Key = organizationUser.Key;
|
||||
efOrganizationUser.Email = organizationUser.Email;
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
};
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user