Skip to content

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

Merged
voommen-livefront merged 13 commits intomainfrom
dirt/pm-28531/organization-report-metrics
Mar 4, 2026
Merged

[PM-28531] Remove old proc and use new one#7110
voommen-livefront merged 13 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 & Details90c75654-1908-4a9d-bac1-07bde741af05


New Issues (2) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 306
detailsMethod at line 306 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from organizationUser...
Attack Vector
2 MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 306
detailsMethod at line 306 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from model. This par...
Attack Vector

Fixed Issues (2) Great job! The following issues were fixed in this Pull Request
Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 307
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 307

@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 60.74%. Comparing base (1e7f7ac) to head (0717496).
⚠️ Report is 28 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%   60.74%   +4.04%     
==========================================
  Files        2013     2026      +13     
  Lines       88191    88684     +493     
  Branches     7861     7906      +45     
==========================================
+ Hits        50009    53874    +3865     
+ Misses      36362    32901    -3461     
- Partials     1820     1909      +89     

☔ 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

@voommen-livefront voommen-livefront Mar 2, 2026

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 properties are required, otherwise I would get a whole host of null checking in areas of the project that I shouldn't touch - if there is no summary data, than this object is not relevant. And I tested it in the database

image

Copy link
Contributor

Choose a reason for hiding this comment

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

@mkincaid-bw SummaryData and RevisionDate were added later to this table and we used NULL as way to safely add them.

prograhamming
prograhamming previously approved these changes Mar 4, 2026
Copy link
Contributor

@mkincaid-bw mkincaid-bw left a comment

Choose a reason for hiding this comment

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

Couple minor formatting changes.

…ganizationIdAndRevisionDate.sql

Co-authored-by: mkincaid-bw <mkincaid@bitwarden.com>
…adByOrganizationIdAndRevisionDate.sql

Co-authored-by: mkincaid-bw <mkincaid@bitwarden.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

@voommen-livefront voommen-livefront merged commit 4785e62 into main Mar 4, 2026
52 checks passed
@voommen-livefront voommen-livefront deleted the dirt/pm-28531/organization-report-metrics branch March 4, 2026 22:21
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