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

UX: clarify the need for authorized extension #346

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ en:
recurring_data_explorer_result_pm:
title: Schedule a PM with Data Explorer results
description: Get scheduled reports sent to your messages
no_csv_allowed: "When using `attach_csv` field, `csv` must be added to the list of authorized extensions in the site settings."
recurring_data_explorer_result_topic:
title: Schedule a post in a topic with Data Explorer results
description: Get scheduled reports posted to a specific topic
Expand Down
10 changes: 9 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ module ::DiscourseDataExplorer
field :query_id, component: :choices, required: true, extra: { content: queries }
field :query_params, component: :"key-value", accepts_placeholders: true
field :skip_empty, component: :boolean
field :attach_csv, component: :boolean
field :attach_csv,
component: :boolean,
validator: ->(attach_csv) do
if attach_csv && !SiteSetting.authorized_extensions.split("|").include?("csv")
Copy link
Member

@ZogStriP ZogStriP Dec 9, 2024

Choose a reason for hiding this comment

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

I think we also need to handle the * which allows for "all" extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh didn't know we do this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ZogStriP ok I added the * case thanks

I18n.t(
"discourse_automation.scriptables.recurring_data_explorer_result_pm.no_csv_allowed",
)
end
end

version 1
triggerables [:recurring]
Expand Down
17 changes: 17 additions & 0 deletions spec/automation/recurring_data_explorer_result_pm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,21 @@
)
end
end

context "when using attach_csv" do
it "requires csv to be in authorized extensions" do
SiteSetting.authorized_extensions = "pdf|txt"

expect { automation.upsert_field!("attach_csv", "boolean", { value: true }) }.to raise_error(
ActiveRecord::RecordInvalid,
/#{I18n.t("discourse_automation.scriptables.recurring_data_explorer_result_pm.no_csv_allowed")}/,
)

SiteSetting.authorized_extensions = "pdf|txt|csv"

expect {
automation.upsert_field!("attach_csv", "boolean", { value: true })
}.to_not raise_error
end
end
end
Loading