]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7779 Event.already_exists can now use component uuid
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 21 Jun 2016 16:04:05 +0000 (18:04 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 27 Jun 2016 08:54:57 +0000 (10:54 +0200)
rather than snapshot id and do a select on snapshot

it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb

index a335d3ead4a7b21f5fd7eea1dd5dd1112e6a27fa..d542196840dc28505db3fdc89d57bd9c22f5c6f0 100644 (file)
@@ -140,7 +140,7 @@ public class ProjectAdministrationTest {
     orchestrator.executeBuild(build);
 
     // There are 7 modules
-    assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(7);
+    assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(1);
 
     Selenese selenese = Selenese.builder()
       .setHtmlTestsInClasspath("modify_version_of_multimodule_project",
index 5034d1fd93832f809f89b5a61ffce93018a62772..0e020368855503b9c3030ab7ab737089dd02b4dc 100644 (file)
@@ -291,7 +291,7 @@ class ProjectController < ApplicationController
     access_denied unless is_admin?(snapshot)
 
     unless params[:version_name].blank?
-      if Event.already_exists(snapshot.id, params[:version_name], EventCategory::KEY_VERSION)
+      if Event.already_exists(snapshot.component_uuid, params[:version_name], EventCategory::KEY_VERSION)
         flash[:error] = message('project_history.version_already_exists', :params => h(params[:version_name]))
       else
         # We update the snapshot to have a version attribute in sync with the new name
@@ -349,7 +349,7 @@ class ProjectController < ApplicationController
     not_found("Snapshot not found") unless snapshot
     access_denied unless is_admin?(snapshot)
 
-    if Event.already_exists(snapshot.id, params[:event_name], EventCategory::KEY_OTHER)
+    if Event.already_exists(snapshot.component_uuid, params[:event_name], EventCategory::KEY_OTHER)
       flash[:error] = message('project_history.event_already_exists', :params => h(params[:event_name]))
     else
       snapshots = find_project_snapshots(snapshot.id)
@@ -372,7 +372,7 @@ class ProjectController < ApplicationController
     not_found("Event not found") unless event
     access_denied unless is_admin?(event.resource)
 
-    if Event.already_exists(event.snapshot_id, params[:event_name], EventCategory::KEY_OTHER)
+    if Event.already_exists(event.component_uuid, params[:event_name], EventCategory::KEY_OTHER)
       flash[:error] = message('project_history.event_already_exists', :params => h(event.name))
     else
       events = find_events(event)
index 6133eaead1e64dfad73ab52e27b391781771495e..be3aa2eafa2b20d666ec47476a16ff767d0805ac 100644 (file)
@@ -68,9 +68,8 @@ class Event < ActiveRecord::Base
   # exists in the history of the corresponding resource (= in any existing 
   # processed snapshot for this resource).
   #
-  def self.already_exists(snapshot_id, event_name, event_category)
-    snapshot = Snapshot.find(snapshot_id.to_i)
-    snapshots = Snapshot.find(:all, :conditions => ["status='P' AND component_uuid=?", snapshot.component_uuid], :include => 'events')
+  def self.already_exists(componentUuid, event_name, event_category)
+    snapshots = Snapshot.find(:all, :conditions => ["status='P' AND component_uuid=?", componentUuid], :include => 'events')
     snapshots.each do |snapshot|
       snapshot.events.each do |event|
         return true if event.name==event_name && event.category==event_category