App: [HOLD for payment 2024-05-03] [Backwards Compatibility] [$250] Remove usages of `policy.submitsTo` in favor of using a new method `PolicyUtils.getSubmitTo`

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Problem

policy.submitsTo is a field calculated on the fly by the API (and the OldDot JS code). This field is sent to Onyx by the API in the policy_ collection, which breaks these fairly newly established Onyx guidelines:

We should NEVER send slightly different versions of an update to each of the users. I think we stopped doing this, but I am calling it out anyway. So if for example we are returning a report, all users of that report should have the same data in onyx instead of sending slightly different updates to the users (eg: visibleParticipants that do not include yourself or sending the policy submitsTo to who the each submits to)

we should keep the data key and values 1:1 with the database. For instance:

  • NVP Onyx keys should always follow the same naming pattern in Onyx as in the DB (although they have the prefix nvp_, we did this for easier backwards compatibility).
  • Policy attributes should be stored at the same path as in the database

Solution

Update App code to stop accessing policy.submitsTo and instead implement PolicyUtils.getSubmitTo, which should match the PHP server implementation:

    /**
     * Gets the submit to of a given employee in this policy.
     *
     * @param string $employeeEmail The email address of the employee
     *
     * @return string The submit to email address, can be empty
     */
    public function getSubmitTo($employeeEmail): string
    {
        // For policy using the optional or basic workflow, the manager is the policy default approver.
        if (in_array($this->getApprovalWorkflow(), [self::APPROVAL_MODE_OPTIONAL, self::APPROVAL_MODE_BASIC], true)) {
            return strtolower($this->getDefaultApprover());
        }

        // Handle Advance approval mode
        $employee = $this->getEmployeeByEmail($employeeEmail);
        if ($employee === null) {
            Log::info('Employee not on the policy', [
                'policyID' => $this->getID(),
                'employeeEmail' => $employeeEmail,
            ]);

            return '';
        }

        $submitTo = $employee->getSubmitsTo();

        // On some old policies, employees don't have a submitTo, so we fallback on the default approver.
        if (!$submitTo) {
            $submitTo = $this->getDefaultApprover();
        }

        return strtolower($submitTo);
    }

About this issue

  • Original URL
  • State: open
  • Created 2 months ago
  • Comments: 32 (24 by maintainers)

Most upvoted comments

@trjExpensify @flodnv re-assigning to other C+, sorry, i thought i would be able to get this today 🙇! @ikevin127 will review it.,

Thanks for the heads up! Assigned you, Kevin! 👍

No need for Design Danny on this!