]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1927 Introduce more duplication to hopefully improve things after
authorDavid Gageot <david@gageot.net>
Thu, 3 May 2012 07:43:49 +0000 (09:43 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 3 May 2012 10:08:33 +0000 (12:08 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/detached_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_widget_definitions.html.erb

index 6b27afd7a08d3dbb24347e1b0393c66df3acbbed..c743653fed8ed37622f072258dea831d5c4e8d1a 100644 (file)
@@ -54,7 +54,6 @@ class DashboardController < ApplicationController
     unless @dashboard
       redirect_to home_path
     end
-
   end
 
   def edit_layout
@@ -123,7 +122,6 @@ class DashboardController < ApplicationController
     redirect_to :action => 'configure', :did => dashboard.id, :id => params[:id], :highlight => widget_id, :category => params[:category]
   end
 
-
   def save_widget
     widget=Widget.find(params[:wid].to_i)
     #TODO check owner of dashboard
@@ -202,12 +200,9 @@ class DashboardController < ApplicationController
 
   def load_widget_definitions(filter_on_category=nil)
     @widget_definitions=java_facade.getWidgets()
-    @widget_categories=[]
-    @widget_definitions.each { |definition| @widget_categories<<definition.getWidgetCategories() }
-    @widget_categories=@widget_categories.flatten.uniq.sort
+    @widget_categories=@widget_definitions.map(&:getWidgetCategories).flatten.uniq.sort
     unless filter_on_category.blank?
       @widget_definitions=@widget_definitions.select { |definition| definition.getWidgetCategories().to_a.include?(filter_on_category) }
     end
   end
-
-end
\ No newline at end of file
+end
index e06ba529b4e56de138de7fbc56dde7c8c938fa75..09f6df60ce402e8b921824f6285d7ddcb6c5fa20 100644 (file)
@@ -21,10 +21,12 @@ class DetachedController < ApplicationController
 
   SECTION=Navigation::SECTION_HOME
 
-  verify :method => :post, :only => [:create, :update, :delete, :up, :down, :follow, :unfollow], :redirect_to => {:action => :index}
+  verify :method => :post, :only => [:set_layout, :add_widget, :set_dashboard, :save_widget], :redirect_to => {:action => :index}
   before_filter :login_required, :except => [:index]
 
   def index
+    # TODO display error page if no dashboard or no resource
+    load_resource()
     load_dashboard()
     load_authorized_widget_definitions()
     unless @dashboard
@@ -33,6 +35,8 @@ class DetachedController < ApplicationController
   end
 
   def configure
+    # TODO display error page if no dashboard or no resource
+    load_resource()
     load_dashboard()
     @category=params[:category]
     load_widget_definitions(@category)
@@ -42,11 +46,12 @@ class DetachedController < ApplicationController
   end
 
   def edit_layout
+    load_resource()
     load_dashboard()
   end
 
   def set_layout
-    dashboard=Dashboard.find(params[:id])
+    dashboard=Dashboard.find(params[:id].to_i)
     if dashboard.editable_by?(current_user)
       dashboard.column_layout=params[:layout]
       dashboard.save!
@@ -85,7 +90,7 @@ class DetachedController < ApplicationController
   end
 
   def add_widget
-    dashboard=Dashboard.find(params[:id])
+    dashboard=Dashboard.find(params[:id].to_i)
     widget_id=nil
     if dashboard.editable_by?(current_user)
       definition=java_facade.getWidget(params[:widget])
@@ -148,7 +153,23 @@ class DetachedController < ApplicationController
     @dashboard_configuration=Api::DashboardConfiguration.new(@dashboard, :period_index => params[:period], :snapshot => @snapshot) if @dashboard && @snapshot
   end
 
+  def load_resource
+  end
+
   def load_authorized_widget_definitions
+    if @resource
+      @authorized_widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language, @snapshot.metric_keys.to_java(:string))
+      @authorized_widget_definitions=@authorized_widget_definitions.select do |widget|
+        authorized=widget.getUserRoles().size==0
+        unless authorized
+          widget.getUserRoles().each do |role|
+            authorized=(role=='user') || (role=='viewer') || has_role?(role, @resource)
+            break if authorized
+          end
+        end
+        authorized
+      end
+    end
   end
 
   def load_widget_definitions(filter_on_category=nil)
index aaaa78408980fe7125b6b53ae722913af41fb737..aaee68693d9e8fd02f701e88c3b8b122b9198438 100644 (file)
@@ -16,6 +16,8 @@
   <% end %>
   <% for i in 0..(4-(@widget_definitions.size%4)) %>
     <td> </td>
-  <% end %> 
-  <% if @widget_definitions.size%4<3 %></tr><% end %>
+  <% end %>
+  <% if @widget_definitions.size%4<3 %>
+         </tr>
+  <% end %>
 </table>