Skip to content

Block report submission when strict policy rules are enabled with violations#72663

Merged
mountiny merged 24 commits into
Expensify:mainfrom
abzokhattab:strict-policy-submit-block
Oct 23, 2025
Merged

Block report submission when strict policy rules are enabled with violations#72663
mountiny merged 24 commits into
Expensify:mainfrom
abzokhattab:strict-policy-submit-block

Conversation

@abzokhattab

@abzokhattab abzokhattab commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #70990
PROPOSAL: #70990 (comment)

Tests

Prerequisites:

  • Enable "Strictly Enforce Workspace Rules" in Domain Settings
  • Workspace must have at least one policy rule
  1. Log in as a submitter in the domain with strict policy rules enabled
  2. Submit a report that contains policy violations in NewDot
  3. Go to Reports and open the created report
  4. verify that the Submit button is disabled and next step message shows: "'Waiting for you to fix the issues. Your admins have restricted submission of expenses with violations."
  5. Go back - verify Review button shows in report preview

Offline tests

Same as tests

QA Steps

same as tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2025-10-19.at.00.28.42.mov
Android: mWeb Chrome
Screen.Recording.2025-10-19.at.00.34.36.mov
iOS: Native
Screen.Recording.2025-10-19.at.00.28.42.mov
iOS: mWeb Safari
Screen.Recording.2025-10-19.at.00.34.36.mov
MacOS: Chrome / Safari https://github.com/user-attachments/assets/fb9c340a-ff1f-46f0-9477-01c0b7b58b63
MacOS: Desktop
Screen.Recording.2025-10-19.at.00.35.18.mov

@abzokhattab abzokhattab marked this pull request as ready for review October 15, 2025 07:01
@abzokhattab abzokhattab requested a review from a team as a code owner October 15, 2025 07:01
@melvin-bot melvin-bot Bot requested review from akinwale and removed request for a team October 15, 2025 07:01
@melvin-bot

melvin-bot Bot commented Oct 15, 2025

Copy link
Copy Markdown

@akinwale Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@abzokhattab abzokhattab marked this pull request as draft October 15, 2025 07:01
Comment thread src/languages/en.ts Outdated
dates: 'Dates',
rates: 'Rates',
submitsTo: ({name}: SubmitsToParams) => `Submits to ${name}`,
waitingForSubmitterToFixViolations: 'Waiting for you to fix the issue(s). Your admins have restricted submission of expenses that have violations.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jamesdeanexpensify is asking for a small copy update here @abzokhattab.

'Waiting for you to fix the issue(s). Your admins have restricted submission of expenses with violations.',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a different question: should we translate this message into other languages, or keep it in English? In NextStepUtils.ts, all the text is hardcoded in English ... should we follow the same pattern? or translate it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point, if this is a NextSteps text showing at the report header and that is all in english right now, I think we should not translate only this one now. The transactions for them all would possibly come later.

cc @trjExpensify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree.

@abzokhattab abzokhattab Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, I kept it hardcoded and moved this logic to NextStepUtils.ts, similar to the buildOptimisticNextStepForPreventSelfApprovalsEnabled function to keep the optimistic values logic in one place and not scattered .. commit details: d48987b

@codecov

codecov Bot commented Oct 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/components/MoneyReportHeader.tsx 0.00% 7 Missing ⚠️
src/components/MoneyReportHeaderStatusBar.tsx 0.00% 2 Missing ⚠️
src/components/AnimatedSubmitButton/index.tsx 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
...ReportPreview/MoneyRequestReportPreviewContent.tsx 63.40% <100.00%> (+0.13%) ⬆️
src/hooks/useStrictPolicyRules.ts 100.00% <100.00%> (ø)
src/libs/NextStepUtils.ts 64.80% <100.00%> (+0.42%) ⬆️
src/libs/ReportPreviewActionUtils.ts 91.04% <100.00%> (+0.20%) ⬆️
src/libs/ReportUtils.ts 74.49% <100.00%> (+0.04%) ⬆️
src/components/AnimatedSubmitButton/index.tsx 2.00% <0.00%> (ø)
src/components/MoneyReportHeaderStatusBar.tsx 22.22% <0.00%> (ø)
src/components/MoneyReportHeader.tsx 0.18% <0.00%> (-0.01%) ⬇️

... and 15 files with indirect coverage changes

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

@abzokhattab abzokhattab marked this pull request as ready for review October 18, 2025 23:02
@abzokhattab

Copy link
Copy Markdown
Contributor Author

The pr is now ready

@trjExpensify

Copy link
Copy Markdown
Contributor

Wahooo! @akinwale can you prioritise the review today, please?

@akinwale

Copy link
Copy Markdown
Contributor

Wahooo! @akinwale can you prioritise the review today, please?

Will do.

@akinwale

