]> source.dussan.org Git - redmine.git/commitdiff
Simplify AttachmentsController#find_container (#37772).
authorGo MAEDA <maeda@farend.jp>
Thu, 20 Oct 2022 04:14:26 +0000 (04:14 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 20 Oct 2022 04:14:26 +0000 (04:14 +0000)
Patch by  Jens Krämer.

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

app/controllers/attachments_controller.rb

index 612e070d2e1fe7ac7429d54bca4e48a5637e18be..210cd7ba41d66e2fae2b689141a3ac08a95cb645 100644 (file)
@@ -219,19 +219,10 @@ class AttachmentsController < ApplicationController
   end
 
   def find_container
-    klass =
-      begin
-        params[:object_type].to_s.singularize.classify.constantize
-      rescue
-        nil
-      end
-    unless klass && (klass.reflect_on_association(:attachments) || klass.method_defined?(:attachments))
-      render_404
-      return
-    end
-
+    # object_type is constrained to valid values in routes
+    klass = params[:object_type].to_s.singularize.classify.constantize
     @container = klass.find(params[:object_id])
-    if @container.respond_to?(:visible?) && !@container.visible?
+    unless @container.visible?
       render_403
       return
     end