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

General: Fix an issue in Chrome when uploading files #9766

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

eceeeren
Copy link
Contributor

@eceeeren eceeeren commented Nov 12, 2024

Note: Please test it first on Chromium Browsers (Google Chrome, Arc etc.)!

Checklist

General

Server

Motivation and Context

Right now when users want to add an attachment on Chromium browsers (such as Chrome and Arc), they get a 404 Not Found error and their attachment is not uploaded. This is an issue occurring in Chromium's version 130, 132 and it is fix in version 132. However since it may take time until the release, a temporary solution was needed to tackle this problem.

See: https://issues.chromium.org/issues/374550348

Description

In one of the Chromium forum comments, it is stated that a work around can be used by bypassing the service workers.

See: https://issues.chromium.org/issues/374550348#comment20

This is first tried on Chrome by bypassing service workers manually and shown that it is working.

image

After that Angular's "ngsw-bypass" header flag is found to fix the problem.

See: https://angular.dev/ecosystem/service-workers/devops#bypassing-the-service-worker

Fixes #9732 and #9168 and #9646

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Log in to Artemis
  2. Navigate to Course Administration
  3. Navigate to Lecture -> Attachments -> Add an attachment
  4. Observe that it is added correctly
  5. Edit Attachment and add another
  6. Observe that it is added correctly
  7. Navigate to Lecture -> Attachment Units -> Add an Attachment Unit
  8. Observe that it is added correctly
  9. Edit Attachment Unit and add another
  10. Observe that it is added correctly
  11. Create a Lecture > click Automatic Unit Processing
  12. Observe that the file is added without an error

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • Bug Fixes
    • Implemented a temporary workaround for a file upload issue in Chromium by adding a custom header to HTTP POST and PUT requests in the attachment services.

These changes enhance the file upload experience while maintaining existing functionality.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 12, 2024
@eceeeren eceeeren temporarily deployed to artemis-test4.artemis.cit.tum.de November 12, 2024 22:21 — with GitHub Actions Inactive
@eceeeren eceeeren linked an issue Nov 12, 2024 that may be closed by this pull request
@eceeeren eceeeren marked this pull request as ready for review November 12, 2024 22:30
@eceeeren eceeeren requested a review from a team as a code owner November 12, 2024 22:30
Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes involve modifications to the AttachmentService and AttachmentUnitService classes to address a file upload issue in Chromium. Specifically, both services' create and update methods now include a custom HTTP header ngsw-bypass set to true, which allows the requests to bypass the Angular Service Worker during file uploads. The core logic of the methods remains unchanged, focusing solely on resolving the upload problem without affecting other functionalities.

Changes

File Change Summary
src/main/webapp/app/lecture/attachment.service.ts Added ngsw-bypass header set to true in create and update methods for file upload workaround.
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts Added ngsw-bypass header set to true in create and update methods for file upload workaround.

Assessment against linked issues

Objective Addressed Explanation
Can't upload files for Lecture and Exercise (#9732)

Possibly related PRs

Suggested labels

bugfix, server, tests

Suggested reviewers

  • JohannesStoehr
  • florian-glombik
  • N0W0RK
  • magaupp

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ee583f9 and ad63c98.

📒 Files selected for processing (2)
  • src/main/webapp/app/lecture/attachment.service.ts (2 hunks)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/webapp/app/lecture/attachment.service.ts
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts (2)

29-31: Enhance the temporary fix documentation.

While the comment clearly indicates this is temporary and links to the Chromium issue, it would be helpful to add information about when this workaround can be removed (e.g., which Chromium version will contain the fix).

 /** Ngsw-worker is bypassed temporarily to fix Chromium file upload issue
  * See: https://issues.chromium.org/issues/374550348
+ * TODO: Remove this workaround once Chromium versions > 132 are widely adopted
  **/

33-36: Consider tracking this temporary fix.

Since this is a temporary workaround, we should track it for future removal.

Would you like me to create a GitHub issue to track the removal of this workaround once Chromium fixes the underlying issue? The issue would include:

  • Link to this PR and the Chromium issue
  • Criteria for removal (Chromium version requirements)
  • List of affected files that need updating
src/main/webapp/app/lecture/attachment.service.ts (1)

38-40: Enhance the documentation for future maintainability.

While the comment explains the temporary nature of the bypass, consider adding:

-        /** Ngsw-worker is bypassed temporarily to fix Chromium file upload issue
-         * See: https://issues.chromium.org/issues/374550348
-         **/
+        /**
+         * Temporarily bypass ngsw-worker to fix file upload 404 errors in Chrome 130-132
+         * @see https://issues.chromium.org/issues/374550348 (Chromium issue)
+         * @see https://github.com/your-repo/issues/9732 (Tracking issue)
+         * @todo Remove this workaround once the Chromium fix is released and widely adopted
+         */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7876792 and ee583f9.

