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

Allow removal of antivirus settings

Oliver Günther0a92e7d11001
diff --git a/app/components/admin/attachments_settings_header_component.html.erb b/app/components/admin/attachments_settings_header_component.html.erb
index 65260b6688a..1a051044604 100644
--- a/app/components/admin/attachments_settings_header_component.html.erb
+++ b/app/components/admin/attachments_settings_header_component.html.erb
@@ -40,11 +40,15 @@ See COPYRIGHT and LICENSE files for more details.
tab_nav.with_tab(selected: @selected == 1, href: admin_settings_attachments_path) do |tab|
tab.with_text { t("settings.general") }
end
- tab_nav.with_tab(selected: @selected == 2, href: admin_settings_virus_scanning_path) do |tab|
- tab.with_icon(icon: :"op-enterprise-addons") unless EnterpriseToken.allows_to?("virus_scanning")
- tab.with_text { t(:"settings.antivirus.title") }
+ if Setting.antivirus_scan_available? &&
+ tab_nav.with_tab(selected: @selected == 2, href: admin_settings_virus_scanning_path) do |tab|
+ tab.with_icon(icon: :"op-enterprise-addons") unless EnterpriseToken.allows_to?("virus_scanning")
+ tab.with_text { t(:"settings.antivirus.title") }
+ end
end
- if User.current.admin? && (EnterpriseToken.allows_to?(:virus_scanning) || Attachment.status_quarantined.any?)
+ if Setting.antivirus_scan_available? &&
+ User.current.admin? &&
+ (EnterpriseToken.allows_to?(:virus_scanning) || Attachment.status_quarantined.any?)
tab_nav.with_tab(selected: @selected == 3, href: admin_quarantined_attachments_path) do |tab|
tab.with_text { t(:"antivirus_scan.quarantined_attachments.title") }
end
diff --git a/app/controllers/admin/attachments/quarantined_attachments_controller.rb b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
index bc6db0ec88a..c2bb91101a7 100644
--- a/app/controllers/admin/attachments/quarantined_attachments_controller.rb
+++ b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
@@ -31,6 +31,8 @@ module Admin
class QuarantinedAttachmentsController < ApplicationController
layout "admin"
before_action :require_admin
+
+ before_action :check_available
before_action :find_quarantined_attachments
before_action :find_attachment, only: %i[destroy]
@@ -53,6 +55,12 @@ module Admin
private
+ def check_available
+ return if Setting.antivirus_scan_available?
+
+ render_404
+ end
+
def create_journal(container, user, notes)
::Journals::CreateService
.new(container, user)
diff --git a/app/controllers/admin/settings/virus_scanning_settings_controller.rb b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
index 57eb4fc24d8..d0137a768a5 100644
--- a/app/controllers/admin/settings/virus_scanning_settings_controller.rb
+++ b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
@@ -32,6 +32,7 @@ module Admin::Settings
class VirusScanningSettingsController < ::Admin::SettingsController
menu_item :attachments
+ before_action :check_available
before_action :require_ee, except: :show # rubocop:disable Rails/LexicallyScopedActionFilter
before_action :check_clamav, only: %i[update], if: -> { scan_enabled? }
@@ -55,6 +56,12 @@ module Admin::Settings
redirect_to action: :show
end
+ def check_available
+ return if Setting.antivirus_scan_available?
+
+ render_404
+ end
+
def mark_unscanned_attachments
@unscanned_attachments = Attachment.status_uploaded
end
diff --git a/app/models/setting/virus_scanning.rb b/app/models/setting/virus_scanning.rb
index c1035b174c1..04fefaa3741 100644
--- a/app/models/setting/virus_scanning.rb
+++ b/app/models/setting/virus_scanning.rb
@@ -29,7 +29,9 @@
class Setting
module VirusScanning
def self.enabled?
- Setting.antivirus_scan_mode != :disabled && EnterpriseToken.allows_to?(:virus_scanning)
+ Setting.antivirus_scan_available? &&
+ Setting.antivirus_scan_mode != :disabled &&
+ EnterpriseToken.allows_to?(:virus_scanning)
end
end
end
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index e1241b4d3ca..83a6f13cb12 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -102,6 +102,10 @@ module Settings
description: "Time in minutes to wait before uploaded files not attached to any container are removed",
default: 180
},
+ antivirus_scan_available: {
+ description: "Virus scanning option selectable in the UI",
+ default: true
+ },
antivirus_scan_mode: {
description: "Virus scanning option for files uploaded to OpenProject",
format: :symbol,