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

Implement attachment status

Oliver Günther731c8937eaf7
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index de87d4fd9f7..4bbb42be8b7 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -29,10 +29,16 @@
require 'digest/md5'
class Attachment < ApplicationRecord
+ enum status: {
+ new: 0,
+ prepared: 1,
+ scanned: 2
+ }.freeze, _prefix: true, _default: :new
+
belongs_to :container, polymorphic: true
belongs_to :author, class_name: 'User'
- validates :author, :content_type, :filesize, presence: true
+ validates :author, :content_type, :filesize, :status, presence: true
validates :description, length: { maximum: 255 }
validate :filesize_below_allowed_maximum,
@@ -122,7 +128,7 @@ class Attachment < ApplicationRecord
end
def prepared?
- downloads == -1
+ status_prepared?
end
# images are sent inline
diff --git a/app/services/attachments/set_prepared_attributes_service.rb b/app/services/attachments/set_prepared_attributes_service.rb
index 73ab99f3157..4da64362694 100644
--- a/app/services/attachments/set_prepared_attributes_service.rb
+++ b/app/services/attachments/set_prepared_attributes_service.rb
@@ -47,7 +47,7 @@ module Attachments
model.extend(OpenProject::ChangedBySystem)
model.change_by_system do
- model.downloads = -1
+ model.status = :prepared
# Set a preliminary content type as the file is not present
# The content type will be updated by the FinishDirectUploadJob if necessary.
model.content_type = params[:content_type].presence || OpenProject::ContentTypeDetector::SENSIBLE_DEFAULT
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index a56fe708878..1a156798382 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -106,8 +106,8 @@ module Settings
antivirus_scan_action: {
description: 'Virus scanning action for found infected files',
format: :symbol,
- default: :quarantine,
- allowed: %i[log quarantine delete]
+ default: :delete,
+ allowed: %i[log delete]
},
auth_source_sso: {
description: 'Configuration for Header-based Single Sign-On',
diff --git a/db/migrate/20240207075946_add_status_to_attachment.rb b/db/migrate/20240207075946_add_status_to_attachment.rb
new file mode 100644
index 00000000000..316644ce3af
--- /dev/null
+++ b/db/migrate/20240207075946_add_status_to_attachment.rb
@@ -0,0 +1,5 @@
+class AddStatusToAttachment < ActiveRecord::Migration[7.1]
+ def change
+ add_column :attachments, :status, :integer, default: 0, null: false
+ end
+end