]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4136 Fixed routing issue on dashboard deletion - Fixed error on SonarQube dashb...
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Fri, 21 Jun 2013 16:04:07 +0000 (18:04 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Fri, 21 Jun 2013 16:04:07 +0000 (18:04 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_delete_form.html.erb

index aa6beb0f624ca244f2c112940e601e67bdeccc7e..758d93d43e2816952ec25a1ca5a74222470ee319 100644 (file)
@@ -100,23 +100,23 @@ class DashboardsController < ApplicationController
     if @dashboard.editable_by?(current_user)
       render :partial => 'delete_form', :resource => params[:resource]
     else
-      redirect_to :action => 'index', :resource => params[:resource]
+      access_denied
     end
   end
 
   def delete
     verify_post_request
-    dashboard=Dashboard.find(params[:id])
+    @dashboard=Dashboard.find(params[:id])
 
-    access_denied unless dashboard.editable_by?(current_user)
+    access_denied unless @dashboard.editable_by?(current_user)
 
-    if dashboard.destroy
+    if @dashboard.destroy
       flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0
+      render :text => params[:resource], :status => 200
     else
-      flash[:error]=Api::Utils.message('dashboard.error_delete_default')
+      @dashboard.errors.add(message('dashboard.error_delete_default'), ' ')
+      render :partial => 'dashboards/delete_form', :status => 400, :resource => params[:resource]
     end
-
-    redirect_to :action => 'index', :resource => params[:resource]
   end
 
   def down
index 1ee10af6bf75e28634b4ce8c9df377333656cd20..55f5266c30d53301d755fc8562f2161640f03bdc 100644 (file)
@@ -46,7 +46,7 @@ class Dashboard < ActiveRecord::Base
   end
 
   def user_rights_consistency
-    if shared? && !user.has_role?(:sharedashboard)
+    if shared? && user && !user.has_role?(:sharedashboard)
       errors.add(:user, "cannot own this dashboard because it has insufficient rights")
     end
   end
index cdc4ea42cc5fc37caac81132f37accd3d23531e0..9d37e5015fff31260c903c7fbbb70ade9f32da95 100644 (file)
@@ -1,5 +1,10 @@
 <form id="delete-dashboard-form" method="post" action="<%= ApplicationController.root_context -%>/dashboards/delete">
-  <input type="hidden" name="id" value="<%= params[:id] -%>">
+  <input type="hidden" name="id" value="<%= @dashboard.id -%>">
+  <% if @dashboard.global %>
+    <input type="hidden" name="global" value="true" />
+  <% else %>
+    <input type="hidden" name="resource" value="<%= params[:resource] %>"/>
+  <% end %>
   <fieldset>
     <div class="modal-head">
       <h2><%= message 'dashboard.delete_confirm_title' -%></h2>
     </div>
   </fieldset>
 </form>
+
+<script>
+  $j("#delete-dashboard-form").modalForm({success: function (data) {
+    var contextParams = data.trim().length > 0 ? '?resource=' + data.trim() : '';
+    window.location = baseUrl + '/dashboards' + contextParams;
+  }});
+</script>