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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Implement attachment status
Oliver Günther731c8937eaf7
diff --git a/app/models/attachment.rb b/app/models/attachment.rbindex 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: truebelongs_to :author, class_name: 'User'- validates :author, :content_type, :filesize, presence: true+ validates :author, :content_type, :filesize, :status, presence: truevalidates :description, length: { maximum: 255 }validate :filesize_below_allowed_maximum,@@ -122,7 +128,7 @@ class Attachment < ApplicationRecordenddef prepared?- downloads == -1+ status_prepared?end# images are sent inlinediff --git a/app/services/attachments/set_prepared_attributes_service.rb b/app/services/attachments/set_prepared_attributes_service.rbindex 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 Attachmentsmodel.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_DEFAULTdiff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex a56fe708878..1a156798382 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -106,8 +106,8 @@ module Settingsantivirus_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.rbnew file mode 100644index 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