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

[HOLD for payment 2023-04-04] Attachments (w/o preview: mp4, docx etc) use Prod domain in case of download #16327

Closed
6 tasks done
kbecciv opened this issue Mar 20, 2023 · 17 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Reviewing Has a PR in review

Comments

@kbecciv
Copy link

kbecciv commented Mar 20, 2023

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


Issue found when executing PR #15178

Action Performed:

  1. Prod side: upload attachment without preview docx. mp4 etc to the chat
  2. On staging click on the download button
  3. check from which domain the file is download

Expected Result:

All attachment URLs to be resolved relative to current environment

Actual Result:

If file without preview like docx or mp4 sent from the Prod and it will be downloaded from the Staging via www.expensify.com
domain instead of staging.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.2.87.0

Reproducible in staging?: Yes

Reproducible in production?: yes

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

Bug5985447_Screen_Recording_2023-03-20_at_19.21.21.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal Team

Slack conversation:

View all open jobs on GitHub

@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Mar 20, 2023
@melvin-bot melvin-bot bot locked and limited conversation to collaborators Mar 20, 2023
@MelvinBot
Copy link

Triggered auto assignment to @maddylewis (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@MelvinBot
Copy link

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@mountiny
Copy link
Contributor

@kidroca Can you have a look at this one? This came from testing your PR, thanks!

@mountiny mountiny self-assigned this Mar 21, 2023
@Expensify Expensify unlocked this conversation Mar 21, 2023
@kidroca
Copy link
Contributor

kidroca commented Mar 21, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Downloading attachments with no preview is not respecting the API in use - being on staging would load an attachment from the prod URL (when the attachment was originally uploaded on prod)

What is the root cause of that problem?

When we upload an attachment the backend saves the address including the host where the attachment was originally uploaded from (uploading an attachment from prod, saves the prod address to the attachment)

What changes do you think we should make in order to solve the problem?

  1. (backend) Don't save the host which uploaded the attachment, only the path for the attachment relative to API root
    • www.expensify.com/chat-attachments/{path}
    • ✔️ /chat-attachments/{path}
  2. (backend) Migrate existing attachment URLs - remove the host portion from them
  3. (app) App logic can prefix attachments with the current API

What alternative solutions did you explore? (Optional)

Because of Old Dot, a migration would probably not be possible ATM (migration would break Old Dot)

We have reusable logic that remmaps hosts to the current environment

/**
* When possible this function resolve URLs relative to API ROOT
* - Absolute URLs like `/{path}`, become: `https://{API_ROOT}/{path}`
* - Similarly for prod or staging URLs we replace the `https://www.expensify`
* or `https://staging.expensify` part, with `https://{API_ROOT}`
* - Unmatched URLs (non expensify) are returned with no modifications
*
* @param {String} url
* @returns {String}
*/
export default function tryResolveUrlFromApiRoot(url) {
const apiRoot = ApiUtils.getApiRoot({shouldUseSecure: false});
return url.replace(ORIGIN_PATTERN, apiRoot);
}

We can use it in order to substitute the API portion of the address with the API we're currently using, by updating the code here

const attrHref = htmlAttribs.href || '';

With something like

const attrHref = ApiUtils.tryResolveUrlFromApiRoot(htmlAttribs.href);

The ideal solution would be if we don't have to do anything with the URL at all
If the API and the website were hosted from the same origin a path like /chat-attachments/{path} would be resolved from {origin}/chat-attachments/{path}

The next best thing is, manually prefixing with the current api
{API_ROOT}/chat-attachments/{path}

And 3rd, the only thing possible ATM is, replacing the origin dynamically
{PROD_OR_STAGING/chat-attachments/{path} -> {API_ROOT}/chat-attachments/{path}

@mountiny
Copy link
Contributor

Lets fix this @kidroca feel free to create a PR

@kidroca
Copy link
Contributor

kidroca commented Mar 21, 2023

BTW the issue is not tied to Desktop - it affects all platforms, though I don't think QA would be able to detect this on mobile

@mountiny mountiny changed the title Desktop - Attachments (w/o preview: mp4, docx etc) use Prod domain in case of download Attachments (w/o preview: mp4, docx etc) use Prod domain in case of download Mar 21, 2023
@mountiny
Copy link
Contributor

Makes sense, updated the title and issue body

@melvin-bot melvin-bot bot added the Overdue label Mar 23, 2023
@mountiny
Copy link
Contributor

@kidroca Feel free to make a PR for this!

@melvin-bot melvin-bot bot removed the Overdue label Mar 24, 2023
kidroca added a commit to kidroca/Expensify.cash that referenced this issue Mar 24, 2023
Attachments should be downloaded from a path relative to the current API root
See: Expensify#16327 (comment)
@melvin-bot melvin-bot bot added the Reviewing Has a PR in review label Mar 24, 2023
@kidroca
Copy link
Contributor

kidroca commented Mar 24, 2023

Created a PR, ready for review, I'll be able to add test steps and screens on Monday

@kidroca
Copy link
Contributor

kidroca commented Mar 27, 2023

PR updated and ready for review

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Daily KSv2 labels Mar 29, 2023
@kidroca
Copy link
Contributor

kidroca commented Apr 4, 2023

✅ PR was merged last week

@parasharrajat
Copy link
Member

@maddylewis Please move this back to Weekly and assign me as C+ as I reviewed the PR. Also, the header did not update to reflect payments, etc.

Thanks.

@mountiny mountiny added Daily KSv2 and removed Monthly KSv2 labels Apr 4, 2023
@mountiny mountiny changed the title Attachments (w/o preview: mp4, docx etc) use Prod domain in case of download [HOLD for payment 2023-04-04] Attachments (w/o preview: mp4, docx etc) use Prod domain in case of download Apr 4, 2023
@mountiny
Copy link
Contributor

mountiny commented Apr 4, 2023

@maddylewis could you please pay @parasharrajat $1000 for his work on this issue, thank you very much!

@maddylewis
Copy link
Contributor

on it!

@maddylewis
Copy link
Contributor

paid!

@parasharrajat
Copy link
Member

Question: Is this Internal or external @mountiny? Or this was handled as regression.

If this is external, is it valid for a bonus?

@mountiny
Copy link
Contributor

mountiny commented Apr 6, 2023

I would say this was handled as a regression/ oversight since we implemented these changes before and this hsould have been done in the original PR

Are we good to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

6 participants