Skip to content

Conversation

JimmyVo16
Copy link
Contributor

@JimmyVo16 JimmyVo16 commented Oct 7, 2025

🎟️ Tracking

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

📔 Objective

Add a new version of SavePolicyCommand to enable

  1. Individual handlers to access metadata properties
  2. Support pre and post side effects.
  3. Refactor to clean up policy dependencies and validation logic.
  4. Enable each policy to implement only the events relevant to it.
  5. Add unit tests

This code isn’t consumed yet and therefore isn’t testable.

⏰ 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

Copy link
Contributor

github-actions bot commented Oct 7, 2025

Logo
Checkmarx One – Scan Summary & Details026e22f5-784a-456a-92ca-664b44f6b98c

New Issues (2)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1511
detailsMethod at line 1511 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
ID: pN371p7oxzg66CFSL1H%2F7897Dng%3D
Attack Vector
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1392
detailsMethod at line 1392 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
ID: xow1RlTy2gYME4GMTq55sfh%2BBY0%3D
Attack Vector
Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 299

Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 98.64865% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.72%. Comparing base (3272586) to head (4408040).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...Policies/Implementations/VNextSavePolicyCommand.cs 98.46% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6426      +/-   ##
==========================================
+ Coverage   50.55%   50.72%   +0.16%     
==========================================
  Files        1854     1866      +12     
  Lines       82184    82696     +512     
  Branches     7262     7307      +45     
==========================================
+ Hits        41547    41944     +397     
- Misses      39047    39154     +107     
- Partials     1590     1598       +8     

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

@JimmyVo16 JimmyVo16 self-assigned this Oct 8, 2025
@JimmyVo16 JimmyVo16 marked this pull request as ready for review October 8, 2025 16:36
@JimmyVo16 JimmyVo16 requested a review from a team as a code owner October 8, 2025 16:36
@JimmyVo16 JimmyVo16 requested a review from r-tome October 8, 2025 16:36

private static Dictionary<PolicyType, IEnforceDependentPoliciesEvent> MapToDictionary(IEnumerable<IEnforceDependentPoliciesEvent> policyValidationEventHandlers)
{
var policyValidationEventsDict = new Dictionary<PolicyType, IEnforceDependentPoliciesEvent>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m not sure if this is needed since it’s from the old pattern. I think it was meant to prevent duplicates, but that was when everything was in one interface. Now we have four interfaces, so I’m not sure it makes sense anymore. I’m happy to remove it.

Copy link
Contributor

@r-tome r-tome left a comment

Choose a reason for hiding this comment

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

Overall this looks great, but since it’s a complex solution, I think it would really benefit from thorough documentation.

  • add xmldoc to every new interface clarifying what it represents and when its called
  • VNextSavePolicyCommand explain the execution flow

Policy? currentPolicy)
{
await ExecutePolicyEventAsync<IPolicyValidationEvent>(
currentPolicy!.Type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we always expect the currentPolicy to not be null? What happens when we're setting up a policy the first time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that should have used the type from the request object.


private static void ValidateEnablingRequirements(
IEnforceDependentPoliciesEvent validator,
Policy? currentPolicy,
Copy link
Contributor

Choose a reason for hiding this comment

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

currentPolicy is not used

public interface IOnPolicyPreUpdateEvent : IPolicyUpdateEvent
{
/// <summary>
/// Performs side effects before a policy is upserted.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I’m addressing your comments here so we can have a thread on it.

Original comment

add xmldoc to every new interface clarifying what it represents and when its called

I added documentation to the method in the interface, would that be sufficient? I’m happy to adjust it if needed, but I’d prefer to avoid duplicating the same text in two places.

@JimmyVo16 JimmyVo16 requested a review from r-tome October 9, 2025 19:09
@JimmyVo16 JimmyVo16 requested a review from r-tome October 10, 2025 15:13
@JimmyVo16 JimmyVo16 merged commit 6072104 into main Oct 10, 2025
40 checks passed
@JimmyVo16 JimmyVo16 deleted the ac/pm-25823/vnext-policy-upsert-pattern branch October 10, 2025 15:23
aliwahhan added a commit to aliwahhan/server that referenced this pull request Oct 12, 2025
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.

2 participants