]> source.dussan.org Git - redmine.git/commitdiff
Introduces Redmine::Plugin#attachment_object_type to provide better API for registeri...
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 27 Feb 2024 07:06:47 +0000 (07:06 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 27 Feb 2024 07:06:47 +0000 (07:06 +0000)
Patch by Jens Krämer (@jkraemer).

git-svn-id: https://svn.redmine.org/redmine/trunk@22747 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/plugin.rb
test/unit/lib/redmine/plugin_test.rb

index c750c492ddf02a13670443c3f268cd47e5f4f6fe..17a20f5a8bc6387e5ca2d37eec81b0854a029a4f 100644 (file)
@@ -428,6 +428,18 @@ module Redmine
       Redmine::WikiFormatting.register(name, *args)
     end
 
+    # Register plugin models that use acts_as_attachable.
+    #
+    # Example:
+    #   attachment_object_type SomeAttachableModel
+    #
+    # This is necessary for the core attachments controller routes and attachments/_form to work.
+    def attachment_object_type(*args)
+      args.each do |klass|
+        Redmine::Acts::Attachable::ObjectTypeConstraint.register_object_type(klass.name.underscore.pluralize)
+      end
+    end
+
     # Returns +true+ if the plugin can be configured.
     def configurable?
       settings && settings.is_a?(Hash) && settings[:partial].present?
index 1b53f7ebf8cac092d51932cf91de830691d986a4..66865481b2e9ffc8efa37143062d2434f8d1c171 100644 (file)
@@ -62,6 +62,14 @@ class Redmine::PluginTest < ActiveSupport::TestCase
     assert_equal File.join(@klass.directory, 'foo_plugin', 'assets'), plugin.assets_directory
   end
 
+  ::FooModel = Class.new(ActiveRecord::Base)
+  def test_register_attachment_object_type
+    Redmine::Acts::Attachable::ObjectTypeConstraint.expects(:register_object_type).with("foo_models")
+    @klass.register :foo_plugin do
+      attachment_object_type FooModel
+    end
+  end
+
   def test_register_should_raise_error_if_plugin_directory_does_not_exist
     e = assert_raises Redmine::PluginNotFound do
       @klass.register(:bar_plugin) {}