Skip to content

[Feature:Forum] PDF Attachment Support#12213

Closed
samarthnaikk wants to merge 6 commits into
Submitty:mainfrom
samarthnaikk:f12202
Closed

[Feature:Forum] PDF Attachment Support#12213
samarthnaikk wants to merge 6 commits into
Submitty:mainfrom
samarthnaikk:f12202

Conversation

@samarthnaikk

Copy link
Copy Markdown
Contributor

Why is this Change Important & Necessary?

The forum currently only supports image attachments, but instructors often need to upload PDF documents such as rubrics or worksheets. Allowing PDFs improves usability while keeping the same file size and security restrictions already in place for images.

What is the New Behavior?

Users can attach both images and PDFs to forum posts. The UI labels now refer to “files” instead of only images, and the file input accepts PDFs. All existing limits (file size, max number of attachments, security checks) remain unchanged.

What steps should a reviewer take to reproduce or test the new feature?

  1. Open the forum and start a new post or edit an existing one.
  2. Attempt to upload image files (should work as before).
  3. Attempt to upload PDF files (should now be accepted).
  4. Try uploading invalid file types (should be rejected).
  5. Confirm that file size and file count limits still apply.
  6. View a post to ensure attached PDFs appear correctly in the UI.

Automated Testing & Documentation

Unit tests have been added to cover PDF detection, MIME validation, and compatibility with existing image validation. Documentation updates may be needed to mention PDF support in forum attachments.

Other information

This is not a breaking change and does not require database migrations. Existing security checks (file validation, MIME type checks, size limits) remain fully enforced.

This PR should solve #12202

@codecov

codecov Bot commented Nov 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.73%. Comparing base (58b54df) to head (e0b16a2).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12213      +/-   ##
============================================
+ Coverage     21.71%   21.73%   +0.02%     
- Complexity     9612     9620       +8     
============================================
  Files           268      268              
  Lines         36073    36083      +10     
  Branches        475      475              
============================================
+ Hits           7832     7844      +12     
+ Misses        27770    27768       -2     
  Partials        471      471              
Flag Coverage Δ
autograder 21.39% <ø> (ø)
js 2.07% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.74% <68.00%> (+0.03%) ⬆️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 90.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@samarthnaikk samarthnaikk changed the title [Feature:Forum] Add Support for PDF Attachments to Forum Posts [Feature:Forum] PDF Attachment Support Nov 15, 2025

@RyanStyron RyanStyron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The functionality is aligned with the description. I would suggest migrating from the use of popups to the use of new tabs, to be consistent with #12135, which is handled by loadInlineImages in forum.js. Additionally, the very same loadInlineImages function is used to render both images and PDFs. Perhaps there should be a separate method (or the same method with altered logic), to improve in-line rendering of PDFs (<iframe> tag?).

@github-project-automation github-project-automation Bot moved this from Seeking Reviewer to Work in Progress in Submitty Development Nov 18, 2025
@RyanStyron

Copy link
Copy Markdown
Contributor

The functionality is aligned with the description. I would suggest migrating from the use of popups to the use of new tabs, to be consistent with #12135, which is handled by loadInlineImages in forum.js. Additionally, the very same loadInlineImages function is used to render both images and PDFs. Perhaps there should be a separate method (or the same method with altered logic), to improve in-line rendering of PDFs (<iframe> tag?).

Also, I would recommend adding a test that creates a $_FILES with one valid image and one invalid file.

@samarthnaikk

Copy link
Copy Markdown
Contributor Author

@RyanStyron I’ve made the changes. Please let me know if you'd like me to adjust or improve anything further.

@RyanStyron RyanStyron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The feature works well. Thank you. The test, however, is slightly misrepresentative of what it claims. I would suggest replacing time.sleep with a short WebDriverWait to wait for an upload preview or for errors. Also, I would recommend strengthening the assertions. The issue with the current test is that it does not explicitly confirm that only the valid file was uploaded or that the invalid file was rejected. It assumes filtering happened but does not assert it. Similarly, it does not check if the image was actually attached to the created post. Please resolve the lint failures as well.

@samarthnaikk samarthnaikk closed this by deleting the head repository Dec 13, 2025
bmcutler added a commit that referenced this pull request Apr 10, 2026
## What is the current behavior?
Discussion forum attachments currently allow valid image uploads, but
reject PDF attachments.

Closes #12202

## What is the new behavior?
This PR allows valid PDF attachments in discussion forum posts in
addition to valid images.

