bitwarden-server/util
Rui Tomé 3866bc5155
[PM-23134] Update PolicyDetails sprocs for performance (#6421)
* Add integration tests for GetByUserIdWithPolicyDetailsAsync in OrganizationUserRepository

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

* Add UserProviderAccessView to identify which organizations a user can access as a provider

* Refactor PolicyDetails_ReadByUserId stored procedure to improve user 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.

* Refactor OrganizationUser_ReadByUserIdWithPolicyDetails stored procedure 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.

* Add new SQL migration script to refactor policy details queries

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

* Remove GetPolicyDetailsByUserIdTests

* Refactor PolicyRequirementQuery to use GetPolicyDetailsByUserIdsAndPolicyType and update unit tests

* Remove GetPolicyDetailsByUserId method from IPolicyRepository and its implementations in PolicyRepository classes

* Revert changes to PolicyDetails_ReadByUserId stored procedure

* Refactor OrganizationUser_ReadByUserIdWithPolicyDetails stored procedure to use UNION instead of OR

* Reduce UserEmail variable size from NVARCHAR(320) to NVARCHAR(256) for consistency in stored procedures

* Bump date on migration script
2025-10-22 13:20:53 +01:00
..
Attachments Fix attachments container (#6165) 2025-08-06 14:44:01 -04:00
DbSeederUtility [PM-21075] Initial database seeder (#5703) 2025-05-09 15:00:26 +02:00
EfShared [PM-2633] Warnings cleanup (#3010) 2023-06-16 10:02:05 -04:00
Migrator [PM-23134] Update PolicyDetails sprocs for performance (#6421) 2025-10-22 13:20:53 +01:00
MsSql feat: non-root self hosted images for standard deployment (#5701) 2025-05-30 10:29:47 -07:00
MsSqlMigratorUtility BRE-917 Update to Alpine base (#5976) 2025-07-28 10:56:20 -04:00
MySqlMigrations [PM-26361] Add User Auto Confirmation (#6436) 2025-10-20 07:27:18 -05:00
Nginx Fixed Nginx entrypoint to cp with preserve owner (#6249) 2025-08-28 09:36:02 -04:00
PostgresMigrations [PM-26361] Add User Auto Confirmation (#6436) 2025-10-20 07:27:18 -05:00
RustSdk [PM-22263] Integate Rust SDK to Seeder (#6150) 2025-10-21 23:46:37 +02:00
Seeder [PM-22263] Integate Rust SDK to Seeder (#6150) 2025-10-21 23:46:37 +02:00
Server Add #nullable disable to platform code (#6057) 2025-07-08 10:25:59 -04:00
Setup Fix Dockerfiles that had BUILDPLATFORM specified for App Stages (#6162) 2025-08-05 17:36:04 -04:00
SqliteMigrations [PM-26361] Add User Auto Confirmation (#6436) 2025-10-20 07:27:18 -05:00
SqlServerEFScaffold [deps] DbOps: Pin dependencies (#5715) 2025-04-28 22:04:00 -04:00