Skip to content
Open
1 change: 0 additions & 1 deletion src/Api/Dirt/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Bit.Api.Dirt.Models;
using Bit.Api.Dirt.Models.Response;
using Bit.Api.Tools.Models.Response;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Dirt.Entities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Enums;

namespace Bit.Api.Tools.Models.Response;
namespace Bit.Api.Dirt.Models.Response;

public class MemberAccessDetailReportResponseModel
{
public Guid? UserGuid { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? UserId { get; set; }
public string? UserName { get; set; }
public string? Email { get; set; }
public OrganizationUserStatusType Status { get; set; }
public string? AvatarColor { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool AccountRecoveryEnabled { get; set; }
public bool UsesKeyConnector { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public string GroupName { get; set; }
public string CollectionName { get; set; }
public string? GroupName { get; set; }
public string? CollectionName { get; set; }
public bool? ReadOnly { get; set; }
public bool? HidePasswords { get; set; }
public bool? Manage { get; set; }
public IEnumerable<Guid> CipherIds { get; set; }
public IEnumerable<Guid>? CipherIds { get; set; }

public MemberAccessDetailReportResponseModel(MemberAccessReportDetail reportDetail)
{
UserGuid = reportDetail.UserGuid;
OrganizationUserId = reportDetail.OrganizationUserId;
UserId = reportDetail.UserId;
UserName = reportDetail.UserName;
Email = reportDetail.Email;
Status = reportDetail.Status;
AvatarColor = reportDetail.AvatarColor;
TwoFactorEnabled = reportDetail.TwoFactorEnabled;
AccountRecoveryEnabled = reportDetail.AccountRecoveryEnabled;
UsesKeyConnector = reportDetail.UsesKeyConnector;
Expand Down
20 changes: 11 additions & 9 deletions src/Core/Dirt/Models/Data/MemberAccessReportDetail.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable
using Bit.Core.Enums;

namespace Bit.Core.Dirt.Reports.Models.Data;
namespace Bit.Core.Dirt.Models.Data;

public class MemberAccessReportDetail
{
public Guid? UserGuid { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? UserId { get; set; }
public string? UserName { get; set; }
public string? Email { get; set; }
public OrganizationUserStatusType Status { get; set; }
public string? AvatarColor { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool AccountRecoveryEnabled { get; set; }
public bool UsesKeyConnector { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public string GroupName { get; set; }
public string CollectionName { get; set; }
public string? GroupName { get; set; }
public string? CollectionName { get; set; }
public bool? ReadOnly { get; set; }
public bool? HidePasswords { get; set; }
public bool? Manage { get; set; }
public IEnumerable<Guid> CipherIds { get; set; }
public IEnumerable<Guid>? CipherIds { get; set; }
}
24 changes: 13 additions & 11 deletions src/Core/Dirt/Models/Data/OrganizationMemberBaseDetail.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable
using Bit.Core.Enums;

namespace Bit.Core.Dirt.Reports.Models.Data;
namespace Bit.Core.Dirt.Models.Data;

public class OrganizationMemberBaseDetail
{
public Guid? UserGuid { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string TwoFactorProviders { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? UserId { get; set; }
public string? UserName { get; set; }
public string? Email { get; set; }
public OrganizationUserStatusType Status { get; set; }
public string? AvatarColor { get; set; }
public string? TwoFactorProviders { get; set; }
public bool UsesKeyConnector { get; set; }
public string ResetPasswordKey { get; set; }
public string? ResetPasswordKey { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public string GroupName { get; set; }
public string CollectionName { get; set; }
public string? GroupName { get; set; }
public string? CollectionName { get; set; }
public bool? ReadOnly { get; set; }
public bool? HidePasswords { get; set; }
public bool? Manage { get; set; }
public Guid CipherId { get; set; }
public Guid? CipherId { get; set; }
}
32 changes: 18 additions & 14 deletions src/Core/Dirt/Reports/ReportFeatures/MemberAccessReportQuery.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// FIXME: Update this file to be null safe and then delete the line below
#nullable disable

using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Services;
using Microsoft.Extensions.Logging;

Expand All @@ -29,7 +26,7 @@ await organizationMemberBaseDetailRepository.GetOrganizationMemberBaseDetailsByO
logger.LogInformation(Constants.BypassFiltersEventId, "Retrieved {BaseDetailsCount} base details for OrganizationId: {OrganizationId}",
baseDetails.Count(), request.OrganizationId);

var orgUsers = baseDetails.Select(x => x.UserGuid.GetValueOrDefault()).Distinct();
var orgUsers = baseDetails.Select(x => x.OrganizationUserId.GetValueOrDefault()).Distinct();
var orgUsersCount = orgUsers.Count();
logger.LogInformation(Constants.BypassFiltersEventId, "Found {UniqueUsersCount} unique users for OrganizationId: {OrganizationId}",
orgUsersCount, request.OrganizationId);
Expand All @@ -45,9 +42,12 @@ await organizationMemberBaseDetailRepository.GetOrganizationMemberBaseDetailsByO
var accessDetails = baseDetails
.GroupBy(b => new
{
b.UserGuid,
b.OrganizationUserId,
b.UserId,
b.UserName,
b.Email,
b.Status,
b.AvatarColor,
b.TwoFactorProviders,
b.ResetPasswordKey,
b.UsesKeyConnector,
Expand All @@ -61,11 +61,14 @@ await organizationMemberBaseDetailRepository.GetOrganizationMemberBaseDetailsByO
})
.Select(g => new MemberAccessReportDetail
{
UserGuid = g.Key.UserGuid,
OrganizationUserId = g.Key.OrganizationUserId,
UserId = g.Key.UserId,
UserName = g.Key.UserName,
Email = g.Key.Email,
TwoFactorEnabled = orgUsersTwoFactorEnabled.FirstOrDefault(x => x.userId == g.Key.UserGuid).twoFactorIsEnabled,
AccountRecoveryEnabled = !string.IsNullOrWhiteSpace(g.Key.ResetPasswordKey) && orgAbility.UseResetPassword,
Status = g.Key.Status,
AvatarColor = g.Key.AvatarColor,
TwoFactorEnabled = orgUsersTwoFactorEnabled.FirstOrDefault(x => x.userId == g.Key.OrganizationUserId).twoFactorIsEnabled,
AccountRecoveryEnabled = !string.IsNullOrWhiteSpace(g.Key.ResetPasswordKey) && orgAbility?.UseResetPassword == true,
UsesKeyConnector = g.Key.UsesKeyConnector,
GroupId = g.Key.GroupId,
GroupName = g.Key.GroupName,
Expand All @@ -74,10 +77,11 @@ await organizationMemberBaseDetailRepository.GetOrganizationMemberBaseDetailsByO
ReadOnly = g.Key.ReadOnly,
HidePasswords = g.Key.HidePasswords,
Manage = g.Key.Manage,
CipherIds = g.Select(c => c.CipherId)
});
CipherIds = g.Select(c => c.CipherId).OfType<Guid>().ToList()
})
.ToList();

var accessDetailsCount = accessDetails.Count();
var accessDetailsCount = accessDetails.Count;
logger.LogInformation(Constants.BypassFiltersEventId, "Completed MemberAccessReport generation for OrganizationId: {OrganizationId}. Generated {AccessDetailsCount} access detail records",
request.OrganizationId, accessDetailsCount);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;

namespace Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;

namespace Bit.Core.Dirt.Reports.ReportFeatures;

Expand All @@ -22,10 +22,10 @@ await _organizationMemberBaseDetailRepository.GetOrganizationMemberBaseDetailsBy
request.OrganizationId);

var insightsDetails = baseDetails
.GroupBy(b => new { b.UserGuid, b.UserName, b.Email, b.UsesKeyConnector })
.GroupBy(b => new { b.OrganizationUserId, b.UserName, b.Email, b.UsesKeyConnector })
.Select(g => new RiskInsightsReportDetail
{
UserGuid = g.Key.UserGuid,
UserGuid = g.Key.OrganizationUserId,
UserName = g.Key.UserName,
Email = g.Key.Email,
UsesKeyConnector = g.Key.UsesKeyConnector,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;

namespace Bit.Core.Dirt.Reports.Repositories;
namespace Bit.Core.Dirt.Repositories;

public interface IOrganizationMemberBaseDetailRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Bit.Core.Auth.Repositories;
using Bit.Core.Billing.Organizations.Repositories;
using Bit.Core.Billing.Providers.Repositories;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.KeyManagement.Repositories;
using Bit.Core.NotificationCenter.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Data;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
using Dapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using AutoMapper;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Bit.Infrastructure.EntityFramework.Dirt;
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories;

public class OrganizationMemberBaseDetailRepository : BaseEntityFrameworkRepository, IOrganizationMemberBaseDetailRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Bit.Core.Auth.Repositories;
using Bit.Core.Billing.Organizations.Repositories;
using Bit.Core.Billing.Providers.Repositories;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Enums;
using Bit.Core.KeyManagement.Repositories;
Expand All @@ -15,7 +14,6 @@
using Bit.Infrastructure.EntityFramework.AdminConsole.Repositories;
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Billing.Repositories;
using Bit.Infrastructure.EntityFramework.Dirt;
using Bit.Infrastructure.EntityFramework.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.KeyManagement.Repositories;
using Bit.Infrastructure.EntityFramework.NotificationCenter.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Bit.Core;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
using Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider;
using Bit.Infrastructure.EntityFramework.Auth.Models;
Expand Down

This file was deleted.

Loading
Loading