]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5036 When drilling down on a measure, return all projects (even the projects...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 25 Aug 2014 14:33:13 +0000 (16:33 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 25 Aug 2014 14:33:13 +0000 (16:33 +0200)
server/sonar-web/src/main/webapp/WEB-INF/app/models/drilldown.rb
server/sonar-web/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb
server/sonar-web/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 012d8eacceb7bdbf90d5bc0ef7ca54cef4b5d9c6..bbd44a080e094eafb7d52731e3c44c9aa79326a5 100644 (file)
@@ -19,7 +19,7 @@
 #
 class Drilldown
 
-  attr_reader :resource, :metric, :selected_resource_ids, :controller
+  attr_reader :resource, :metric, :selected_resource_ids, :controller, :selected_project_not_authorized
   attr_reader :snapshot, :columns, :highlighted_resource, :highlighted_snapshot
 
   def initialize(resource, metric, selected_resource_ids, controller, options={})
@@ -39,6 +39,11 @@ class Drilldown
           if column.selected_snapshot
             @highlighted_snapshot=column.selected_snapshot
             @highlighted_resource=column.selected_snapshot.project
+            # User should only access projects he's authorized to see.
+            unless controller.has_role?(:user, (column.selected_snapshot.project.copy_resource_id || column.selected_snapshot.resource_id_for_authorization))
+              @selected_project_not_authorized = true
+              break
+            end
           end
         end
         column=DrilldownColumn.new(self, column)
@@ -142,13 +147,7 @@ class DrilldownColumn
     sids=@measures.map { |m| m.snapshot_id }.compact.uniq
     unless sids.empty?
       snapshots = Snapshot.all(:include => :project, :conditions => {'snapshots.id' => sids})
-
-      # User should only see projects he's authorized to see.
-      authorized_project_ids = snapshots.map{|s| s.project.copy_resource_id || s.resource_id_for_authorization}.compact
-      authorized_project_ids = @drilldown.controller.select_authorized(:user, authorized_project_ids) unless authorized_project_ids.empty?
-      authorized_snapshots = snapshots.select{|s| authorized_project_ids.include?(s.project.copy_resource_id || s.resource_id_for_authorization)}
-
-      authorized_snapshots.each do |snapshot|
+      snapshots.each do |snapshot|
         @resource_per_sid[snapshot.id]=snapshot.project
         if @drilldown.selected_resource_ids.include?(snapshot.project_id)
           @selected_snapshot=snapshot
@@ -157,7 +156,6 @@ class DrilldownColumn
     end
   end
 
-  # The resource can be null if it's linked to a copy (on a View or a Developer)
   def resource(measure)
     @resource_per_sid[measure.snapshot_id]
   end
index 03f26531bd76bc550c8ea4bc2b18c4381c94bda4..1f9d2a805bd7ffc2e89ce464d2a8a69f3ce3f736 100644 (file)
    rids=[]
    first_column=true
    last_base_snapshot=nil
+   last_column = nil
    @drilldown.columns.each_with_index do |column, index|
 %>
   <% if first_column %>
         <%
            column.measures.each_with_index do |measure, row_index|
              resource=column.resource(measure)
-             if resource
-               clazz = cycle('even', 'odd', :name => "col_#{index}")
-               selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
-               if selected
-                 clazz += ' selected'
-                 paths << [h(resource.name), @selected_rids-[resource.id]]
-               end
+             clazz = cycle('even', 'odd', :name => "col_#{index}")
+             selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
+             if selected
+               clazz += ' selected'
+               paths << [h(resource.name), @selected_rids-[resource.id]]
+             end
         %>
           <tr class="<%= clazz -%>" id="row_<%= index -%>_<%= row_index -%>">
             <td nowrap>
               <%= @period ? format_variation(measure, :period => @period, :style => 'light') : measure.formatted_value -%>
             </td>
           </tr>
-          <% end
-             end %>
+        <% end %>
       </table>
     </div>
   </td>
   <% end
      first_column = column.switch?
      rids<<column.selected_snapshot.project_id if column.selected_snapshot
+     last_column = column
 
      # column.base_snapshot contain the real snapshot that is selected. We have to use in when loading issues in order to corretly load issues, for instance on views.
      last_base_snapshot = column.base_snapshot
      end
   %>
+  <% if last_column && @drilldown.selected_project_not_authorized %>
+    <p class="notes"><%= message('not_authorized_to_access_project', {:params => last_column.selected_snapshot.project.name}) -%></p>
+  <% end %>
 
 <script>
   $j('#col_rules tr.selected').each(function (index,item) {
index 142eb95bb77d52a3a5ac04e78b952e6745e3e3bd..56e4d0500d72d773fed5f36a0e76c427d0a8299b 100644 (file)
@@ -56,6 +56,7 @@
   <%
      rids=[]
      first_column=true
+     last_column = nil
      @drilldown.columns.each_with_index do |column, index|
   %>
     <% if first_column %>
         <table class="spaced">
           <% column.measures.each_with_index do |measure, row_index|
             resource=column.resource(measure)
-            if resource
-              selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
-              clazz = cycle("even", "odd", :name => "col_#{index}")
-              clazz = clazz + ' selected' if selected
+            selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
+            clazz = cycle("even", "odd", :name => "col_#{index}")
+            clazz = clazz + ' selected' if selected
           %>
             <tr class="<%= clazz -%>" id="row_<%= index -%>_<%= row_index -%>">
               <td nowrap>
@@ -95,8 +95,7 @@
                 <%= format_measure(measure, :skip_span_id => true, :period => @period) -%>
               </td>
             </tr>
-          <% end
-            end %>
+          <% end %>
         </table>
       </div>
     </td>
     <% end
        first_column = column.switch?
        rids<<column.selected_snapshot.project_id if column.selected_snapshot
+       last_column = column
        end
     %>
+    <% if last_column && @drilldown.selected_project_not_authorized %>
+      <p class="notes"><%= message('not_authorized_to_access_project', {:params => last_column.selected_snapshot.project.name}) -%></p>
+    <% end %>
 </div>
 <script>
   <% for i in 0...@drilldown.columns.size do  %>
index 6ec7275a21f665b08f813cb502e1866ce2b69b12..bc649128268d58b6b6b537ea6761b98fb82b88aa 100644 (file)
@@ -222,6 +222,7 @@ new_window=New window
 no_data=No data
 no_lines_match_your_filter_criteria=No lines match your filter criteria.
 no_results=No results
+not_authorized_to_access_project=You are not authorized to access to this '{0}' project
 over_x_days=over {0} days
 over_x_days.short={0} days
 over_x_days_detailed=over {0} days ({1})