2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/system/edit_category_images_spec.rb
Régis Hanol 6212b0b736
FEATURE: Support non-image file uploads in site settings (#37005)
This change extends the upload type site setting to support non-image
files by adding two new optional attributes:

- `authorized_extensions`: pipe-separated list of allowed extensions
(e.g., "txt|json"). When not specified, only images are allowed.
- `max_file_size_kb`: maximum file size in KB. When not specified, uses
max_image_size_kb or max_attachment_size_kb based on file type.

The upload component has been rewritten as a Glimmer component with:
- Separate UI for image files (preview with lightbox) and non-image
files (file info with download link)
- Display of upload restrictions when configured
- Drag and drop support
- Progress bar during upload

Example usage in site_settings.yml:

```yaml
llms_txt:
  default: ""
  type: upload
  authorized_extensions: "txt|md"
  max_file_size_kb: 512
```

Ref - t/162690
Related #36939

**Empty site setting**
<img width="1762" height="1229" alt="2026-01-08 @ 09 32 13"
src="https://github.com/user-attachments/assets/8f1bad3a-7070-4313-b82f-66335e9dbaff"
/>

**Site setting with a file uploaded**
<img width="1762" height="1229" alt="2026-01-08 @ 09 32 26"
src="https://github.com/user-attachments/assets/f20cc78b-8e81-451b-b334-8f3dada213b1"
/>

---------

Co-authored-by: chapoi <101828855+chapoi@users.noreply.github.com>
2026-01-19 22:37:38 +01:00

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
describe "Edit Category Images", type: :system do
fab!(:admin)
fab!(:category)
let(:category_page) { PageObjects::Pages::Category.new }
context "when trying to upload an image" do
before { sign_in(admin) }
context "when authorized_extensions blank and authorized_extensions_for_staff have restrictions" do
before do
SiteSetting.authorized_extensions = ""
SiteSetting.authorized_extensions_for_staff = "jpg|jpeg|png"
SiteSetting.enable_s3_uploads = false
end
it "displays and updates new counter" do
category_page.visit_images(category)
find("#category-logo-uploader .file-uploader__controls").click
attach_file(
"category-logo-uploader__input",
"#{Rails.root}/spec/fixtures/images/logo.png",
make_visible: true,
)
expect(page).to have_content("uploaded successfully").or have_css(
".has-image .file-uploader__preview.input-xxlarge",
)
upload = Upload.last
expect(upload.user_id).to eq(admin.id)
expect(upload.original_filename).to eq("logo.png")
end
end
end
end