## What changed?
- allow forum attachments that are valid images or PDFs
- validation is content-based and not extension-only
- preserved existing image validation behavior
- kept existing forum attachment limits unchanged
- updated the forum upload UI to accept PDFs (`accept="image/*,.pdf"`)
- added a separate PDF rendering path for forum attachments
- kept existing inline image rendering behavior unchanged
- updated edit/history views to correctly display PDF attachments
- aligned attachment opening behavior with current forum behavior by
using new-tab opening without popup-style window features
- added unit tests for:
  - valid PDF accepted
  - invalid file rejected
  - existing image behavior still works
- added focused e2e coverage for:
  - valid PDF upload
  - invalid file rejection
  - attachment visible on created post
  - PDF preview rendering

## Notes
This implementation was informed by feedback from #12213:
- attachment opening behavior was simplified to stay consistent with the
current forum attachment UX
- PDF handling was separated from image handling instead of forcing both
through the same rendering path
- existing attachment data flow was preserved to avoid breaking forum
edit/history views
- tests were strengthened to verify actual outcomes rather than
timing-based assumptions

## Manual Testing
- created a thread with a PDF attachment and verified the thread was
created successfully
- verified the PDF appears in the created post attachment section
- verified PDF preview renders correctly
- verified PDF open behavior uses a new tab
- verified PDF appears correctly in the edit attachment table
- verified remove/delete still works for PDF attachments
- verified existing image upload, preview, and open behavior still works

## Screenshots

### Upload UI (PDF selectable)
![Upload
UI](https://github.com/user-attachments/assets/998badcc-1771-4db0-8672-114ab63303dc)

### PDF Preview on created post
![PDF
Preview](https://github.com/user-attachments/assets/865d24fd-2a13-48e0-8563-38beb2c0ea61)

### Edit view showing PDF tile
![Edit
View](https://github.com/user-attachments/assets/0d7f0070-5379-429b-b252-0cf6fc1fe8c9)

---------

Co-authored-by: dagemcn <[email protected]>
Co-authored-by: Barb Cutler <[email protected]>
GarvitKhandelwal31 pushed a commit to GarvitKhandelwal31/Submitty that referenced this pull request Apr 13, 2026
## What is the current behavior?
Discussion forum attachments currently allow valid image uploads, but
reject PDF attachments.

Closes Submitty#12202

## What is the new behavior?
This PR allows valid PDF attachments in discussion forum posts in
addition to valid images.

## What changed?
- allow forum attachments that are valid images or PDFs
- validation is content-based and not extension-only
- preserved existing image validation behavior
- kept existing forum attachment limits unchanged
- updated the forum upload UI to accept PDFs (`accept="image/*,.pdf"`)
- added a separate PDF rendering path for forum attachments
- kept existing inline image rendering behavior unchanged
- updated edit/history views to correctly display PDF attachments
- aligned attachment opening behavior with current forum behavior by
using new-tab opening without popup-style window features
- added unit tests for:
  - valid PDF accepted
  - invalid file rejected
  - existing image behavior still works
- added focused e2e coverage for:
  - valid PDF upload
  - invalid file rejection
  - attachment visible on created post
  - PDF preview rendering

## Notes
This implementation was informed by feedback from Submitty#12213:
- attachment opening behavior was simplified to stay consistent with the
current forum attachment UX
- PDF handling was separated from image handling instead of forcing both
through the same rendering path
- existing attachment data flow was preserved to avoid breaking forum
edit/history views
- tests were strengthened to verify actual outcomes rather than
timing-based assumptions

## Manual Testing
- created a thread with a PDF attachment and verified the thread was
created successfully
- verified the PDF appears in the created post attachment section
- verified PDF preview renders correctly
- verified PDF open behavior uses a new tab
- verified PDF appears correctly in the edit attachment table
- verified remove/delete still works for PDF attachments
- verified existing image upload, preview, and open behavior still works

## Screenshots

### Upload UI (PDF selectable)
![Upload
UI](https://github.com/user-attachments/assets/998badcc-1771-4db0-8672-114ab63303dc)

### PDF Preview on created post
![PDF
Preview](https://github.com/user-attachments/assets/865d24fd-2a13-48e0-8563-38beb2c0ea61)

### Edit view showing PDF tile
![Edit
View](https://github.com/user-attachments/assets/0d7f0070-5379-429b-b252-0cf6fc1fe8c9)

---------

Co-authored-by: dagemcn <[email protected]>
Co-authored-by: Barb Cutler <[email protected]>
@GarvitKhandelwal31 GarvitKhandelwal31 moved this from Work in Progress to Done in Submitty Development Jun 9, 2026
@GarvitKhandelwal31 GarvitKhandelwal31 moved this from Done to Work in Progress in Submitty Development Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Work in Progress

Development

Successfully merging this pull request may close these issues.

3 participants