summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2023-12-22 02:25:17 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2023-12-22 02:25:17 +0000
commit5df44ab302f0366b2bbc4fd5deea08179ea75c15 (patch)
tree5c5f889ec839adcfc9dddb6b9735c73ab6a76627
parentd05d732080fac8599cdbb182009c78e60ba3518e (diff)
downloadredmine-5df44ab302f0366b2bbc4fd5deea08179ea75c15.tar.gz
redmine-5df44ab302f0366b2bbc4fd5deea08179ea75c15.zip
Backport r22551 from trunk to 5.0-stable (#39862).
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22553 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--config/routes.rb4
-rw-r--r--lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb24
2 files changed, 27 insertions, 1 deletions
diff --git a/config/routes.rb b/config/routes.rb
index 1a920b1b4..ad7a44dc9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -312,7 +312,9 @@ Rails.application.routes.draw do
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
resources :attachments, :only => [:show, :update, :destroy]
- constraints object_type: /(issues|versions|news|messages|wiki_pages|projects|documents|journals)/ do
+
+ # register plugin object types with ObjectTypeConstraint.register_object_type(PluginModel.name.underscore.pluralize')
+ constraints Redmine::Acts::Attachable::ObjectTypeConstraint do
get 'attachments/:object_type/:object_id/edit', :to => 'attachments#edit_all', :as => :object_attachments_edit
patch 'attachments/:object_type/:object_id', :to => 'attachments#update_all', :as => :object_attachments
get 'attachments/:object_type/:object_id/download', :to => 'attachments#download_all', :as => :object_attachments_download
diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index 4a069980d..9c09a7870 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -20,6 +20,30 @@
module Redmine
module Acts
module Attachable
+
+ class ObjectTypeConstraint
+ cattr_accessor :object_types
+
+ self.object_types = Concurrent::Set.new(%w[
+ issues versions news messages wiki_pages projects documents journals
+ ])
+
+ class << self
+ def matches?(request)
+ request.path_parameters[:object_type] =~ param_expression
+ end
+
+ def register_object_type(type)
+ object_types << type
+ @param_expression = nil
+ end
+
+ def param_expression
+ @param_expression ||= Regexp.new("^(#{object_types.join("|")})$")
+ end
+ end
+ end
+
def self.included(base)
base.extend ClassMethods
end