]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4923 Remove rule_notes and active_rule_notes table and correctly display notes...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 22 Jan 2014 10:28:45 +0000 (11:28 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 22 Jan 2014 10:28:55 +0000 (11:28 +0100)
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/492_remove_rule_notes_and_active_rule_notes.rb [new file with mode: 0644]

index 91ed2ee273572cc5d5a6d9c36c8e4c0c717e3662..d7fda0833c65393e7de6711608677437422acdc9 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 491;
+  public static final int LAST_VERSION = 492;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 0f001cee48e727cf781e4bf5a043008ecfbcb7ee..0b77126778f58d5aacaef6af19b90a47a6a6e120 100644 (file)
@@ -202,6 +202,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('488');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('489');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('490');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('491');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('492');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index f250e0019b9a167eab419f202235540ed31f1369..a1a965d2f1bbdd423544426d0674da744e016069 100644 (file)
@@ -411,24 +411,6 @@ CREATE TABLE "ACTION_PLANS" (
   "UPDATED_AT" TIMESTAMP
 );
 
-CREATE TABLE "ACTIVE_RULE_NOTES" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "ACTIVE_RULE_ID" INTEGER,
-  "USER_LOGIN" VARCHAR(40),
-  "DATA" CLOB(2147483647),
-  "CREATED_AT" TIMESTAMP,
-  "UPDATED_AT" TIMESTAMP
-);
-
-CREATE TABLE "RULE_NOTES" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "RULE_ID" INTEGER,
-  "USER_LOGIN" VARCHAR(40),
-  "DATA" CLOB(2147483647),
-  "CREATED_AT" TIMESTAMP,
-  "UPDATED_AT" TIMESTAMP
-);
-
 CREATE TABLE "AUTHORS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "PERSON_ID" INTEGER,
@@ -656,10 +638,6 @@ CREATE INDEX "RESOURCE_INDEX_RID" ON "RESOURCE_INDEX" ("RESOURCE_ID");
 
 CREATE INDEX "INDEX_ACTION_PLANS_ON_PROJET_ID" ON "ACTION_PLANS" ("PROJECT_ID");
 
-CREATE INDEX "INDEX_ACTIVE_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_NOTES" ("ACTIVE_RULE_ID");
-
-CREATE INDEX "INDEX_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "RULE_NOTES" ("RULE_ID");
-
 CREATE UNIQUE INDEX "UNIQ_SEMAPHORE_CHECKSUMS" ON "SEMAPHORES" ("CHECKSUM");
 
 CREATE INDEX "SEMAPHORE_NAMES" ON "SEMAPHORES" ("NAME");
index 569a39dc1dfe2c92324a9c1419bfcf787daffa3f..fc250dcc0dcca6f56cb24d2bfd07c085170dba7a 100644 (file)
@@ -47,5 +47,13 @@ module RulesConfigurationHelper
     "#{qProfileRule.repositoryKey().to_s}:#{qProfileRule.key().to_s}"
   end
 
+  def html_text(text)
+    Api::Utils.markdown_to_html(text)
+  end
+
+  def plain_text(text)
+    Api::Utils.convert_string_to_unix_newlines(text)
+  end
+
 end
 
index 0267f2e642863be06d584fab689666347e5bab35..d61881477a731afe5087656426686f4d9fa25126 100644 (file)
@@ -21,8 +21,6 @@ class ActiveRule < ActiveRecord::Base
   belongs_to :rules_profile, :class_name => 'Profile', :foreign_key => 'profile_id'
   belongs_to :rule
   has_many :active_rule_parameters, :dependent => :destroy
