myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2458] trunk/lib/authorization.rb: added ability


From: noreply
Subject: [myexperiment-hackers] [2458] trunk/lib/authorization.rb: added ability to join via arbitrary columns for authorisation and reordered joins so that policies /permissions come first
Date: Mon, 5 Jul 2010 22:30:27 -0400 (EDT)

Revision
2458
Author
dgc
Date
2010-07-05 22:30:25 -0400 (Mon, 05 Jul 2010)

Log Message

added ability to join via arbitrary columns for authorisation and reordered joins so that policies/permissions come first

Modified Paths

Diff

Modified: trunk/lib/authorization.rb (2457 => 2458)


--- trunk/lib/authorization.rb	2010-07-05 08:53:40 UTC (rev 2457)
+++ trunk/lib/authorization.rb	2010-07-06 02:30:25 UTC (rev 2458)
@@ -806,8 +806,11 @@
 
     # filtering
 
+    auth_id   = opts.delete(:auth_id)   || "#{model.table_name}.id"
+    auth_type = opts.delete(:auth_type) || "'#{model.name}'"
+
     conditions.push(view_conditions(user_id, friends, networks))
-    conditions.push("contributions.contributable_type = '#{model.name}'") if model != Contribution
+    conditions.push("contributions.contributable_type = #{auth_type}") if model != Contribution
 
     # result model
 
@@ -816,7 +819,7 @@
     end
 
     if model != Contribution
-      joins.push("INNER JOIN contributions ON contributions.contributable_id = #{model.table_name}.id AND contributions.contributable_type = '#{model.name}'")
+      joins.push("INNER JOIN contributions ON contributions.contributable_id = #{auth_id} AND contributions.contributable_type = #{auth_type}")
     end
 
     # selection
@@ -842,7 +845,7 @@
     if joins.length > 0
       opts[:joins] = [] unless opts[:joins]
       opts[:joins] = [opts[:joins]] unless opts[:joins].class == Array
-      opts[:joins] = opts[:joins] + joins
+      opts[:joins] = joins + opts[:joins]
       opts[:joins] = opts[:joins].join(" ") # Rails 1 does not support arrays here
     end
 
@@ -859,9 +862,9 @@
       end
     end
 
-    # enforce grouping by contributable type and id
+    # default to grouping by contributable type and id
 
-    opts[:group] = 'contributable_type, contributable_id'
+    opts[:group] ||= 'contributions.contributable_type, contributions.contributable_id'
 
     # do it
 

reply via email to

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