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] changed structural implementation

Eric Schubertc5313556271f
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b997b83e354..d1168ae7e5f 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -91,8 +91,9 @@ class ProjectsController < ApplicationController
hide_project_in_layout
end
- def set_hide_attachments
- @project.update_column(:hide_attachments, params["value"] != "1")
+ def deactivate_work_package_attachments
+ @project.deactivate_work_package_attachments = params[:value] != "1"
+ @project.save
end
private
diff --git a/app/models/project.rb b/app/models/project.rb
index 1f22f408ada..e3596966e96 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -89,6 +89,8 @@ class Project < ApplicationRecord
has_many :project_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'
has_many :storages, through: :project_storages
+ store_attribute :settings, :deactivate_work_package_attachments, :boolean, default: false
+
acts_as_favorable
acts_as_customizable # partially overridden via Projects::ActsAsCustomizablePatches in order to support sections and
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index feb430611f5..b60f013478b 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -82,8 +82,8 @@ class WorkPackage < ApplicationRecord
scope :visible, ->(user = User.current) { allowed_to(user, :view_work_packages) }
scope :in_status, ->(*args) do
- where(status_id: (args.first.respond_to?(:id) ? args.first.id : args.first))
- end
+ where(status_id: (args.first.respond_to?(:id) ? args.first.id : args.first))
+ end
scope :for_projects, ->(projects) {
where(project_id: projects)
@@ -291,6 +291,7 @@ class WorkPackage < ApplicationRecord
def milestone?
type&.is_milestone?
end
+
alias_method :is_milestone?, :milestone?
def done_ratio
@@ -302,7 +303,11 @@ class WorkPackage < ApplicationRecord
end
def hide_attachments?
- project&.hide_attachments || Setting.hide_attachments
+ if project&.deactivate_work_package_attachments.nil?
+ !Setting.show_work_package_attachments
+ else
+ project&.deactivate_work_package_attachments?
+ end
end
def estimated_hours=(hours)
@@ -507,11 +512,13 @@ class WorkPackage < ApplicationRecord
.where(types: { id: work_packages.map(&:type_id).uniq }))
.distinct
end
+
private_class_method :available_custom_fields_from_db
def self.available_custom_field_key(work_package)
:"#work_package_custom_fields_#{work_package.project_id}_#{work_package.type_id}"
end
+
private_class_method :available_custom_field_key
def custom_field_cache_key
@@ -560,6 +567,7 @@ class WorkPackage < ApplicationRecord
" AND #{Version.table_name}.sharing <> 'system'"
)
end
+
private_class_method :having_version_from_other_project
# Update issues so their versions are not pointing to a
@@ -579,6 +587,7 @@ class WorkPackage < ApplicationRecord
end
end
end
+
private_class_method :update_versions
# Default assignment based on category
@@ -644,6 +653,7 @@ class WorkPackage < ApplicationRecord
group by s.id, s.is_closed, j.id"
).to_a
end
+
private_class_method :count_and_group_by
def set_attachments_error_details
diff --git a/app/views/admin/settings/attachments_settings/show.html.erb b/app/views/admin/settings/attachments_settings/show.html.erb
index 1d8a2116e9e..5cecc9a5336 100644
--- a/app/views/admin/settings/attachments_settings/show.html.erb
+++ b/app/views/admin/settings/attachments_settings/show.html.erb
@@ -39,6 +39,12 @@ See COPYRIGHT and LICENSE files for more details.
method: :patch
) do %>
<section class="form--section">
+ <div class="form--field">
+ <%= setting_check_box :show_work_package_attachments, container_class: '-slim' %>
+ <div class="form--field-instructions">
+ <%= t('settings.attachments.show_work_package_attachments') %>
+ </div>
+ </div>
<div class="form--field">
<%= setting_text_field :attachment_max_size, size: 6, unit: t(:"number.human.storage_units.units.kb"), container_class: '-slim' %>
</div>
@@ -51,9 +57,6 @@ See COPYRIGHT and LICENSE files for more details.
) %>
</div>
</div>
- <div class="form--field">
- <%= setting_check_box :hide_attachments, container_class: '-slim' %>
- </div>
</section>
<%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %>
<% end %>
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 2f881d05e23..479ed4fa1e4 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -736,10 +736,10 @@ module Settings
default: "",
writable: false
},
- hide_attachments: {
- description: "Hide attachments by default.",
+ show_work_package_attachments: {
+ description: "Show work package attachments by default.",
format: :boolean,
- default: false,
+ default: true,
writable: true
},
https: {
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f61dd2ce25b..84e189c902b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3064,7 +3064,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
setting_app_subtitle: "Application subtitle"
setting_app_title: "Application title"
setting_attachment_max_size: "Attachment max. size"
- setting_hide_attachments: "Hide attachments by default"
+ setting_show_work_package_attachments: "Show attachments in the files tab by default"
setting_antivirus_scan_mode: "Scan mode"
setting_antivirus_scan_action: "Infected file action"
setting_autofetch_changesets: "Autofetch repository changes"
@@ -3173,6 +3173,9 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
<br/>
Leave empty to allow any file type to be uploaded.
Multiple values allowed (one line for each value).
+ show_work_package_attachments: >
+ Deactivating this option will hide the attachments list on the work packages files tab for new projects. The
+ files attached in the description of a work package will still be uploaded in the internal attachments storage.
antivirus:
title: "Virus scanning"
clamav_ping_failed: "Failed to connect the the ClamAV daemon. Double-check the configuration and try again."
diff --git a/config/routes.rb b/config/routes.rb
index 144c1370435..e7e1e801a62 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -220,7 +220,7 @@ Rails.application.routes.draw do
# Destroy uses a get request to prompt the user before the actual DELETE request
get :destroy_info, as: "confirm_destroy"
- post :set_hide_attachments
+ post :deactivate_work_package_attachments
end
resources :versions, only: %i[new create] do
diff --git a/db/migrate/20240424160513_add_hide_attachments_to_projects.rb b/db/migrate/20240424160513_add_hide_attachments_to_projects.rb
index 7adaf9754d0..2aee142d7c1 100644
--- a/db/migrate/20240424160513_add_hide_attachments_to_projects.rb
+++ b/db/migrate/20240424160513_add_hide_attachments_to_projects.rb
@@ -30,6 +30,6 @@
class AddHideAttachmentsToProjects < ActiveRecord::Migration[7.1]
def change
- add_column :projects, :hide_attachments, :boolean, default: false
+ add_column :projects, :settings, :jsonb, null: false, default: {}
end
end
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index 71caac573e8..b282a43722c 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -580,9 +580,7 @@ module API
super
end
- def hide_attachments?
- represented.hide_attachments?
- end
+ delegate :hide_attachments?, to: :represented
# Permissions
def current_user_watcher?
@@ -702,6 +700,7 @@ module API
json_key_representer_parts,
represented.cache_checksum,
Setting.work_package_done_ratio,
+ Setting.show_work_package_attachments,
Setting.feeds_enabled?]
end
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 b5561f99331..5db1acca02a 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,10 @@ end
end
end
row.with_column do
- render(Primer::Alpha::ToggleSwitch.new(src: set_hide_attachments_project_path(@project),
+ 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]_attachments))
+ checked: [email protected]_work_package_attachments?))
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 f94bfd9c18c..7279eba8412 100644
--- a/modules/storages/spec/features/hide_attachments_spec.rb
+++ b/modules/storages/spec/features/hide_attachments_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
view_file_links
manage_file_links)
end
- let(:project) { create(:project, hide_attachments: true) }
+ let(:project) { create(:project, deactivate_work_package_attachments: true) }
let!(:current_user) { create(:user, member_with_permissions: { project => permissions }) }
let(:work_package) { create(:work_package, project:, description: "Initial description") }
let(:attachment) { create(:attachment, container: work_package) }
@@ -55,44 +55,44 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
login_as current_user
visit project_settings_project_storages_path(project)
- click_button("Attachments")
+ click_on("Attachments")
expect(page).to have_css("toggle-switch", text: "Off")
- expect(project.reload.hide_attachments).to be_truthy
+ expect(project.reload).to be_deactivate_work_package_attachments
- find("button.ToggleSwitch-track").click
+ click_on(class: "ToggleSwitch-track")
expect(page).to have_css("toggle-switch", text: "On")
- wait_for(page).to have_css('svg[data-target="toggle-switch.loadingSpinner"][hidden="hidden"]', visible: false)
- expect(project.reload.hide_attachments).to be_falsey
+ wait_for(page).to have_css('svg[data-target="toggle-switch.loadingSpinner"][hidden="hidden"]', visible: :hidden)
+ expect(project.reload).not_to be_deactivate_work_package_attachments
- find("button.ToggleSwitch-track").click
+ click_on(class: "ToggleSwitch-track")
expect(page).to have_css("toggle-switch", text: "Off")
- wait_for(page).to have_css('svg[data-target="toggle-switch.loadingSpinner"][hidden="hidden"]', visible: false)
- expect(project.reload.hide_attachments).to be_truthy
+ 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
end
describe "OpenProject setting" do
it "changes database value" do
- checkbox_label = "Hide attachments by default"
+ checkbox_label = "Show attachments in the files tab by default"
login_as create(:admin)
visit admin_settings_attachments_path
- expect(page).to have_unchecked_field(checkbox_label)
-
- check(checkbox_label)
- click_button("Save")
-
- # Check db directly to avoid cache being used.
- expect(Setting.find_by(name: "hide_attachments").value).to be_truthy
expect(page).to have_checked_field(checkbox_label)
uncheck(checkbox_label)
- click_button("Save")
+ click_on("Save")
- expect(Setting.find_by(name: "hide_attachments").value).to be_falsey
+ # Check db directly to avoid cache being used.
+ expect(Setting.find_by(name: "show_work_package_attachments").value).to be_falsy
expect(page).to have_unchecked_field(checkbox_label)
+
+ check(checkbox_label)
+ click_on("Save")
+
+ expect(Setting.find_by(name: "show_work_package_attachments").value).to be_truthy
+ expect(page).to have_checked_field(checkbox_label)
end
end