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

Move virus scanning into its own menu

Oliver Günther38853d72ac9a
diff --git a/app/controllers/admin/settings/attachments_settings_controller.rb b/app/controllers/admin/settings/attachments_settings_controller.rb
index 4d588437d30..0ea83831c5c 100644
--- a/app/controllers/admin/settings/attachments_settings_controller.rb
+++ b/app/controllers/admin/settings/attachments_settings_controller.rb
@@ -36,45 +36,6 @@ module Admin::Settings
t(:'attributes.attachments')
end
- def av_form
- selected = params.dig(:settings, :antivirus_scan_mode)&.to_sym || :disabled
-
- respond_to do |format|
- format.turbo_stream do
- render turbo_stream: turbo_stream.replace(:attachments_av_subform,
- partial: "admin/settings/attachments_settings/av_form",
- locals: { selected: })
- end
- end
- end
-
- private
-
- def check_clamav
- return if params[:settings].blank?
- return if params[:settings][:antivirus_scan_mode] == "disabled"
-
- service = ::Attachments::ClamAVService.new(params[:settings][:antivirus_scan_mode].to_sym,
- params[:settings][:antivirus_scan_target])
-
- service.ping
- rescue StandardError => e
- Rails.logger.error { "Failed to check availability of ClamAV: #{e.message}" }
- flash[:error] = t(:'settings.antivirus.clamav_ping_failed')
- redirect_to action: :show
- end
-
- def success_callback(_call)
- if Setting.antivirus_scan_mode == :disabled && Attachment.status_quarantined.any?
- flash[:info] = t('settings.antivirus.remaining_quarantined_files_html',
- link: helpers.link_to(t('antivirus_scan.quarantined_attachments.title'), admin_quarantined_attachments_path),
- file_count: t(:label_x_files, count: Attachment.status_quarantined.count))
- redirect_to action: :show
- else
- super
- end
- end
-
def settings_params
super.tap do |settings|
settings["attachment_whitelist"] = settings["attachment_whitelist"].split(/\r?\n/)
diff --git a/app/controllers/admin/settings/virus_scanning_settings_controller.rb b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
new file mode 100644
index 00000000000..c8bdebed523
--- /dev/null
+++ b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
@@ -0,0 +1,78 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Admin::Settings
+ class VirusScanningSettingsController < ::Admin::SettingsController
+ menu_item :settings_attachments
+
+ before_action :check_clamav, only: %i[update]
+
+ def default_breadcrumb
+ t(:'virus_scanning.title')
+ end
+
+ def av_form
+ selected = params.dig(:settings, :antivirus_scan_mode)&.to_sym || :disabled
+
+ respond_to do |format|
+ format.turbo_stream do
+ render turbo_stream: turbo_stream.replace(:attachments_av_subform,
+ partial: "admin/settings/virus_scanning_settings/av_form",
+ locals: { selected: })
+ end
+ end
+ end
+
+ private
+
+ def check_clamav
+ return if params[:settings].blank?
+ return if params[:settings][:antivirus_scan_mode] == "disabled"
+
+ service = ::Attachments::ClamAVService.new(params[:settings][:antivirus_scan_mode].to_sym,
+ params[:settings][:antivirus_scan_target])
+
+ service.ping
+ rescue StandardError => e
+ Rails.logger.error { "Failed to check availability of ClamAV: #{e.message}" }
+ flash[:error] = t(:'settings.antivirus.clamav_ping_failed')
+ redirect_to action: :show
+ end
+
+ def success_callback(_call)
+ if Setting.antivirus_scan_mode == :disabled && Attachment.status_quarantined.any?
+ flash[:info] = t('settings.antivirus.remaining_quarantined_files_html',
+ link: helpers.link_to(t('antivirus_scan.quarantined_attachments.title'), admin_quarantined_attachments_path),
+ file_count: t(:label_x_files, count: Attachment.status_quarantined.count))
+ redirect_to action: :show
+ else
+ super
+ end
+ end
+ end
+end
diff --git a/app/views/admin/settings/attachments_settings/show.html.erb b/app/views/admin/settings/attachments_settings/show.html.erb
index 7c65fcfa56e..d4b4570fc11 100644
--- a/app/views/admin/settings/attachments_settings/show.html.erb
+++ b/app/views/admin/settings/attachments_settings/show.html.erb
@@ -30,12 +30,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= styled_form_tag(
admin_settings_attachments_path,
- method: :patch,
- data: {
- 'controller': 'refresh-on-form-changes',
- 'refresh-on-form-changes-target': 'form',
- 'refresh-on-form-changes-turbo-stream-url-value': url_for(action: 'av_form')
- }
+ method: :patch
) do %>
<section class="form--section">
<div class="form--field">
@@ -51,31 +46,5 @@ See COPYRIGHT and LICENSE files for more details.
</div>
</div>
</section>
- <fieldset class="form--fieldset">
- <legend class="form--fieldset-legend"><%= t('settings.antivirus.title') %></legend>
- <div class="form--field">
- <%= setting_select :antivirus_scan_mode,
- [
- [t(:label_disabled), :disabled],
- ['ClamAV (Socket)', :clamav_socket],
- ['ClamAV (Host)', :clamav_host],
- ],
- container_class: '-wide',
- data: {
- action: 'refresh-on-form-changes#triggerTurboStream'
- }
- %>
- <div class="form--field-instructions">
- <p><%= t('settings.antivirus.modes.description_html',
- disabled_option: t(:label_disabled),
- socket_option: 'ClamAV (Socket)',
- host_option: 'ClamAV (Host)',
- ) %></p>
- </div>
- </div>
-
- <%= render partial: 'av_form', locals: { selected: Setting.antivirus_scan_mode } %>
- </fieldset>
-
<%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>
<% end %>
diff --git a/app/views/admin/settings/attachments_settings/_av_form.html.erb b/app/views/admin/settings/virus_scanning_settings/_av_form.html.erb
similarity index 99%
rename from app/views/admin/settings/attachments_settings/_av_form.html.erb
rename to app/views/admin/settings/virus_scanning_settings/_av_form.html.erb
index a79b945df7c..f7de9c25882 100644
--- a/app/views/admin/settings/attachments_settings/_av_form.html.erb
+++ b/app/views/admin/settings/virus_scanning_settings/_av_form.html.erb
@@ -35,6 +35,6 @@
delete_option: t('settings.antivirus.actions.delete')
) %></p>
</div>
+ </div>
<% end %>
- </div>
</turbo-frame>
diff --git a/app/views/admin/settings/virus_scanning_settings/show.html.erb b/app/views/admin/settings/virus_scanning_settings/show.html.erb
new file mode 100644
index 00000000000..f385158ccf5
--- /dev/null
+++ b/app/views/admin/settings/virus_scanning_settings/show.html.erb
@@ -0,0 +1,63 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2024 the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+<%= toolbar title: t(:'settings.antivirus.title') %>
+
+<%= styled_form_tag(
+ admin_settings_virus_scanning_path,
+ method: :patch,
+ data: {
+ 'controller': 'refresh-on-form-changes',
+ 'refresh-on-form-changes-target': 'form',
+ 'refresh-on-form-changes-turbo-stream-url-value': url_for(action: 'av_form')
+ }
+ ) do %>
+ <div class="form--field">
+ <%= setting_select :antivirus_scan_mode,
+ [
+ [t(:label_disabled), :disabled],
+ ['ClamAV (Socket)', :clamav_socket],
+ ['ClamAV (Host)', :clamav_host],
+ ],
+ container_class: '-wide',
+ data: {
+ action: 'refresh-on-form-changes#triggerTurboStream'
+ }
+ %>
+ <div class="form--field-instructions">
+ <p><%= t('settings.antivirus.modes.description_html',
+ disabled_option: t(:label_disabled),
+ socket_option: 'ClamAV (Socket)',
+ host_option: 'ClamAV (Host)',
+ ) %></p>
+ </div>
+ </div>
+
+ <%= render partial: 'av_form', locals: { selected: Setting.antivirus_scan_mode } %>
+ <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>
+<% end %>
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index f16f599d7cd..cb04a51a569 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -356,11 +356,17 @@ Redmine::MenuManager.map :admin_menu do |menu|
icon: 'attachment',
if: Proc.new { User.current.admin? }
+ menu.push :virus_scanning_settings,
+ { controller: '/admin/settings/virus_scanning_settings', action: :show },
+ caption: :'settings.antivirus.title',
+ parent: :settings_attachments,
+ if: Proc.new { User.current.admin? }
+
menu.push :attachment_quarantine,
{ controller: '/admin/attachments/quarantined_attachments', action: :index },
caption: :'antivirus_scan.quarantined_attachments.title',
parent: :settings_attachments,
- if: Proc.new { User.current.admin? && Setting.antivirus_scan_action == :quarantine }
+ if: Proc.new { User.current.admin? && Attachment.status_quarantined.exists? }
menu.push :enumerations,
{ controller: '/enumerations' },
diff --git a/config/routes.rb b/config/routes.rb
index 5fbea4a1025..09126987668 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -424,7 +424,12 @@ Rails.application.routes.draw do
resource :authentication, controller: '/admin/settings/authentication_settings', only: %i[show update]
resource :attachments, controller: '/admin/settings/attachments_settings', only: %i[show update]
- get 'attachments/av_form', controller: '/admin/settings/attachments_settings', action: 'av_form'
+ resource :virus_scanning, controller: '/admin/settings/virus_scanning_settings', only: %i[show update] do
+ collection do
+ get :av_form
+ end
+ end
+
resource :incoming_mails, controller: '/admin/settings/incoming_mails_settings', only: %i[show update]
resource :aggregation, controller: '/admin/settings/aggregation_settings', only: %i[show update]
resource :mail_notifications, controller: '/admin/settings/mail_notifications_settings', only: %i[show update]