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
: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
</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 %>
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