myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3130] trunk/app/models/pack.rb: Fixes to resolve


From: noreply
Subject: [myexperiment-hackers] [3130] trunk/app/models/pack.rb: Fixes to resolve_link for adding:
Date: Wed, 19 Sep 2012 17:08:13 +0000 (UTC)

Revision
3130
Author
dtm
Date
2012-09-19 17:08:12 +0000 (Wed, 19 Sep 2012)

Log Message

Fixes to resolve_link for adding:
- fix failing to find packs (one mapping too many)
- catch something went wrong exception with when using 
  ActionController::Routing::Routes.recognize_path
- let non-contributables be added as external links

Modified Paths

Diff

Modified: trunk/app/models/pack.rb (3129 => 3130)


--- trunk/app/models/pack.rb	2012-09-19 09:58:31 UTC (rev 3129)
+++ trunk/app/models/pack.rb	2012-09-19 17:08:12 UTC (rev 3130)
@@ -513,9 +513,12 @@
         contributable = nil
 
         # Use Rails' routing to figure out the URL
-        request = ActionController::Routing::Routes.recognize_path(uri.path, :method => :get)
-        model_name = request[:controller].classify
-        model_name = Conf.model_aliases.index(model_name) || model_name # Get proper name for model i.e. File -> Blob
+        begin
+          request = ActionController::Routing::Routes.recognize_path(uri.path, :method => :get)
+          model_name = request[:controller].classify
+        rescue Exception => exc
+          raise URI::InvalidURIError
+        end
 
         if Conf.contributable_models.include?(model_name) && request[:action] == "show"
           contributable = eval(model_name).find_by_id(request[:id])
@@ -523,27 +526,29 @@
           is_remote = true # Treat as a remote entry
         end
 
-        if contributable && errors_here.empty?
-          entry = PackContributableEntry.new
-          entry.contributable = contributable
-
-          type = 'contributable'
-
-          # check if the 'contributable' is a pack, then that it's not the same pack,
-          # to which we are trying to add something at the moment
-          if contributable == self.id
-            errors_here.add_to_base('Cannot add the pack to itself')
+        if !is_remote
+          if contributable && errors_here.empty?
+            entry = PackContributableEntry.new
+            entry.contributable = contributable
+  
+            type = 'contributable'
+  
+            # check if the 'contributable' is a pack, then that it's not the same pack,
+            # to which we are trying to add something at the moment
+            if contributable == self.id
+              errors_here.add_to_base('Cannot add the pack to itself')
+            end
+  
+            # Check if version was specified in the uri
+            entry.contributable_version = request[:version]
+  
+            # maybe it was as a query instead?
+            if uri.query
+              entry.contributable_version = CGI.parse(uri.query)["version"].first.try(:to_i)
+            end
+          else
+            errors_here.add_to_base('The item the link points to does not exist.')
           end
-
-          # Check if version was specified in the uri
-          entry.contributable_version = request[:version]
-
-          # maybe it was as a query instead?
-          if uri.query
-            entry.contributable_version = CGI.parse(uri.query)["version"].first.try(:to_i)
-          end
-        else
-          errors_here.add_to_base('The item the link points to does not exist.')
         end
       else
         is_remote = true # Treat as a remote entry

reply via email to

[Prev in Thread] Current Thread [Next in Thread]