-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
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:
- Set optimistic next steps for approvals, when policy is Control and on Advanced Approval mode
- Specifically new for mid-level approvers
- Need to build basic approval chain from policy
employeeListin order to be able to figure out who should optimistically be the next approval - 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:
- “Finished! No further action required”
- “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:
- 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, andoverLimitForwardsTo. Later, we'll add in rule approvers (tag & category)
- Note: For v1 we will only consider
- 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:
- Get policy's
employeeList - Get report submitter, get their policy data with
employeeList[submitterEmail] - The first member of the approval chain is the employee's
submitsTo- likesubmitsToEmail = employeeList[submitterEmail]?.submitsTo ?? policyOwnerEmail - Next, get the submitsTo person's policy data with
submitsToEmployeeData = employeeList[submitsToEmail] - From here on, we get the next approver by looking at
forwardsTo,overLimitForwardsTo, andapprovalLimit- If
submitsToEmployeeDatahas anapprovalLimitandoverLimitForwardsTo, do this:- Get the report total
- If the report total is >
approvalLimit, then the next approver in line is the email address insubmitsToEmployeeData?.overLimitForwardsTo - If the report is <=
approvalLimit, then the next approver in line issubmitsToEmployeeData?.forwardsTo
- If
submitsToEmployeeDatadoesn't have eitherapprovalLimitor doesn't haveoverLimitForwardsTo, the next approver in line issubmitsToEmployeeData?.forwardsTo - Note: If we ever run into a missing approver here (a.k.a. if
submitsToEmployeeDatadoesn't have aforwardsTo), we're done!
- If
- Now we get the
forwardsTooroverLimitForwardsTo's policy data withforwardsEmployeeData = employeeList[forwardsToEmail] - Repeat steps 5 & 6 until you either:
- End up with an email address you already added to the approval chain
- Run into some employee's data that doesn't have a
forwardsTo
This looks something like this:
Where $policy->getForwardsTo looks like this:
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
Type
Projects
Status

