Files
server/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserUserViewQuery.cs
Rui Tomé c4614bfb3d [AC-1144] Warn admins when removing or revoking users without master password (#2953)
* [AC-1144] Modified OrganizationUserUserDetails queries to include value for 'HasMasterPassword' property

* [AC-1144] Added 'HasMasterPassword' property to ProviderUserUserDetailsView

* [AC-1144] Added IProviderUserRepository.GetDetailsByIdAsync to get the details for a given ProviderUser.Id

* [AC-1144] Changed ProviderUsersController.Get to use ProviderUserRepository.GetDetailsByIdAsync

* [AC-1144] Modified OrganizationUsersController.Get to user OrganizationUserRepository.GetDetailsByIdWithCollectionsAsync to output HasMasterPassword value

* [AC-1144] Reverted changes for ProviderUser

* [AC-1144] Removed line break
2023-06-16 16:38:58 +01:00

38 lines
1.7 KiB
C#

using Bit.Core.Models.Data.Organizations.OrganizationUsers;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
public class OrganizationUserUserDetailsViewQuery : IQuery<OrganizationUserUserDetails>
{
public IQueryable<OrganizationUserUserDetails> Run(DatabaseContext dbContext)
{
var query = from ou in dbContext.OrganizationUsers
join u in dbContext.Users on ou.UserId equals u.Id into u_g
from u in u_g.DefaultIfEmpty()
join su in dbContext.SsoUsers on new { ou.UserId, OrganizationId = (Guid?)ou.OrganizationId } equals new { UserId = (Guid?)su.UserId, su.OrganizationId } into su_g
from su in su_g.DefaultIfEmpty()
select new { ou, u, su };
return query.Select(x => new OrganizationUserUserDetails
{
Id = x.ou.Id,
UserId = x.ou.UserId,
OrganizationId = x.ou.OrganizationId,
Name = x.u.Name,
Email = x.u.Email ?? x.ou.Email,
AvatarColor = x.u.AvatarColor,
TwoFactorProviders = x.u.TwoFactorProviders,
Premium = x.u.Premium,
Status = x.ou.Status,
Type = x.ou.Type,
AccessAll = x.ou.AccessAll,
ExternalId = x.ou.ExternalId,
SsoExternalId = x.su.ExternalId,
Permissions = x.ou.Permissions,
ResetPasswordKey = x.ou.ResetPasswordKey,
UsesKeyConnector = x.u != null && x.u.UsesKeyConnector,
AccessSecretsManager = x.ou.AccessSecretsManager,
HasMasterPassword = x.u != null && !string.IsNullOrWhiteSpace(x.u.MasterPassword)
});
}
}