Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#53672] Fix toggle state for new projects.

Pavel Balashou8ec985ea8a21
diff --git a/modules/storages/app/views/storages/project_settings/index.html.erb b/modules/storages/app/views/storages/project_settings/index.html.erb
index 5db1acca02a..81c39f7d5e0 100644
--- a/modules/storages/app/views/storages/project_settings/index.html.erb
+++ b/modules/storages/app/views/storages/project_settings/index.html.erb
@@ -65,10 +65,15 @@ end
end
end
row.with_column do
+ checked = if @project.deactivate_work_package_attachments.nil?
+ Setting.show_work_package_attachments
+ else
+ [email protected]_work_package_attachments
+ end
render(Primer::Alpha::ToggleSwitch.new(src: deactivate_work_package_attachments_project_path(@project),
csrf_token: form_authenticity_token,
status_label_position: :start,
- checked: [email protected]_work_package_attachments?))
+ checked:))
end
end
l.with_row do
diff --git a/modules/storages/spec/features/hide_attachments_spec.rb b/modules/storages/spec/features/hide_attachments_spec.rb
index 7279eba8412..88019f9cd88 100644
--- a/modules/storages/spec/features/hide_attachments_spec.rb
+++ b/modules/storages/spec/features/hide_attachments_spec.rb
@@ -70,6 +70,36 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
wait_for(page).to have_css('svg[data-target="toggle-switch.loadingSpinner"][hidden="hidden"]', visible: :hidden)
expect(project.reload).to be_deactivate_work_package_attachments
end
+
+ context "if Setting.show_work_package_attachments is false", with_settings: { show_work_package_attachments: false } do
+ let(:project) { create(:project) }
+
+ it 'renders the toggle as off for project with not set deactivate_work_package_attachments' do
+ expect(project.deactivate_work_package_attachments).to be_nil
+
+ login_as current_user
+
+ visit project_settings_project_storages_path(project)
+ click_on("Attachments")
+
+ expect(page).to have_css("toggle-switch", text: "Off")
+ end
+ end
+
+ context "if Setting.show_work_package_attachments is true", with_settings: { show_work_package_attachments: true } do
+ let(:project) { create(:project) }
+
+ it 'renders the toggle as on for project with not set deactivate_work_package_attachments' do
+ expect(project.deactivate_work_package_attachments).to be_nil
+
+ login_as current_user
+
+ visit project_settings_project_storages_path(project)
+ click_on("Attachments")
+
+ expect(page).to have_css("toggle-switch", text: "On")
+ end
+ end
end
describe "OpenProject setting" do