Skip to content

Commit 56a7fd2

Browse files
committed
Add link from group name to group page on project overview page (#12795).
Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@21073 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent 482656f commit 56a7fd2

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

app/helpers/application_helper.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,28 @@ def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_fo
5151

5252
# Displays a link to user's account page if active
5353
def link_to_user(user, options={})
54-
if user.is_a?(User)
55-
name = h(user.name(options[:format]))
56-
if user.active? || (User.current.admin? && user.logged?)
57-
only_path = options[:only_path].nil? ? true : options[:only_path]
58-
link_to name, user_url(user, :only_path => only_path), :class => user.css_classes
59-
else
60-
name
54+
user.is_a?(User) ? link_to_principal(user, options) : h(user.to_s)
55+
end
56+
57+
# Displays a link to user's account page or group page
58+
def link_to_principal(principal, options={})
59+
only_path = options[:only_path].nil? ? true : options[:only_path]
60+
case principal
61+
when User
62+
name = h(principal.name(options[:format]))
63+
if principal.active? || (User.current.admin? && principal.logged?)
64+
url = user_url(principal, :only_path => only_path)
65+
css_classes = principal.css_classes
6166
end
67+
when Group
68+
name = h(principal.to_s)
69+
url = group_url(principal, :only_path => only_path)
70+
css_classes = "group icon icon-#{principal.class.name.downcase}"
6271
else
63-
h(user.to_s)
72+
name = h(principal.to_s)
6473
end
74+
75+
url ? link_to(name, url, :class => css_classes) : name
6576
end
6677

6778
# Displays a link to edit group page if current user is admin

app/views/projects/_members_box.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="members box">
33
<h3 class="icon icon-group"><%=l(:label_member_plural)%></h3>
44
<% @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>
5+
<p><span class="label"><%= role %>:</span> <%= @principals_by_role[role].sort.collect{|p| link_to_principal p}.join(", ").html_safe %></p>
66
<% end %>
77
</div>
88
<% end %>

test/helpers/application_helper_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,17 @@ def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
17081708
end
17091709
end
17101710

1711+
def test_link_to_principal_should_link_to_user
1712+
user = User.find(2)
1713+
assert_equal link_to_user(user), link_to_principal(user)
1714+
end
1715+
1716+
def test_link_to_principal_should_link_to_group
1717+
group = Group.find(10)
1718+
result = link_to('A Team', '/groups/10', :class => 'group icon icon-group')
1719+
assert_equal result, link_to_principal(group)
1720+
end
1721+
17111722
def test_link_to_group_should_return_only_group_name_for_non_admin_users
17121723
User.current = nil
17131724
group = Group.find(10)

0 commit comments

Comments
 (0)