]> source.dussan.org Git - redmine.git/commitdiff
Display all users roles on project overview (#3339).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 12 May 2009 19:04:52 +0000 (19:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 12 May 2009 19:04:52 +0000 (19:04 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2734 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/models/project.rb
app/views/projects/show.rhtml
test/unit/project_test.rb

index 3f29e4e4ce64087ba2dcb7ec9206c15195ecd24c..0dcc874c6e488f275dd9ff2f7e1031d4a22eb23a 100644 (file)
@@ -112,7 +112,7 @@ class ProjectsController < ApplicationController
       redirect_to_project_menu_item(@project, params[:jump]) && return
     end
     
-    @members_by_role = @project.members.find(:all, :include => [:user, :roles], :order => 'position').group_by {|m| m.roles.first}
+    @users_by_role = @project.users_by_role
     @subprojects = @project.children.visible
     @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
     @trackers = @project.rolled_up_trackers
index 64a5e98c8ef4a5a1627c012774a8ba7c2913a507..b022ed96b2272ef4a0086df139f2f8e6e8208f2f 100644 (file)
@@ -245,6 +245,17 @@ class Project < ActiveRecord::Base
                          :order => "#{Tracker.table_name}.position")
   end
   
+  # Returns a hash of project users grouped by role
+  def users_by_role
+    members.find(:all, :include => [:user, :roles]).inject({}) do |h, m|
+      m.roles.each do |r|
+        h[r] ||= []
+        h[r] << m.user
+      end
+      h
+    end
+  end
+  
   # Deletes all project's members
   def delete_all_members
     me, mr = Member.table_name, MemberRole.table_name
index 304fe5d67c9bb950f36f00bd35f25794aaa45dd9..4e068a5d832fdc62132976c9788b165b98d7c4c9 100644 (file)
 </div>
 
 <div class="splitcontentright">
-    <% if @members_by_role.any? %>
+  <% if @users_by_role.any? %>
        <div class="box">
                <h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>       
-               <p><% @members_by_role.keys.sort.each do |role| %>
-               <%= role.name %>:
-               <%= @members_by_role[role].collect(&:user).sort.collect{|u| link_to_user u}.join(", ") %>
-               <br />
+               <p><% @users_by_role.keys.sort.each do |role| %>
+               <%= role.name %>: <%= @users_by_role[role].sort.collect{|u| link_to_user u}.join(", ") %><br />
                <% end %></p>
        </div>
        <% end %>
index 4ecd9d4a8414545eefc507526df3cd9f69211d11..1ea5c19828e7a4931116f41c1b7c2f2bdf4e0263 100644 (file)
@@ -186,6 +186,14 @@ class ProjectTest < Test::Unit::TestCase
     assert_equal [5, 6, 3, 4], d.collect(&:id)\r
   end\r
   \r
+  def test_users_by_role\r
+    users_by_role = Project.find(1).users_by_role\r
+    assert_kind_of Hash, users_by_role\r
+    role = Role.find(1)\r
+    assert_kind_of Array, users_by_role[role]\r
+    assert users_by_role[role].include?(User.find(2))\r
+  end\r
+  \r
   def test_rolled_up_trackers\r
     parent = Project.find(1)\r
     parent.trackers = Tracker.find([1,2])\r