1
0
mirror of https://github.com/bitwarden/server synced 2025-12-10 21:33:41 +00:00

Organization report tables, repos, services, and endpoints (#6158)

* PM-23754 initial commit

* pm-23754 fixing controller tests

* pm-23754 adding commands and queries

* pm-23754 adding endpoints, command/queries, repositories, and sql migrations

* pm-23754 add new sql scripts

* PM-23754 adding sql scripts

* pm-23754

* PM-23754 fixing migration script

* PM-23754 fixing migration script again

* PM-23754 fixing migration script validation

* PM-23754 fixing db validation script issue

* PM-23754 fixing endpoint and db validation

* PM-23754 fixing unit tests

* PM-23754 fixing implementation based on comments and tests

* PM-23754 updating logging statements

* PM-23754 making changes based on PR comments.

* updating migration scripts

* removing old migration files

* update code based testing for whole data object for OrganizationReport and add a stored procedure.

* updating services, unit tests, repository tests

* fixing unit tests

* fixing migration script

* fixing migration script again

* fixing migration script

* another fix

* fixing sql file, updating controller to account for different orgIds in the url and body.

* updating error message in controllers without a body

* making a change to the command

* Refactor ReportsController by removing organization reports

The IDropOrganizationReportCommand is no longer needed

* will code based on PR comments.

* fixing unit test

* fixing migration script based on last changes.

* adding another check in endpoint and adding unit tests

* fixing route parameter.

* PM-23754 updating data fields to return just the column

* PM-23754 fixing repository method signatures

* PM-23754 making change to orgId parameter through out code to align with api naming

---------

Co-authored-by: Tom <144813356+ttalty@users.noreply.github.com>
This commit is contained in:
Graham Walker
2025-09-08 15:06:13 -05:00
committed by GitHub
parent cb0d5a5ba6
commit 226f274a72
79 changed files with 24744 additions and 1047 deletions

View File

@@ -3,6 +3,7 @@
using System.Data;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
@@ -23,26 +24,153 @@ public class OrganizationReportRepository : Repository<OrganizationReport, Guid>
{
}
public async Task<ICollection<OrganizationReport>> GetByOrganizationIdAsync(Guid organizationId)
public async Task<OrganizationReport> GetLatestByOrganizationIdAsync(Guid organizationId)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
{
var results = await connection.QueryAsync<OrganizationReport>(
$"[{Schema}].[OrganizationReport_ReadByOrganizationId]",
var result = await connection.QuerySingleOrDefaultAsync<OrganizationReport>(
$"[{Schema}].[OrganizationReport_GetLatestByOrganizationId]",
new { OrganizationId = organizationId },
commandType: CommandType.StoredProcedure);
return results.ToList();
return result;
}
}
public async Task<OrganizationReport> GetLatestByOrganizationIdAsync(Guid organizationId)
public async Task<OrganizationReport> UpdateSummaryDataAsync(Guid organizationId, Guid reportId, string summaryData)
{
return await GetByOrganizationIdAsync(organizationId)
.ContinueWith(task =>
using (var connection = new SqlConnection(ConnectionString))
{
var reports = task.Result;
return reports.OrderByDescending(r => r.CreationDate).FirstOrDefault();
});
var parameters = new
{
Id = reportId,
OrganizationId = organizationId,
SummaryData = summaryData,
RevisionDate = DateTime.UtcNow
};
await connection.ExecuteAsync(
$"[{Schema}].[OrganizationReport_UpdateSummaryData]",
parameters,
commandType: CommandType.StoredProcedure);
// Return the updated report
return await connection.QuerySingleOrDefaultAsync<OrganizationReport>(
$"[{Schema}].[OrganizationReport_ReadById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
}
}
public async Task<OrganizationReportSummaryDataResponse> GetSummaryDataAsync(Guid reportId)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
{
var result = await connection.QuerySingleOrDefaultAsync<OrganizationReportSummaryDataResponse>(
$"[{Schema}].[OrganizationReport_GetSummaryDataById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
return result;
}
}
public async Task<IEnumerable<OrganizationReportSummaryDataResponse>> GetSummaryDataByDateRangeAsync(
Guid organizationId,
DateTime startDate, DateTime
endDate)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
{
var parameters = new
{
OrganizationId = organizationId,
StartDate = startDate,
EndDate = endDate
};
var results = await connection.QueryAsync<OrganizationReportSummaryDataResponse>(
$"[{Schema}].[OrganizationReport_GetSummariesByDateRange]",
parameters,
commandType: CommandType.StoredProcedure);
return results;
}
}
public async Task<OrganizationReportDataResponse> GetReportDataAsync(Guid reportId)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
{
var result = await connection.QuerySingleOrDefaultAsync<OrganizationReportDataResponse>(
$"[{Schema}].[OrganizationReport_GetReportDataById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
return result;
}
}
public async Task<OrganizationReport> UpdateReportDataAsync(Guid organizationId, Guid reportId, string reportData)
{
using (var connection = new SqlConnection(ConnectionString))
{
var parameters = new
{
OrganizationId = organizationId,
Id = reportId,
ReportData = reportData,
RevisionDate = DateTime.UtcNow
};
await connection.ExecuteAsync(
$"[{Schema}].[OrganizationReport_UpdateReportData]",
parameters,
commandType: CommandType.StoredProcedure);
// Return the updated report
return await connection.QuerySingleOrDefaultAsync<OrganizationReport>(
$"[{Schema}].[OrganizationReport_ReadById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
}
}
public async Task<OrganizationReportApplicationDataResponse> GetApplicationDataAsync(Guid reportId)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
{
var result = await connection.QuerySingleOrDefaultAsync<OrganizationReportApplicationDataResponse>(
$"[{Schema}].[OrganizationReport_GetApplicationDataById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
return result;
}
}
public async Task<OrganizationReport> UpdateApplicationDataAsync(Guid organizationId, Guid reportId, string applicationData)
{
using (var connection = new SqlConnection(ConnectionString))
{
var parameters = new
{
OrganizationId = organizationId,
Id = reportId,
ApplicationData = applicationData,
RevisionDate = DateTime.UtcNow
};
await connection.ExecuteAsync(
$"[{Schema}].[OrganizationReport_UpdateApplicationData]",
parameters,
commandType: CommandType.StoredProcedure);
// Return the updated report
return await connection.QuerySingleOrDefaultAsync<OrganizationReport>(
$"[{Schema}].[OrganizationReport_ReadById]",
new { Id = reportId },
commandType: CommandType.StoredProcedure);
}
}
}