]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3102 Fix issues on reviews when a user is deleted from the DB
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 13 Feb 2012 16:58:39 +0000 (17:58 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 13 Feb 2012 16:58:39 +0000 (17:58 +0100)
It was not possible to see or update a review which had been created/
assigned/commented by a deleted user.

=> A migration script cleans the DB and the constraint on review
   author is now removed

sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb [new file with mode: 0644]

index 58325dfd4bcbcecf0111d1f5aa421e1fa18ba270..1d01411d8151ca874a3d295c50911dc21e33e438 100644 (file)
@@ -34,7 +34,7 @@ public class SchemaMigration {
 
   public final static int VERSION_UNKNOWN = -1;
 
-  public static final int LAST_VERSION = 259;
+  public static final int LAST_VERSION = 260;
   public static final int VERSION_2_13 = 241;
 
   public final static String TABLE_NAME = "schema_migrations";
index c1dad7a4d3547b674b782dfdcba97f468b95d883..55e139b8d158a3d9ac147ac2eef6b2852a02cf6a 100644 (file)
@@ -27,7 +27,6 @@ class Review < ActiveRecord::Base
   alias_attribute :comments, :review_comments
   has_and_belongs_to_many :action_plans
 
-  validates_presence_of :user, :message => "can't be empty"
   validates_presence_of :status, :message => "can't be empty"
   validates_inclusion_of :severity, :in => Severity::KEYS
 
index 14e22c06400649cefa5be6ff548e8503ecd40ec3..ccbd6eadd085e9c47e2005102288925c819be36a 100644 (file)
@@ -78,7 +78,7 @@
         <%= message('author') -%>:
       </td>
       <td class="val">
-        <%= h(review.user.name) -%>
+        <%= review.user ? h(review.user.name) : '-' -%>
       </td>
     </tr>
     <tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb
new file mode 100644 (file)
index 0000000..892fc18
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+
+#
+# Sonar 2.14
+#
+class FixReviewsWithDeletedUser < ActiveRecord::Migration
+
+  def self.up
+    # For http://jira.codehaus.org/browse/SONAR-3102
+    Review.find(:all, :include => ['assignee', 'user']).each do |review|
+      if review.user_id && !review.user
+        review.user_id=nil
+        must_save=true
+      end
+      if review.assignee_id && !review.assignee
+        review.assignee_id=nil
+        must_save=true
+      end
+      review.save if must_save
+    end
+
+    ReviewComment.find(:all, :include => 'user').each do |comment|
+      comment.delete if comment.user_id && !comment.user
+    end
+  end
+
+end