aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-10 10:50:34 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-10 10:50:42 +0200
commit870b9a0be9b0b0d8415ea3ac2c2f576eb011c6fd (patch)
treea838b8d6e5c2838ddd73d5cfae425153279db9cf /sonar-server
parent5aaffa9672bcad7d92bad4609a48de231becdaaf (diff)
downloadsonarqube-870b9a0be9b0b0d8415ea3ac2c2f576eb011c6fd.tar.gz
sonarqube-870b9a0be9b0b0d8415ea3ac2c2f576eb011c6fd.zip
SONAR-4979 While changing owner of a dashboard and unsharing it, current user is still following it
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb37
2 files changed, 45 insertions, 0 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
index 6cdcbd952c5..d5f42cf6027 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
@@ -88,6 +88,13 @@ class DashboardsController < ApplicationController
if @dashboard.editable_by?(current_user)
load_dashboard_from_params(@dashboard)
if @dashboard.save
+
+ # SONAR-4979 If the dashboard is no more shared, current user has to unfollow it if he was following it
+ # unless @dashboard.shared
+ # active = current_user.active_dashboards.to_a.find { |a| (a.user_id == dashboard_owner.id) && (a.dashboard_id == @dashboard.id)}
+ # active.destroy if active
+ # end
+
render :text => CGI.escapeHTML(params[:resource]), :status => 200
else
@dashboard.user = dashboard_owner
@@ -162,6 +169,7 @@ class DashboardsController < ApplicationController
redirect_to :action => 'index', :resource => params[:resource]
end
+
private
def position(offset)
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb
new file mode 100644
index 00000000000..804c2d1c0dd
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb
@@ -0,0 +1,37 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 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.
+#
+
+#
+# SonarQube 4.3
+# SONAR-4979
+#
+class RemoveActiveDashboardsLinkedOnUnsharedDashboards < ActiveRecord::Migration
+
+ class ActiveDashboard < ActiveRecord::Base
+ end
+
+ def self.up
+ ActiveDashboard.reset_column_information
+
+ # Delete every active_dashboards linked on unshared dashboard not owned by the user
+ ActiveDashboard.delete_all(['dashboard_id in (SELECT d.id FROM dashboards d INNER JOIN active_dashboards ad on ad.dashboard_id=d.id WHERE ad.user_id<>d.user_id AND d.shared=?)', false])
+ end
+
+end