mirror of
https://github.com/bitwarden/server
synced 2026-02-15 16:05:37 +00:00
Example query
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Models;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using OneOf;
|
||||
using OneOf.Types;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
||||
|
||||
public class GetOrganizationUserQuery(IOrganizationUserRepository organizationUserRepository)
|
||||
: IGetOrganizationUserQuery
|
||||
{
|
||||
public async Task<OneOf<InvitedOrganizationUser, AcceptedOrganizationUser, ConfirmedOrganizationUser, None>> GetOrganizationUserAsync(Guid organizationUserId)
|
||||
{
|
||||
var organizationUser = await organizationUserRepository.GetByIdAsync(organizationUserId);
|
||||
|
||||
if (organizationUser == null)
|
||||
{
|
||||
return new None();
|
||||
}
|
||||
|
||||
// Determine the appropriate model type based on the status
|
||||
// For revoked users, use GetPriorActiveOrganizationUserStatusType to determine the underlying status
|
||||
var effectiveStatus = organizationUser.Status == OrganizationUserStatusType.Revoked
|
||||
? OrganizationService.GetPriorActiveOrganizationUserStatusType(organizationUser)
|
||||
: organizationUser.Status;
|
||||
|
||||
return effectiveStatus switch
|
||||
{
|
||||
OrganizationUserStatusType.Invited => InvitedOrganizationUser.FromEntity(organizationUser),
|
||||
OrganizationUserStatusType.Accepted => AcceptedOrganizationUser.FromEntity(organizationUser),
|
||||
OrganizationUserStatusType.Confirmed => ConfirmedOrganizationUser.FromEntity(organizationUser),
|
||||
_ => throw new InvalidOperationException($"Unsupported organization user status: {organizationUser.Status}")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Models;
|
||||
using OneOf;
|
||||
using OneOf.Types;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
|
||||
public interface IGetOrganizationUserQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves an organization user by their ID and returns the appropriate strongly-typed model
|
||||
/// based on their status (Invited, Accepted, Confirmed, or Revoked).
|
||||
/// </summary>
|
||||
/// <param name="organizationUserId">The ID of the organization user to retrieve.</param>
|
||||
/// <returns>
|
||||
/// A OneOf containing either:
|
||||
/// - InvitedOrganizationUser (status: Invited or Revoked-Invited)
|
||||
/// - AcceptedOrganizationUser (status: Accepted or Revoked-Accepted)
|
||||
/// - ConfirmedOrganizationUser (status: Confirmed or Revoked-Confirmed)
|
||||
/// - None if the user is not found
|
||||
/// </returns>
|
||||
Task<OneOf<InvitedOrganizationUser, AcceptedOrganizationUser, ConfirmedOrganizationUser, None>> GetOrganizationUserAsync(Guid organizationUserId);
|
||||
}
|
||||
Reference in New Issue
Block a user