-  has_one :active_rule_note
-  alias_attribute :note, :active_rule_note
 
   def level
     failure_level
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb
deleted file mode 100644 (file)
index 9a732e3..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2013 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube 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.
-#
-# SonarQube 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 this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-class ActiveRuleNote < ActiveRecord::Base
-  belongs_to :active_rule
-  alias_attribute :text, :data
-  
-  validates_presence_of :active_rule, :message => "can't be empty"
-  validates_presence_of :user_login, :message => "can't be empty"
-  validates_length_of :data, :minimum => 1
-
-  def user
-    @user ||=
-        begin
-          user_login ? User.first(:conditions => ['login=?', user_login]) : nil
-        end
-  end
-
-  def html_text
-    Api::Utils.markdown_to_html(text)
-  end
-
-  def plain_text
-    Api::Utils.convert_string_to_unix_newlines(text)
-  end
-  
-end
index 97d1bf5bba3d2de99bae1f0cec862a4dda8ea98a..4fb806c1fe43a2c088708afdcd03558b9fa5e0b4 100644 (file)
@@ -36,8 +36,6 @@ class Rule < ActiveRecord::Base
   has_many :rules_parameters, :inverse_of => :rule
   has_many :active_rules, :inverse_of => :rule
   belongs_to :parent, :class_name => 'Rule', :foreign_key => 'parent_id'
-  has_one :rule_note, :inverse_of => :rule
-  alias_attribute :note, :rule_note
 
 =begin TODO Uncomment these lines to make rule read-only when Rule facade is complete
   def read_only?
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb
deleted file mode 100644 (file)
index 8592e61..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2013 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube 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.
-#
-# SonarQube 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 this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-#
-class RuleNote < ActiveRecord::Base
-  belongs_to :rule
-  alias_attribute :text, :data
-  
-  validates_presence_of :rule, :message => "can't be empty"
-  validates_presence_of :user_login, :message => "can't be empty"
-
-  def user
-    @user ||=
-        begin
-          user_login ? User.find(:first, :conditions => ['login=?', user_login]) : nil
-        end
-  end
-
-  def html_text
-    Api::Utils.markdown_to_html(text)
-  end
-
-  def plain_text
-    Api::Utils.convert_string_to_unix_newlines(text)
-  end
-  
-end
index 23b66caa197ab64d508cc730a0b1866991fa5d1e..c18b5994a27298090c5d7a17215780d4f32adac4 100644 (file)
@@ -29,7 +29,7 @@
              href="#!"><%=message('delete')-%></a>
         <% end %>
       </cite>
-      <p><%= note.data -%></p>
+      <p><%= html_text(note.data) -%></p>
     </blockquote>
   <% elsif profiles_administrator? %>
     <a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
@@ -52,7 +52,7 @@
       <tr>
         <td class="width100" colspan="2">
           <textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
-                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.data) unless note.nil? -%></textarea>
+                    onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(plain_text(note.data)) unless note.nil? -%></textarea>
         </td>
       </tr>
     <tr>
index 966c94d1c6a13d91f73f3e76fcfc0cfa48f89519..a84e48f9bd32e58f9d94c4dfa777e3d8d4c7db54 100644 (file)
@@ -18,8 +18,8 @@
   <% end %>
   </div>
 
-  <% unless rule.ruleNote.nil? %>
-    <p><%= rule.ruleNote.data -%></p>
+  <% if rule.ruleNote && !rule.ruleNote.data.strip.blank? %>
+    <p><%= html_text(rule.ruleNote.data) -%></p>
   <% end %>
 
   <% if profiles_administrator? %>
@@ -48,7 +48,7 @@
       </tr>
       <tr>
         <td class="width100" colspan="2">
-          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.data) if note -%></textarea>
+          <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(plain_text(note.data)) if note -%></textarea>
         </td>
       </tr>
     <tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/492_remove_rule_notes_and_active_rule_notes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/492_remove_rule_notes_and_active_rule_notes.rb
new file mode 100644 (file)
index 0000000..f3e4c84
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# Sonar 4.2
+# SONAR-4923
+#
+class RemoveRuleNotesAndActiveRuleNotes < ActiveRecord::Migration
+
+  class Project < ActiveRecord::Base
+  end
+
+  def self.up
+    remove_index_quietly(:active_rule_notes, 'arn_active_rule_id')
+    drop_table(:active_rule_notes)
+
+    remove_index_quietly(:rule_notes, 'rule_notes_rule_id')
+    drop_table(:rule_notes)
+  end
+
+  def self.remove_index_quietly(table, name)
+    begin
+      remove_index(table, :name => name)
+    rescue
+      # probably already removed
+    end
+  end
+
+end