Display all users roles on project overview (#3339).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2734 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3df4df3438
commit
da2854cf75
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -35,13 +35,11 @@
|
|||
</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 %>
|
||||
|
|
|
@ -186,6 +186,14 @@ class ProjectTest < Test::Unit::TestCase
|
|||
assert_equal [5, 6, 3, 4], d.collect(&:id)
|
||||
end
|
||||
|
||||
def test_users_by_role
|
||||
users_by_role = Project.find(1).users_by_role
|
||||
assert_kind_of Hash, users_by_role
|
||||
role = Role.find(1)
|
||||
assert_kind_of Array, users_by_role[role]
|
||||
assert users_by_role[role].include?(User.find(2))
|
||||
end
|
||||
|
||||
def test_rolled_up_trackers
|
||||
parent = Project.find(1)
|
||||
parent.trackers = Tracker.find([1,2])
|
||||
|
|
Loading…
Reference in New Issue