aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-01-20 10:56:56 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-01-23 19:23:18 +0100
commit2044f95a1c1064f2cde28df0c33af633fdd8d8a2 (patch)
tree04dd4aac0e07726d417d4bded646ba0e7c455f62 /sonar-server
parent2095f5221c41f4df2b3d19b1f880181a092ffc99 (diff)
downloadsonarqube-2044f95a1c1064f2cde28df0c33af633fdd8d8a2.tar.gz
sonarqube-2044f95a1c1064f2cde28df0c33af633fdd8d8a2.zip
SONAR-1492 Allow notes per quality rule
=> DB stuff & Ruby models implemented
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb45
9 files changed, 111 insertions, 12 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
index 6a92fe9a881..8b66f10adae 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
@@ -32,7 +32,7 @@ class Api::RulesController < Api::RestController
options[:priorities]=params[:priorities].split(',') if params[:priorities]
options[:status]=params[:status]
options[:searchtext]=params[:searchtext]
- options[:include_parameters]=true
+ options[:include_parameters_and_notes]=true
options[:inheritance]=params[:inheritance]
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
index e372f6f7459..4fb539ecf85 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
@@ -58,18 +58,18 @@ class RulesConfigurationController < ApplicationController
@rules = Rule.search(java_facade, {
:profile => @profile, :status => @status, :priorities => @priorities, :inheritance => @inheritance,
- :plugins => @plugins, :searchtext => @searchtext, :include_parameters => true, :language => @profile.language})
+ :plugins => @plugins, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language})
unless @searchtext.blank?
if @status==STATUS_ACTIVE
@hidden_inactives=Rule.search(java_facade, {
:profile => @profile, :status => STATUS_INACTIVE, :priorities => @priorities,
- :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
+ :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
elsif @status==STATUS_INACTIVE
@hidden_actives=Rule.search(java_facade, {
:profile => @profile, :status => STATUS_ACTIVE, :priorities => @priorities,
- :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
+ :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
index f6cc5f3b626..f2613920847 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
@@ -21,6 +21,8 @@ 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
new file mode 100644
index 00000000000..45bdfb4b8bb
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb
@@ -0,0 +1,27 @@
+#
+# 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
+#
+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"
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
index 78691867b8f..72d5ee07cd5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
@@ -24,7 +24,7 @@ class Profile < ActiveRecord::Base
has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
has_many :projects, :order => 'name asc'
has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id',
- :include => ['active_rule_parameters']
+ :include => ['active_rule_parameters', 'active_rule_note']
validates_uniqueness_of :name, :scope => :language, :case_sensitive => false
validates_presence_of :name
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
index cfaa06e534f..e1a75229ee2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
@@ -28,6 +28,8 @@ class Rule < ActiveRecord::Base
has_many :rule_failures
has_many :active_rules
belongs_to :parent, :class_name => 'Rule', :foreign_key => 'parent_id'
+ has_one :rule_note
+ alias_attribute :note, :rule_note
def repository_key
plugin_name
@@ -263,7 +265,7 @@ class Rule < ActiveRecord::Base
values[:key] = searchtext
end
- includes=(options[:include_parameters] ? :rules_parameters : nil)
+ includes=(options[:include_parameters_and_notes] ? [:rules_parameters, :rule_note] : nil)
rules = Rule.find(:all, :include => includes, :conditions => [conditions.join(" AND "), values]).sort
filter(rules, options)
end
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
new file mode 100644
index 00000000000..c879875a95f
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb
@@ -0,0 +1,27 @@
+#
+# 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
+#
+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"
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
index 120f3613207..8ca525c5202 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
@@ -32,9 +32,9 @@
page.toggle "desc_#{rule.id}"
end
%>
- <br/>
<div id="desc_<%= rule.id -%>" class="rule_desc" style="display:none">
- <%= rule.description %>
+ <span class="subtitle"><%= message('key') -%>: <%= rule.plugin_rule_key -%></span>
+ <div style="margin:8px 0px"><%= rule.description %></div>
<table style="margin: 10px 0">
<% rule.parameters.each do |parameter|
active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
@@ -44,10 +44,6 @@
:locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :active_rule => active_rule, :is_admin => is_admin } %>
</tbody>
<% end %>
- <tr>
- <td width="10%" nowrap class="left"><%= message('key') -%>: &nbsp;</td>
- <td class="left"><%= rule.plugin_rule_key -%></td>
- </tr>
</table>
<% if is_admin %>
<% if rule.template? %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb
new file mode 100644
index 00000000000..db934a2d24f
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.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 AddRuleAndActiveRuleNotes < ActiveRecord::Migration
+
+ def self.up
+ create_table :active_rule_notes do |t|
+ t.timestamps
+ t.column :active_rule_id, :integer, :null => true
+ t.column :user_login, :string, :null => true, :limit => 40
+ t.column :data, :binary, :null => true
+ end
+ add_index :active_rule_notes, :active_rule_id
+
+
+ create_table :rule_notes do |t|
+ t.timestamps
+ t.column :rule_id, :integer, :null => true
+ t.column :user_login, :string, :null => true, :limit => 40
+ t.column :data, :binary, :null => true
+ end
+ add_index :rule_notes, :rule_id
+ end
+
+end