Project

General

Profile

Feature #12795 » 0002-Add-link-from-group-name-to-group-page.patch

Go MAEDA, 2020-11-15 14:13

View differences:

app/helpers/application_helper.rb
49 49

  
50 50
  # Displays a link to user's account page if active
51 51
  def link_to_user(user, options={})
52
    if user.is_a?(User)
53
      name = h(user.name(options[:format]))
54
      if user.active? || (User.current.admin? && user.logged?)
55
        only_path = options[:only_path].nil? ? true : options[:only_path]
56
        link_to name, user_url(user, :only_path => only_path), :class => user.css_classes
57
      else
58
        name
52
    user.is_a?(User) ? link_to_principal(user, options) : h(user.to_s)
53
  end
54

  
55
  # Displays a link to user's account page or group page
56
  def link_to_principal(principal, options={})
57
    only_path = options[:only_path].nil? ? true : options[:only_path]
58
    case principal
59
    when User
60
      name = h(principal.name(options[:format]))
61
      if principal.active? || (User.current.admin? && principal.logged?)
62
        url = user_url(principal, :only_path => only_path)
59 63
      end
64
    when Group
65
      name = h(principal.to_s)
66
      url = group_url(principal, :only_path => only_path)
60 67
    else
61
      h(user.to_s)
68
      name = h(principal.to_s)
62 69
    end
70

  
71
    url ? link_to(name, url, :class => principal.css_classes) : name
63 72
  end
64 73

  
65 74
  # Displays a link to edit group page if current user is admin
app/models/group.rb
50 50
    name.to_s
51 51
  end
52 52

  
53
  def css_classes
54
    'group'
55
  end
56

  
53 57
  def name
54 58
    lastname
55 59
  end
app/views/projects/_members_box.html.erb
2 2
  <div class="members box">
3 3
    <h3 class="icon icon-group"><%=l(:label_member_plural)%></h3>
4 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>
5
      <p><span class="label"><%= role %>:</span> <%= @principals_by_role[role].sort.collect{|p| link_to_principal p}.join(", ").html_safe %></p>
6 6
    <% end %>
7 7
  </div>
8 8
  <% end %>
test/helpers/application_helper_test.rb
1642 1642
    end
1643 1643
  end
1644 1644

  
1645
  def test_link_to_principal_should_link_to_user
1646
    user = User.find(2)
1647
    assert_equal link_to_user(user), link_to_principal(user)
1648
  end
1649

  
1650
  def test_link_to_principal_should_link_to_group
1651
    group = Group.find(10)
1652
    result = link_to('A Team', '/groups/10', :class => 'group')
1653
    assert_equal result, link_to_principal(group)
1654
  end
1655

  
1645 1656
  def test_link_to_group_should_return_only_group_name_for_non_admin_users
1646 1657
    User.current = nil
1647 1658
    group = Group.find(10)
(1-1/4)