Skip to content

[Simple AA in NewDot] Make sure optimistic Next Steps & report action are set for Control mid-level "Approvals" in NewDot #43567

@Beamanator

Description

@Beamanator

Tracking issue: https://github.com/Expensify/Expensify/issues/393839

Design doc section: Make sure optimistic Next Steps & report action are set correctly, for “Approve” (old term “Forward”) in NewDot

Goals:

  1. Set optimistic next steps for approvals, when policy is Control and on Advanced Approval mode
    • Specifically new for mid-level approvers
  2. Need to build basic approval chain from policy employeeList in order to be able to figure out who should optimistically be the next approval
  3. Also needs to optimistically add Approved <total> report action to workspace chat

Background:

We currently generate optimistic Next Steps when approving a report in NewDot here. The current possible next steps are:

  1. “Finished! No further action required”
  2. “Next steps: Waiting for you to pay the expenses”

Problem:

There are now more possible cases when a report is getting approved!

When a Control policy has "Advanced Approvals" enabled, there can be multiple "mid-level" approvers. When these members approve the policy, we actually call this "forwarding" - because we "forward" the report to the next person in line. The final approver actually does the "approving".

Solution:

  1. Build the report's approval chain any time someone approves a report on a Control workspace with advanced approvals enabled
    • Note: For v1 we will only consider submitsTo, forwardsTo, and overLimitForwardsTo. Later, we'll add in rule approvers (tag & category)
  2. Optimistically add a report action saying approved <total> even when forwarding the report

Approval Chain Logic:

When building out the approval chain logic, logic should look like this:

  1. Get policy's employeeList
  2. Get report submitter, get their policy data with employeeList[submitterEmail]
  3. The first member of the approval chain is the employee's submitsTo - like submitsToEmail = employeeList[submitterEmail]?.submitsTo ?? policyOwnerEmail
  4. Next, get the submitsTo person's policy data with submitsToEmployeeData = employeeList[submitsToEmail]
  5. From here on, we get the next approver by looking at forwardsTo, overLimitForwardsTo, and approvalLimit
    1. If submitsToEmployeeData has an approvalLimit and overLimitForwardsTo, do this:
      1. Get the report total
      2. If the report total is > approvalLimit, then the next approver in line is the email address in submitsToEmployeeData?.overLimitForwardsTo
      3. If the report is <= approvalLimit, then the next approver in line is submitsToEmployeeData?.forwardsTo
    2. If submitsToEmployeeData doesn't have either approvalLimit or doesn't have overLimitForwardsTo, the next approver in line is submitsToEmployeeData?.forwardsTo
    3. Note: If we ever run into a missing approver here (a.k.a. if submitsToEmployeeData doesn't have a forwardsTo), we're done!
  6. Now we get the forwardsTo or overLimitForwardsTo's policy data with forwardsEmployeeData = employeeList[forwardsToEmail]
  7. Repeat steps 5 & 6 until you either:
    1. End up with an email address you already added to the approval chain
    2. Run into some employee's data that doesn't have a forwardsTo

This looks something like this:

Screenshot 2024-07-01 at 3 35 41 PM

Where $policy->getForwardsTo looks like this:

Screenshot 2024-07-01 at 3 36 52 PM

Examples:

Say, for example, we have this Control employeeList policy setup (with advanced approvals enabled):

Member Email policy role submitsTo forwardsTo overLimitForwardsTo approvalLimit
boss_owner@gmail.com admin mini_owner@gmail.com
mini_owner@gmail.com admin boss_owner@gmail.com
manager@gmail.com employee mini_owner@gmail.com mini_owner@gmail.com boss_owner@gmail.com 10000
employee1@gmail.com employee manager@gmail.com
employee2@gmail.com employee manager@gmail.com

Each member's approval chain looks like this:

Policy Member Approval Chain (if report total <= approvalLimit) Approval Chain (if report total > approvalLimit)
boss_owner@gmail.com mini_owner@gmail.com same
mini_owner@gmail.com boss_owner@gmail.com same
manager@gmail.com mini_owner@gmail.com same
employee1@gmail.com manager@gmail.com, mini_owner@gmail.com manager@gmail.com, boss_owner@gmail.com
employee2@gmail.com manager@gmail.com, mini_owner@gmail.com manager@gmail.com, boss_owner@gmail.com

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2NewFeatureSomething to build that is a new item.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions