From 965f1d3ec12507edaa980a68a4b13ee295dc4366 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 18 May 2012 13:39:33 +0200 Subject: [PATCH] Fix links in My Dashboards sections --- .../app/controllers/dashboards_controller.rb | 3 +-- .../WEB-INF/app/models/active_dashboard.rb | 4 +++ .../app/views/dashboards/_create.html.erb | 2 +- .../app/views/dashboards/index.html.erb | 27 ++++++++++--------- 4 files changed, 21 insertions(+), 15 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 afe9b33a584..f012d8b8edb 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 @@ -80,7 +80,7 @@ class DashboardsController < ApplicationController load_dashboard_from_params(dashboard) if dashboard.save - if !dashboard.shared? + unless dashboard.shared? ActiveDashboard.destroy_all(['dashboard_id = ? and (user_id<>? OR user_id IS NULL)', dashboard.id, current_user.id]) end else @@ -182,5 +182,4 @@ class DashboardsController < ApplicationController end end - end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb index b902485966e..abdbbfa00c8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_dashboard.rb @@ -43,6 +43,10 @@ class ActiveDashboard < ActiveRecord::Base dashboard.owner?(user) end + def editable_by?(user) + dashboard.editable_by?(user) + end + def follower?(user) self.user.nil? || self.user_id==user.id end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb index 63661de8333..f3e9a09e4ee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create.html.erb @@ -15,7 +15,7 @@ <% if is_admin? %> - + <%= message('shared') -%>:
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb index fc41d6de894..705f7d27e0d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/index.html.erb @@ -24,7 +24,7 @@ <% @actives.each_with_index do |active, index| %> - <%= link_to active.name(true), {:controller => :dashboard, :action => :index, :did => active.dashboard_id, :id => (params[:resource] unless active.global?)} -%> + <%= active.name(true) -%>
<%= h active.dashboard.description -%>
<% if is_admin %> @@ -34,27 +34,32 @@ <% end %> <% if index > 0 %> - <%= link_to image_tag('blue-up.png'), {:action => 'up', :id => active.id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %> + <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.id, :resource => params[:resource]}, :method => :post, :id => "up-#{u active.name}" %> <% else %> <%= image_tag('transparent_16.gif') %> <% end %> <% if index < @actives.size-1 %> - <%= link_to image_tag('blue-down.png'), {:action => 'down', :id => active.id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %> + <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.id, :resource => params[:resource]}, :method => :post, :id => "down-#{u active.name}" %> <% end %> - <% if active.owner?(current_user) %> + <% if active.editable_by?(current_user) %> <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => active.dashboard_id, :id => (params[:resource] unless active.global?)}, :id => "configure-#{u active.name}", :class => 'link-action' %> | <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => active.dashboard_id, :resource => params[:resource]}}, {:id => "edit-#{u active.name}", :method => :get, :class => 'link-action'} %> <% if @actives.size() > 1 %> - | - <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, - :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %> + | + <% if active.owner?(current_user) %> + <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, + :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %> + <% else %> + <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, + :id => "unfollow-#{u active.name}", :class => 'link-action' %> + <% end %> <% end %> - <% elsif @actives.size() > 1 %> + <% elsif !active.owner?(current_user) && (@actives.size() > 1) %> <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post, :id => "unfollow-#{u active.name}", :class => 'link-action' %> <% end %> @@ -86,10 +91,8 @@ @shared_dashboards.each do |dashboard| %> - <%= link_to dashboard.name(true), {:controller => :dashboard, :action => :index, :id => params[:resource], :did => dashboard.id} -%> - <% if dashboard.description.present? %> -

<%= h dashboard.description -%>

- <% end %> + <%= dashboard.name(true) -%> +
<%= h dashboard.description -%>
<%= dashboard.user_name -%> -- 2.39.5