Skip to content

[PM-28531] Remove old proc and use new one#7110

Open
voommen-livefront wants to merge 11 commits intomainfrom
dirt/pm-28531/organization-report-metrics
Open

[PM-28531] Remove old proc and use new one#7110
voommen-livefront wants to merge 11 commits intomainfrom
dirt/pm-28531/organization-report-metrics

Conversation

@voommen-livefront
Copy link
Collaborator

@voommen-livefront voommen-livefront commented Feb 27, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-28531

📔 Objective

  1. Removed procedure OrganizationReport_GetSummariesByDateRange as it didn't confirm to naming convention
  2. Created new proc OrganizationReport_ReadByOrganizationIdAndRevisionDate
  3. Update repo to use this new proc
  4. Updated model to include encrpytion key, org id and date.

📸 Screenshots

image

@voommen-livefront voommen-livefront requested review from a team as code owners February 27, 2026 19:05
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Logo
Checkmarx One – Scan Summary & Detailsd554ea86-f03c-4a13-b02f-a3aae8aac240

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 78.26087% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.45%. Comparing base (1e7f7ac) to head (2a4f451).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
.../Dirt/Repositories/OrganizationReportRepository.cs 0.00% 9 Missing ⚠️
...ucture.Dapper/Dirt/OrganizationReportRepository.cs 0.00% 3 Missing ⚠️
...etOrganizationReportSummaryDataByDateRangeQuery.cs 94.28% 1 Missing and 1 partial ⚠️
.../Dirt/Controllers/OrganizationReportsController.cs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7110      +/-   ##
==========================================
- Coverage   56.70%   56.45%   -0.25%     
==========================================
  Files        2013     2014       +1     
  Lines       88191    88151      -40     
  Branches     7861     7863       +2     
==========================================
- Hits        50009    49770     -239     
- Misses      36362    36565     +203     
+ Partials     1820     1816       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

prograhamming
prograhamming previously approved these changes Mar 2, 2026
prograhamming
prograhamming previously approved these changes Mar 2, 2026
Comment on lines +9 to +18
SELECT
[OrganizationId],
[ContentEncryptionKey],
[SummaryData],
[RevisionDate]
FROM [dbo].[OrganizationReportView]
WHERE [OrganizationId] = @OrganizationId
AND [RevisionDate] >= @StartDate
AND [RevisionDate] <= @EndDate
ORDER BY [RevisionDate] DESC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire SELECT statement should be indented 4 spaces, and SQL keywords should be on their own line
https://contributing.bitwarden.com/contributing/code-style/sql#select-statements

Suggested change
SELECT
[OrganizationId],
[ContentEncryptionKey],
[SummaryData],
[RevisionDate]
FROM [dbo].[OrganizationReportView]
WHERE [OrganizationId] = @OrganizationId
AND [RevisionDate] >= @StartDate
AND [RevisionDate] <= @EndDate
ORDER BY [RevisionDate] DESC
SELECT
[OrganizationId],
[ContentEncryptionKey],
[SummaryData],
[RevisionDate]
FROM
[dbo].[OrganizationReportView]
WHERE
[OrganizationId] = @OrganizationId
AND [RevisionDate] >= @StartDate
AND [RevisionDate] <= @EndDate
ORDER BY
[RevisionDate] DESC

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't commit this suggestion because I renamed the file, but I have updated the formatting in the new file,

@@ -0,0 +1,23 @@
DROP PROC IF EXISTS [dbo].[OrganizationReport_GetSummariesByDateRange]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not follow our EDD pattern.
https://contributing.bitwarden.com/contributing/database-migrations/edd/

Database changes must be deployable independently of code changes, and must support both the current and next release. Dropping this proc should happen later in another PR once the server code has been deployed and hardened a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkincaid-bw The procedure and the endpoint weren't used this far.
It is safe to drop the proc in this PR as it is being replaced by a new one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, my apologies for this PR being so large - I should have made two PR's one with the DB changes and another with the code changes. I came in this morning thinking of what else I got to do next and didn't think about making another PR.

BEGIN
SET NOCOUNT ON

SELECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above re: formatting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name is OrganizationReport_ReadyByOrganizationIdAndRevisionDate.sql (_ReadyBy...) but should be OrganizationReport_ReadByOrganizationIdAndRevisionDate.sql (_ReadBy...) to match the stored proc name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so sorry about this - I should have fixed this before this was made available to you.

public string? SummaryData { get; set; }
public required Guid OrganizationId { get; set; }
[JsonPropertyName("encryptedData")]
public required string SummaryData { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SummaryData and RevisionDate (below) properties are required here, but both columns in the DB allow nulls. Not sure if it's an issue or not but I just wanted to point it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkincaid-bw you are right - the procedures are required - if there is no summary data, than this object is not relevant. And I tested it in the database

image

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants