From 4677430bfe3da77a26dd23ae3e9296952e0bb40c Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 13 Feb 2012 17:58:39 +0100 Subject: [PATCH] SONAR-3102 Fix issues on reviews when a user is deleted from the DB 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 --- .../org/sonar/jpa/entity/SchemaMigration.java | 2 +- .../main/webapp/WEB-INF/app/models/review.rb | 1 - .../views/project_reviews/_review.html.erb | 2 +- .../260_fix_reviews_with_deleted_user.rb | 45 +++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index 58325dfd4bc..1d01411d815 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -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"; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index c1dad7a4d35..55e139b8d15 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb index 14e22c06400..ccbd6eadd08 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb @@ -78,7 +78,7 @@ <%= message('author') -%>: - <%= h(review.user.name) -%> + <%= review.user ? h(review.user.name) : '-' -%> 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 index 00000000000..892fc182177 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/260_fix_reviews_with_deleted_user.rb @@ -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 -- 2.39.5