📒 Files selected for processing (2)
  • src/main/webapp/app/lecture/attachment.service.ts (1 hunks)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/lecture/attachment.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (3)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts (1)

33-36: Verify consistent implementation across services.

The implementation looks correct for addressing the Chromium file upload issue. However, since this is a temporary fix, we should ensure:

  1. The same header is consistently implemented in AttachmentService.
  2. The bypass doesn't affect other browsers negatively.

Let's verify the consistency of implementation:

src/main/webapp/app/lecture/attachment.service.ts (2)

38-42: Consider architectural implications of service worker bypass.

While this fix addresses the immediate issue, consider the following:

  1. Impact on offline functionality: Bypassing the service worker means these requests won't be cached for offline use.
  2. Monitoring: Consider adding telemetry to track if/when the Chromium issue is resolved.
  3. Related services: Other file upload services (e.g., AttachmentUnitService) might need similar changes.

Let's check for similar file upload implementations:

#!/bin/bash
# Look for similar file upload services that might need the same fix
ast-grep --pattern 'class $_Service {
  $$$
  create($_: $_) {
    $$$
    formData.append("file", $_)
    $$$
  }
}'

42-42: Implementation looks good, verify scope of bypass.

The service worker bypass is correctly implemented using Angular's supported header mechanism. The change is focused and doesn't affect other functionality.

Let's verify that the bypass is only applied to file uploads and not other requests:

✅ Verification successful

Service worker bypass correctly scoped.
The ngsw-bypass header is only applied to relevant file upload services.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of ngsw-bypass to ensure the bypass is scoped appropriately
rg -g '*.ts' "'ngsw-bypass'"

# Check for similar file upload endpoints that might need the same fix
ast-grep --pattern 'formData.append("file", $_)'

Length of output: 494


Script:

#!/bin/bash
# Search for other instances of ngsw-bypass in TypeScript files only
rg -t ts 'ngsw-bypass'

# Check for similar file upload endpoints that might need the same fix in TypeScript files
ast-grep --pattern 'formData.append("file", $_)' --lang typescript

Length of output: 426

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 12, 2024
@eceeeren eceeeren linked an issue Nov 12, 2024 that may be closed by this pull request
Copy link

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test4.artemis.cit.tum.de" is already in use by PR #9768.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Nov 13, 2024
Copy link

@AjayvirS AjayvirS left a comment

Choose a reason for hiding this comment

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

The following was succesfully tested on TS1:

  • Attachment added correctly:
    image

  • Attachment edited correctly:
    image

  • Attachment unit added correctly:
    image

  • Attachment unit edited correctly:
    image

  • Attachment with AUP enabled added correctly:
    image

@github-actions github-actions bot removed the deployment-error Added by deployment workflows if an error occured label Nov 13, 2024
@vinceclifford vinceclifford temporarily deployed to artemis-test5.artemis.cit.tum.de November 13, 2024 18:48 — with GitHub Actions Inactive
Copy link

@vinceclifford vinceclifford left a comment

Choose a reason for hiding this comment

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

Works as expected, tested on TS5.

Copy link

@sachmii sachmii left a comment

Choose a reason for hiding this comment

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

Tested on TS5. Almost everything worked. I just noticed two bugs but I am not sure if they are related to this PR though:

  1. When clicking twice on the upload button for the unit while it's loading, it is added twice. Is this intended?
Bildschirmfoto 2024-11-13 um 23 08 25
  1. The tooltip says you can add png files as file. But when trying to add one, I receive an error.
Bildschirmfoto 2024-11-13 um 23 10 47 Bildschirmfoto 2024-11-13 um 23 10 53

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

Tested on TS5. Every features mentioned work as expected

@eceeeren
Copy link
Contributor Author

eceeeren commented Nov 13, 2024

Tested on TS5. Almost everything worked. I just noticed two bugs but I am not sure if they are related to this PR though:

  1. When clicking twice on the upload button for the unit while it's loading, it is added twice. Is this intended?
Bildschirmfoto 2024-11-13 um 23 08 25 2. The tooltip says you can add png files as file. But when trying to add one, I receive an error.

Bildschirmfoto 2024-11-13 um 23 10 47 Bildschirmfoto 2024-11-13 um 23 10 53

Hello, these are not related to this PR but I think both of them are not intended :) You can open an issue with them

Copy link

@sachmii sachmii left a comment

Choose a reason for hiding this comment

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

re-approve 👍

@krusche krusche added this to the 7.7.1 milestone Nov 14, 2024
@krusche krusche changed the title General: Temporarily bypass ngsw-worker when uploading a file General: Fix an issue in Chrome when uploading files Nov 14, 2024
@krusche krusche merged commit d266ee6 into develop Nov 14, 2024
89 of 95 checks passed
@krusche krusche deleted the bugfix/general/temp-ngsw-worker-bypass branch November 14, 2024 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready to merge
Projects
Status: Merged
7 participants