Skip to content

Conversation

r-tome
Copy link
Contributor

@r-tome r-tome commented Oct 7, 2025

🎟️ Tracking

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

📔 Objective

Modified OrganizationUser_ReadByUserIdWithPolicyDetails to use a CTE and the new stored procedure UserProviderAccessView, as outlined in the dbops update.

Updated PolicyRequirementQuery to use PolicyDetails_ReadByUserIdsPolicyType.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

r-tome added 6 commits October 2, 2025 14:52
…zationUserRepository

- Implemented multiple test cases to verify the behavior of GetByUserIdWithPolicyDetailsAsync for different user statuses (Confirmed, Accepted, Invited, Revoked).
- Ensured that the method returns correct policy details based on user status and organization.
- Added tests for scenarios with multiple organizations and non-existing policy types.
- Included checks for provider users and custom user permissions.

These tests enhance coverage and ensure the correctness of policy retrieval logic.
…access logic

- Introduced a Common Table Expression (CTE) for organization users to streamline the selection process based on user status and email.
- Added a CTE for providers to enhance clarity and maintainability.
- Updated the main query to utilize the new CTEs, improving readability and performance.
- Ensured that the procedure correctly identifies provider access based on user permissions.
…ure to enhance user access logic

- Introduced a Common Table Expression (CTE) for organization users to improve selection based on user status and email.
- Updated the main query to utilize the new CTEs, enhancing readability and performance.
- Adjusted the logic for identifying provider access to ensure accurate policy retrieval based on user permissions.
- Created a new view, UserProviderAccessView, to streamline user access to provider organizations.
- Introduced two stored procedures: PolicyDetails_ReadByUserId and OrganizationUser_ReadByUserIdWithPolicyDetails, enhancing the logic for retrieving policy details based on user ID and policy type.
- Utilized Common Table Expressions (CTEs) to improve query readability and performance, ensuring accurate policy retrieval based on user permissions and organization status.
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.65%. Comparing base (98210b5) to head (71dd6c4).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6421      +/-   ##
==========================================
+ Coverage   50.42%   54.65%   +4.22%     
==========================================
  Files        1853     1853              
  Lines       82394    82120     -274     
  Branches     7265     7260       -5     
==========================================
+ Hits        41550    44880    +3330     
+ Misses      39260    35574    -3686     
- Partials     1584     1666      +82     

☔ 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.

Copy link
Contributor

github-actions bot commented Oct 7, 2025

Logo
Checkmarx One – Scan Summary & Details92cef538-80ee-474f-9c58-68ac0cc8c72d

New Issues (1)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Use_Of_Hardcoded_Password /src/Core/Constants.cs: 146
detailsThe application uses the hard-coded password CipherRepositoryBulkResourceCreation for authentication purposes, either using it to verify users' id...
ID: Iw7LlQy2lHqcXY3odicwEquu6vw%3D
Attack Vector

@r-tome r-tome requested a review from JimmyVo16 October 7, 2025 12:55
Copy link
Contributor

@JimmyVo16 JimmyVo16 left a comment

Choose a reason for hiding this comment

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

Just one recommendation.

[dbo].[OrganizationUserView] OU
WHERE
(OU.[Status] <> 0 AND OU.[UserId] = @UserId)
OR (OU.[Status] = 0 AND OU.[Email] = @UserEmail AND @UserEmail IS NOT NULL)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use UNION instead of OR. Here’s an example: maybe we can turn this UNION into a view and use it for both stored procedures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bitwarden/dept-dbops what do you think?

Choose a reason for hiding this comment

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

I did a quick test and the UNION does perform slightly better than the OR clause, which is what I expected.

@r-tome r-tome marked this pull request as ready for review October 8, 2025 10:35
@r-tome r-tome requested review from a team as code owners October 8, 2025 10:35
@r-tome r-tome requested a review from eliykat October 8, 2025 10:35
@eliykat
Copy link
Member

eliykat commented Oct 9, 2025

@JimmyVo16 has already been looking at this so I'll let him handle the review.

@eliykat eliykat removed their request for review October 9, 2025 03:53
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.

4 participants