Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement report approvals #24639

Merged
merged 53 commits into from
Aug 28, 2023
Merged

Implement report approvals #24639

merged 53 commits into from
Aug 28, 2023

Conversation

youssef-lr
Copy link
Contributor

@youssef-lr youssef-lr commented Aug 16, 2023

Details

cc @mountiny @luacmartins

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/303752

Tests

  • Verify that no errors appear in the JS console
  1. Create a Control policy in OldDot.
  2. Enable this policy for expense chats, replace {policyID} with the ID of the policy we just created:
update nameValuePairs set value = JSON_SET(value, '$.isPolicyExpenseChatEnabled', 'true') where name = "expensify_policy{policyID}";
  1. Invite two members, let's call them teacher@school.edu and principal@school.edu
  2. Set the submitsTo of teacher@school.edu to principal@school.edu, meaning the principal will be the manager of the teacher. Do not set a forwardsTo.
  3. Head to NewDot and log in as the teacher.
  4. Navigate to the workspace chat.
  5. Click on "+" and created a Split Bill request.
  6. Log in as the principal now principal@school.edu
  7. Make sure the expense report in the LHN and a green dot next to it. The policy expense chat will NOT appear.
  8. Make sure you see the 'Approve' button. Do not approve yet.
  9. Log in now as the admin of the control policy.
  10. Make sure you see both the policy expense chat of the teacher and the expense report create.
  11. Verify no green dot appears next to the expense report. Navigate to the report and verify you don't see the 'Approve' button nor the settlement button.
  12. Log in back to the principal account so we can approve the report.
  13. Approve the report and make sure an approved ${amount} action has been created.
  14. Make sure the IOU preview displays Cash • Approved.
  15. The green dot should disappear now.
  16. Let's login as the admin of the policy again.
  17. The green dot should appear next to the expense report.
  18. You should see the settlement button now when that the report has been approved.
  19. Navigate to the policy expense chat, and make sure the report preview says principal@school.edu approved ${amount}.

Note: there is currently a bug being worked on where the expense report shows initially $0 because we are not fetching the transactions from Auth and setting them in Onyx. The Split report action will also show $0 when you log out then back in.

Offline tests

QA Steps

Must be QA'ed internally, same steps as above.

  • Verify that no errors appear in the JS console

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 / Chrome
    • iOS / native
    • iOS / 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 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 verified the translation was requested/reviewed 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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.js 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 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(themeColors.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 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.
  • 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Mobile Web - Chrome
Screen.Recording.2023-08-28.at.14.33.18.mov
Mobile Web - Safari
Desktop
iOS
Android

@youssef-lr youssef-lr force-pushed the youssef_approve_money_request branch from 14fc52f to 00fb139 Compare August 16, 2023 17:53
@youssef-lr youssef-lr force-pushed the youssef_approve_money_request branch from 4716a6b to 5de9792 Compare August 16, 2023 20:46
@youssef-lr youssef-lr changed the title Implement report approvals [HOLD App#24058] Implement report approvals Aug 16, 2023
@youssef-lr
Copy link
Contributor Author

youssef-lr commented Aug 28, 2023

This is failing for the admin. I can see the green dot next to the expense report. I can also see both approve and pay buttons and their style is a bit off.

@luacmartins Hmm I'm not able to reproduce this, can you show me please how the configuration looks like in oldDot => people?

@youssef-lr
Copy link
Contributor Author

youssef-lr commented Aug 28, 2023

the admin did not get notified about the approval (until they load the expense report)

Hmm yeah I noticed this recently, I could swear it was working fine before. I'll create an issue for this to be fixed in Web-E.

Edit: created issue https://github.com/Expensify/Expensify/issues/311998

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

Worked 1:1 with @youssef-lr to solve remaining blockers. All good now!

@luacmartins luacmartins merged commit 0343bfe into main Aug 28, 2023
12 of 13 checks passed
@luacmartins luacmartins deleted the youssef_approve_money_request branch August 28, 2023 22:58
@melvin-bot melvin-bot bot added the Emergency label Aug 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 28, 2023

@luacmartins looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@luacmartins
Copy link
Contributor

tests passed

@OSBotify
Copy link
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.

@Pujan92
Copy link
Contributor

Pujan92 commented Aug 29, 2023

@youssef-lr seems causing a console warning regression where policy is passed undefined and has required prop for the child component MoneyRequestHeader.

Screenshot 2023-08-30 at 00 39 22

https://expensify.slack.com/archives/C049HHMV9SM/p1693292429308959
cc: @gadhiyamanan

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.59-0 🚀

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

return false;
}

return report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report.statusNum === CONST.REPORT.STATUS.REIMBURSED;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing the deploy blocker here: #26322

If I change this line back to

return report.stateNum > CONST.REPORT.STATE_NUM.PROCESSING;

It works again.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.60-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.60-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.59-5 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.60-3 🚀

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

Comment on lines +1136 to +1147
// If the report is already settled, there's no action required from any user.
if (isSettled(report.reportID)) {
return false;
}

// Report is pending approval and the current user is the manager
if (isReportManager(report) && !isReportApproved(report)) {
return true;
}

// Current user is an admin and the report has been approved but not settled yet
return policy.role === CONST.POLICY.ROLE.ADMIN && isReportApproved(report);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may be missing the case where the employee is missing a bank account and the report gets the RNVP isWaitingOnBankAccount . For CORPORATE policies, I think we should also return true if the report has isWaitingOnBankAccount and the current user is the submitter, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

And we should return false if report.isWaitingOnBankAccount is truthy and the current user is NOT the submitter because the we are expecting an action on the submitter. What actions could the admin or manager take?

}
// STEP 2: Get existing IOU/Expense report and update its total OR build a new optimistic one
// For Control policy expense chats, if the report is already approved, create a new expense report
let oneOnOneIOUReport = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${oneOnOneChatReport.iouReportID}`, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #28330:
As this line was called without !isNewOneOnOneIOUReport check, it was possible to get all reports with oneOnOneChatReport.iouReportID being empty string.

let amount = CurrencyUtils.convertToDisplayString(total, currency);
const amount =
type === CONST.IOU.REPORT_ACTION_TYPE.PAY
? CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(getReport(iouReportID)), currency)
Copy link
Contributor

Choose a reason for hiding this comment

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

When we create all optimistic reports, report actions etc the report is not readily available in Onyx and even though this function gets total as a param the total is shown as zero for the first time the optimistic actions were created. This caused #43907

*/
function getPolicyName(report, returnEmptyIfNotFound = false, policy = undefined) {
const noPolicyFound = returnEmptyIfNotFound ? '' : Localize.translateLocal('workspace.common.unavailable');
if (_.isEmpty(report)) {
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 had checked if allPolicies are empty here, this caused #44480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
InternalQA This pull request required internal QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants