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 all 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
13 changes: 12 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ 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
return if !attach_csv

extensions = SiteSetting.authorized_extensions.split("|")
if (extensions & %w[csv *]).empty?
I18n.t(
"discourse_automation.scriptables.recurring_data_explorer_result_pm.no_csv_allowed",
)
end
end

version 1
triggerables [:recurring]
Expand Down
23 changes: 23 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,27 @@
)
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

SiteSetting.authorized_extensions = "*"

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