akinwale commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp 72663-android-hybrid
Android: mWeb Chrome 72663-android-chrome
iOS: HybridApp 72663-ios-hybrid
iOS: mWeb Safari 72663-ios-safari
MacOS: Chrome / Safari
72663-web.mp4
MacOS: Desktop 72663-desktop

@akinwale akinwale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@melvin-bot melvin-bot Bot requested a review from NikkiWines October 20, 2025 17:32

@NikkiWines NikkiWines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good - a couple of NABs and questions

Comment thread src/libs/ReportUtils.ts Outdated
Comment thread src/languages/en.ts Outdated
Comment thread src/hooks/useStrictPolicyRules.ts
Comment thread src/components/MoneyReportHeaderStatusBar.tsx

@akinwale akinwale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-tested. LGTM.

@mountiny

Copy link
Copy Markdown
Contributor

@abzokhattab LEt me know in slack once you address these, thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Performance Violations Found

PERF-6 - Use specific properties as hook dependencies

File: src/components/MoneyReportHeader.tsx
Line: 222

The dependencies violations and transactions are entire objects/arrays. This causes the hook to re-execute whenever any property changes, even unrelated ones.

Fix: Use specific properties instead:

  • transactions.length instead of transactions
  • Object.keys(violations).length instead of violations

PERF-6 - Use specific properties as hook dependencies

File: src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Line: 485-497

The dependencies include entire objects like violations, iouReport, policy, transactions, and invoiceReceiverPolicy. This causes unnecessary re-executions when unrelated properties change.

Fix: Use specific properties from these objects instead of passing the entire objects.

@github-actions

Copy link
Copy Markdown
Contributor

HelpDot Documentation Review

Overall Assessment

This PR (#72663) focuses entirely on implementing functionality to block report submission when strict policy rules are enabled with violations. No documentation files were modified in this PR.

Analysis Summary

  • Files Changed: 13 files (all TypeScript code and test files)
  • Documentation Files: None
  • Scope: Pure backend/frontend functionality implementation
  • Feature: Strict policy rules enforcement for report submission

Documentation Impact Assessment

While this PR introduces new user-facing functionality (blocking report submission with policy violations), it does not include any accompanying documentation updates.

Key Findings

  • Code Quality: Well-structured implementation with comprehensive test coverage
  • Feature Completeness: Includes proper UI feedback and error messaging
  • ⚠️ Documentation Gap: No help documentation was updated to reflect this new behavior

Recommendations

Since this PR introduces a significant change to user workflow (blocking report submission), consider:

  1. User Documentation: Update relevant help articles in the docs/ or help/ directories to explain:

    • How strict policy rules work
    • What users see when submission is blocked
    • How to resolve policy violations
  2. Admin Documentation: Document the 'Strictly Enforce Workspace Rules' setting for workspace administrators

  3. FAQ Updates: Add common questions about policy violation handling

Conclusion

No documentation review needed for this PR as it contains no documentation changes. However, this feature may warrant future documentation updates to help users understand the new strict policy enforcement behavior.

Note: This assessment focuses on documentation quality standards since no documentation files were present in this PR.

@mountiny

Copy link
Copy Markdown
Contributor

@kacper-mikolajczak @adamgrzybowski this comment I think seems a bit off on this PR #72663 (comment) I dont think there is other way to implement this

@mountiny

Copy link
Copy Markdown
Contributor

@abzokhattab There seems to be conflicts

@abzokhattab

Copy link
Copy Markdown
Contributor Author

fixed

*/
function useStrictPolicyRules(): UseStrictPolicyRulesResult {
const [myDomainSecurityGroups] = useOnyx(ONYXKEYS.MY_DOMAIN_SECURITY_GROUPS, {canBeMissing: true});
const [securityGroups] = useOnyx(ONYXKEYS.COLLECTION.SECURITY_GROUP, {canBeMissing: true});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder how we could incorporate the selector for the groupID here already since it's dependent on the other useOnyx @TMisiukiewicz

@mountiny mountiny merged commit 8504026 into Expensify:main Oct 23, 2025
23 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.2.37-1 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@izarutskaya

Copy link
Copy Markdown

@abzokhattab PR is failing with original bug ID #70990

1761309673062.72663_desktop.mp4
1761310071470.72663_iOS.mp4

@trjExpensify

Copy link
Copy Markdown
Contributor

@abzokhattab PR is failing with original bug ID #70990

@izarutskaya can you expand on that? How is it failing? Your video looks like it's behaving as expected. The user is prevented from submitting a report with this restriction.

image

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.2.37-8 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@kacper-mikolajczak

Copy link
Copy Markdown
Contributor

this comment I think seems a bit off on this PR #72663 (comment) I dont think there is other way to implement this

You are clearly right @mountiny! These are not actual violations - I will take a look on how we could improve PERF-6 rule detection and get back to you.

const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep;
let optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep;

if (shouldBlockSubmit && isReportOwner(moneyRequestReport)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In #73426, we decided to only show the violation with open expense report.

More details in:
#73426 (comment)

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.

10 participants