Feature #33174 » feature-33174.patch
app/controllers/projects_controller.rb | ||
---|---|---|
162 | 162 |
return |
163 | 163 |
end |
164 | 164 | |
165 |
@users_by_role = @project.users_by_role
|
|
165 |
@principals_by_role = @project.principals_by_role
|
|
166 | 166 |
@subprojects = @project.children.visible.to_a |
167 | 167 |
@news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").to_a |
168 | 168 |
@trackers = @project.rolled_up_trackers.visible |
app/models/project.rb | ||
---|---|---|
507 | 507 |
end |
508 | 508 |
end |
509 | 509 | |
510 |
# Returns a hash of project users grouped by role |
|
511 |
def users_by_role
|
|
512 |
members.includes(:user, :roles).inject({}) do |h, m|
|
|
510 |
# Returns a hash of project users/groups grouped by role
|
|
511 |
def principals_by_role
|
|
512 |
memberships.includes(:principal, :roles).inject({}) do |h, m|
|
|
513 | 513 |
m.roles.each do |r| |
514 | 514 |
h[r] ||= [] |
515 |
h[r] << m.user
|
|
515 |
h[r] << m.principal
|
|
516 | 516 |
end |
517 | 517 |
h |
518 | 518 |
end |
app/views/projects/_members_box.html.erb | ||
---|---|---|
1 |
<% if @users_by_role.any? %>
|
|
1 |
<% if @principals_by_role.any? %>
|
|
2 | 2 |
<div class="members box"> |
3 | 3 |
<h3 class="icon icon-group"><%=l(:label_member_plural)%></h3> |
4 |
<% @users_by_role.keys.sort.each do |role| %>
|
|
5 |
<p><span class="label"><%= role %>:</span> <%= @users_by_role[role].sort.collect{|u| link_to_user u}.join(", ").html_safe %></p>
|
|
4 |
<% @principals_by_role.keys.sort.each do |role| %>
|
|
5 |
<p><span class="label"><%= role %>:</span> <%= @principals_by_role[role].sort.collect{|p| link_to_user p}.join(", ").html_safe %></p>
|
|
6 | 6 |
<% end %> |
7 | 7 |
</div> |
8 | 8 |
<% end %> |
test/unit/project_test.rb | ||
---|---|---|
455 | 455 |
assert Project.find(3).allowed_parents.include?(nil) |
456 | 456 |
end |
457 | 457 | |
458 |
def test_users_by_role |
|
459 |
users_by_role = Project.find(1).users_by_role |
|
460 |
assert_kind_of Hash, users_by_role |
|
458 |
def test_principals_by_role |
|
459 |
group = Group.find(10) |
|
460 |
Member.create!(:principal => group, :project_id => 1, :role_ids => [1]) |
|
461 | ||
462 |
principals_by_role = Project.find(1).principals_by_role |
|
463 |
assert_kind_of Hash, principals_by_role |
|
461 | 464 |
role = Role.find(1) |
462 |
assert_kind_of Array, users_by_role[role] |
|
463 |
assert users_by_role[role].include?(User.find(2)) |
|
465 |
assert_kind_of Array, principals_by_role[role] |
|
466 |
assert principals_by_role[role].include?(User.find(2)) |
|
467 |
assert principals_by_role[role].include?(group) |
|
464 | 468 |
end |
465 | 469 | |
466 | 470 |
def test_rolled_up_trackers |