Project

General

Profile

Feature #12796 » 0001-Show-user-groups-in-user-profile-page.patch

Marius BĂLTEANU, 2019-03-10 10:24

View differences:

app/helpers/application_helper.rb
63 63
    end
64 64
  end
65 65

  
66
  # Displays a link to edit group page if current user is admin
67
  # Otherwise display only the group name
68
  def link_to_group(group, options={})
69
    if group.is_a?(Group)
70
      name = h(group.name)
71
      if (User.current.admin?)
72
        only_path = options[:only_path].nil? ? true : options[:only_path]
73
        link_to name, edit_group_path(group, :only_path => only_path)
74
      else
75
        name
76
      end
77
    end
78
  end
79

  
66 80
  # Displays a link to +issue+ with its subject.
67 81
  # Examples:
68 82
  #
app/views/users/show.html.erb
84 84
<% end %>
85 85
</ul>
86 86
<% end %>
87

  
88
<% unless @user.groups.empty? %>
89
<div id="groups">
90
  <h3><%=l(:label_group_plural)%></h3>
91
  <ul>
92
  <% for group in @user.groups %>
93
    <li><%= link_to_group(group) %>
94
  <% end %>
95
  </ul>
96
</div>
97
<% end %>
98

  
87 99
<%= call_hook :view_account_left_bottom, :user => @user %>
88 100
</div>
89 101

  
test/functional/users_controller_test.rb
110 110
    get :show, :params => {:id => 2}
111 111
    assert_response :success
112 112
    assert_select 'h2', :text => /John Smith/
113

  
114
    # groups block should not be rendeder for users which are not part of any group
115
    assert_select 'div#groups', 0
113 116
  end
114 117

  
115 118
  def test_show_should_display_visible_custom_fields
......
204 207
    end
205 208
  end
206 209

  
210
  def test_show_user_should_list_user_groups
211
    @request.session[:user_id] = 1
212
    get :show, :params => {:id => 8}
213

  
214
    assert_select 'div#groups', 1 do
215
      assert_select 'h3', :text => 'Groups'
216
      assert_select 'li', 2
217
      assert_select 'a[href=?]', '/groups/10/edit', :text => 'A Team'
218
      assert_select 'a[href=?]', '/groups/11/edit', :text => 'B Team'
219
    end
220
  end
221

  
207 222
  def test_new
208 223
    get :new
209 224
    assert_response :success
test/helpers/application_helper_test.rb
1534 1534
    end
1535 1535
  end
1536 1536

  
1537
  def test_link_to_group_should_return_only_group_name_for_non_admin_users
1538
    group = Group.find(10)
1539
    assert_equal "A Team", link_to_group(group)
1540
  end
1541

  
1542
  def test_link_to_group_should_link_to_group_edit_page_for_admin_users
1543
    group = Group.find(10)
1544
    User.current = User.find(1)
1545
    result = link_to("A Team", "/groups/10/edit")
1546
    assert_equal result, link_to_group(group)
1547
  end
1548

  
1537 1549
  def test_link_to_user_should_not_link_to_anonymous
1538 1550
    user = User.anonymous
1539 1551
    assert user.anonymous?
(1-1/3)