From 076dc17e1f50c4b9c31759d4640ab24472a43469 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Vilain Date: Tue, 18 Jun 2013 17:16:41 +0200 Subject: [PATCH] SONAR-4136 Added shared dashboards ownership change for admins --- .../app/controllers/dashboards_controller.rb | 26 ++++++++--- .../webapp/WEB-INF/app/models/dashboard.rb | 2 +- .../dashboards/_available_dashboards.html.erb | 20 ++------- .../views/dashboards/_create_form.html.erb | 44 +++++++++++++++++++ .../dashboards/_dashboard_operations.html.erb | 20 +++++++++ .../views/dashboards/_delete_form.html.erb | 18 ++++++++ .../app/views/dashboards/_edit_form.html.erb | 40 +++++++++++++++++ .../views/dashboards/_my_dashboards.html.erb | 20 +-------- .../app/views/dashboards/index.html.erb | 18 ++++---- .../src/main/webapp/stylesheets/dashboard.css | 11 ----- 10 files changed, 157 insertions(+), 62 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create_form.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_dashboard_operations.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_delete_form.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit_form.html.erb 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 52474be0159..ca949ed9e89 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 @@ -45,10 +45,16 @@ class DashboardsController < ApplicationController end end + def create_form + @global = !params[:resource] + @dashboard = Dashboard.new + render :partial => 'create_form', :resource => params[:resource] + end + def create verify_post_request - @dashboard=Dashboard.new() - @dashboard.user_id=current_user.id + @dashboard = Dashboard.new() + @dashboard.user_id = current_user.id load_dashboard_from_params(@dashboard) active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==@dashboard.name } @@ -69,10 +75,10 @@ class DashboardsController < ApplicationController end end - def edit - @dashboard=Dashboard.find(params[:id]) + def edit_form + @dashboard = Dashboard.find(params[:id]) if @dashboard.editable_by?(current_user) - render :partial => 'edit' + render :partial => 'edit_form', :resource => params[:resource] else redirect_to :action => 'index', :resource => params[:resource] end @@ -92,6 +98,15 @@ class DashboardsController < ApplicationController redirect_to :action => 'index', :resource => params[:resource] end + def delete_form + @dashboard = Dashboard.find(params[:id]) + if @dashboard.editable_by?(current_user) + render :partial => 'delete_form', :resource => params[:resource] + else + redirect_to :action => 'index', :resource => params[:resource] + end + end + def delete verify_post_request dashboard=Dashboard.find(params[:id]) @@ -174,6 +189,7 @@ class DashboardsController < ApplicationController dashboard.is_global=(params[:global].present?) dashboard.shared=(params[:shared].present? && is_admin?) dashboard.column_layout=Dashboard::DEFAULT_LAYOUT if !dashboard.column_layout + dashboard.user = User.find_active_by_login(params[:owner]) unless params[:owner].nil? end def add_default_dashboards_if_first_user_dashboard(global) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb index 4d8577fff51..f4337a54e6d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb @@ -68,7 +68,7 @@ class Dashboard < ActiveRecord::Base end def editable_by?(user) - (user && self.user_id==user.id) || (user_id.nil? && user.has_role?(:admin)) + (user && self.user_id==user.id) || user.has_role?(:admin) end def owner?(user) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb index 1146206e2fd..a60c371d5ad 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_available_dashboards.html.erb @@ -13,8 +13,7 @@ <%= message('dashboard.no_dashboard') -%> - <% - else + <% else @shared_dashboards.each do |dashboard| %> @@ -29,23 +28,10 @@ <%= h(dashboard.user_name || message('dashboard.username.default')) -%>   - - <% if dashboard.editable_by?(current_user) %> - <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, - :id => "configure-#{u dashboard.name}", :class => 'link-action' %> - | - <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}}, - {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %> - | - <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, - :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %> - | - <% end %> - <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %> - + <%= render :partial => 'dashboard_operations', :locals => {:dashboard => dashboard, :can_be_disabled => true, :subscription_action => 'follow'} %> <% end - end + end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create_form.html.erb new file mode 100644 index 00000000000..a570962e753 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_create_form.html.erb @@ -0,0 +1,44 @@ +
+ <% if @global %> + + <% else %> + + <% end %> +
+ + + +
+
+ + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_dashboard_operations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_dashboard_operations.html.erb new file mode 100644 index 00000000000..98f60da4ffc --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_dashboard_operations.html.erb @@ -0,0 +1,20 @@ + + <% if dashboard.editable_by?(current_user) %> + <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, + :id => "configure-#{u dashboard.name}", :class => 'link-action' %> + | + <%= link_to message('edit'), {:action => :edit_form, :id => dashboard.id, :resource => params[:resource]}, + :id => "edit-#{u dashboard.name}", :class => 'open-modal link-action' %> + + <% if can_be_disabled %> + | + <%= link_to message('delete'), {:action => :delete_form, :id => dashboard.id, :resource => params[:resource]}, + :id => "delete-#{u dashboard.name}", :class => 'open-modal link-action' %> + | + <% end %> + <% end %> + <% if can_be_disabled %> + <%= link_to message(subscription_action), {:action => subscription_action.to_sym, :id => dashboard.id, :resource => params[:resource]}, :method => :post, + :id => "#{subscription_action}-#{u dashboard.name}", :class => 'link-action' %> + <% end %> + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_delete_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_delete_form.html.erb new file mode 100644 index 00000000000..87eb2f68ea2 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_delete_form.html.erb @@ -0,0 +1,18 @@ +
+ +
+ + + +
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit_form.html.erb new file mode 100644 index 00000000000..faa26a54363 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_edit_form.html.erb @@ -0,0 +1,40 @@ +
+ + <% if @dashboard.global %> + + <% else %> + + <% end %> +
+ + + +
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb index 193af39786f..9164ce3927d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboards/_my_dashboards.html.erb @@ -39,25 +39,7 @@ <%= image_tag('transparent_16.gif') %> <% end %> - - <% if dashboard.editable_by?(current_user) %> - <%= link_to message('dashboard.configure_widgets'), {:controller => :dashboard, :action => :configure, :did => dashboard.id, :id => (params[:resource] unless dashboard.global?)}, - :id => "configure-#{u dashboard.name}", :class => 'link-action' %> - | - <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}}, - {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %> - <% if @actives.size() > 1 %> - | - <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post, - :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %> - | - <% end %> - <% end %> - <% if @actives.size() > 1 %> - <%= link_to message('unfollow'), {:action => :unfollow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, - :id => "unfollow-#{u dashboard.name}", :class => 'link-action' %> - <% end %> - + <%= render :partial => 'dashboard_operations', :locals => {:dashboard => dashboard, :can_be_disabled => @actives.length > 1, :subscription_action => 'unfollow'} %> <% end end 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 2fda8e73f69..ff63175ddb2 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 @@ -1,15 +1,15 @@
-
-

<%= message(@global ? 'dashboard.my_global_dashboards' : 'dashboard.my_project_dashboards') -%>

- <%= render_partial :partial => 'my_dashboards', :locals => { :is_admin => is_admin? } %> +
    +
  • + <%= link_to message('create'), {:action => :create_form, :resource => params[:resource]}, :id => "create-link-dashboard", :class => 'open-modal link-action' %> +
  • +
-

<%= message('dashboard.available_dashboards') -%>

- <%= render_partial :partial => 'available_dashboards', :locals => { :is_admin => is_admin? } %> -
+

<%= message(@global ? 'dashboard.my_global_dashboards' : 'dashboard.my_project_dashboards') -%>

+ <%= render_partial :partial => 'my_dashboards', :locals => { :is_admin => is_admin? } %> -
- <%= render :partial => 'dashboards/create' %> -
+

<%= message('dashboard.available_dashboards') -%>

+ <%= render_partial :partial => 'available_dashboards', :locals => { :is_admin => is_admin? } %>
<% if params[:highlight] %> diff --git a/sonar-server/src/main/webapp/stylesheets/dashboard.css b/sonar-server/src/main/webapp/stylesheets/dashboard.css index 4579e3373da..ea1431d917d 100644 --- a/sonar-server/src/main/webapp/stylesheets/dashboard.css +++ b/sonar-server/src/main/webapp/stylesheets/dashboard.css @@ -161,17 +161,6 @@ font-weight: normal; } -#my_dasboards { - margin-right: 280px; -} - -#create_dashboard { - width: 235px; - position: absolute; - top: 0; - right: 28px; -} - /*OPERATIONS*/ #dashboard #dashboard-operations { position: relative; -- 2.39.5