]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1973 Fix review not linked to the project but to the module
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 16 May 2011 13:50:59 +0000 (15:50 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 16 May 2011 13:50:59 +0000 (15:50 +0200)
Reviews should reference the top project that contains the violation
they reference, and not the module. It was not the case, and as a
consequence, the search engine did not work as expected.

sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb

index 8489caea88b6c13e2834b35639f7a7e615d1469c..9658c9dfcb31d38926fed2a961eccf4d0b96b1e8 100644 (file)
@@ -43,6 +43,13 @@ class Project < ActiveRecord::Base
     root||self
   end
   
+  def root_project
+    @root_project ||= 
+      begin
+        parent_module(self)
+      end
+  end
+  
   def last_snapshot
     @last_snapshot ||=
       begin
@@ -153,4 +160,9 @@ class Project < ActiveRecord::Base
     end
     chart_measures
   end
+  
+  def parent_module(current_module)
+    current_module.root ? parent_module(current_module.root) : current_module
+  end
+  
 end
index 46e97ba9c955cf96d8c8d9c3181761b68c11a5a4..1f91e4abe79ccf91bd09fa9f7fd691523b29b7de 100644 (file)
@@ -205,7 +205,7 @@ class Review < ActiveRecord::Base
   
   def assign_project
     if self.project.nil? && self.resource
-      self.project=self.resource.project
+      self.project=self.resource.root_project
     end
   end