aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-19 03:23:26 +0000
committerGodin <mandrikov@gmail.com>2010-12-19 03:23:26 +0000
commitd3bac1b2a70bd187247e6c44ba35f09e1a5a44c6 (patch)
tree126ed9fd242678c8c7a555ff86f825838def27f5 /sonar-server
parent733f89f53adb3364b11420a41aca1280149fbfbd (diff)
downloadsonarqube-d3bac1b2a70bd187247e6c44ba35f09e1a5a44c6.tar.gz
sonarqube-d3bac1b2a70bd187247e6c44ba35f09e1a5a44c6.zip
SONAR-1722: Allow to revert rule state
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java14
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb15
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb1
4 files changed, 33 insertions, 1 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
index 6d692a6e7b7..c5c118dc1cb 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
@@ -124,6 +124,20 @@ public class ProfilesManager extends BaseDao {
getSession().commit();
}
+ public void revert(int profileId, int activeRuleId) {
+ RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
+ ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId);
+ if (activeRule != null && activeRule.isInherited() && activeRule.isOverrides()) {
+ ActiveRule parentActiveRule = getProfile(profile.getParentId()).getActiveRule(activeRule.getRule());
+ removeActiveRule(profile, activeRule);
+ activeRule = (ActiveRule) parentActiveRule.clone();
+ activeRule.setRulesProfile(profile);
+ activeRule.setInherited(true);
+ profile.getActiveRules().add(activeRule);
+ getSession().commit();
+ }
+ }
+
private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule) {
ActiveRule activeRule = profile.getActiveRule(parentActiveRule.getRule());
if (activeRule != null) {
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index a4749ef623b..1808547126f 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -209,6 +209,10 @@ public final class JRubyFacade implements ServerComponent {
getProfilesManager().deactivated(parentProfileId, ruleId);
}
+ public void revertRule(int profileId, int activeRuleId) {
+ getProfilesManager().revert(profileId, activeRuleId);
+ }
+
public List<Footer> getWebFooters() {
return getContainer().getComponents(Footer.class);
}
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 39b20b92cb4..5cd988308d3 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
@@ -29,7 +29,7 @@ class RulesConfigurationController < ApplicationController
RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
- verify :method => :post, :only => ['activate_rule', 'update_param', 'bulk_edit', 'create', 'update', 'delete', 'change_parent'], :redirect_to => { :action => 'index' }
+ verify :method => :post, :only => ['activate_rule', 'update_param', 'bulk_edit', 'create', 'update', 'delete', 'change_parent', 'revert_rule'], :redirect_to => { :action => 'index' }
before_filter :admin_required, :except => [ 'index', 'export' ]
@@ -94,6 +94,19 @@ class RulesConfigurationController < ApplicationController
redirect_to :action => 'index', :id => params[:id]
end
+
+ #
+ #
+ # POST /rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
+ #
+ #
+ def revert_rule
+ id = params[:id].to_i
+ rule_id = params[:active_rule_id].to_i
+ java_facade.revertRule(id, rule_id)
+ redirect_to :action => 'index', :id => params[:id]
+ 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 d612abf3f3f..dd8d4ae7885 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
@@ -27,6 +27,7 @@
<% if inherited %>
<% if overrides %>
Overrides rule from parent profile.<br/>
+ <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
<% else %>
Inherited from parent profile.<br/>
<% end %>