]> source.dussan.org Git - redmine.git/commitdiff
Display user's groups on profile (#12796).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Mar 2019 11:49:51 +0000 (11:49 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Mar 2019 11:49:51 +0000 (11:49 +0000)
Only for admins or when viewing its own profile.

git-svn-id: http://svn.redmine.org/redmine/trunk@17973 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/views/users/show.html.erb
test/functional/users_controller_test.rb
test/helpers/application_helper_test.rb

index 8ccdf073632c0fe2f8a15b03b348530c8a44a2e5..7174575be17a096ef8c1c98c1d18d5bb0a8cad58 100644 (file)
@@ -65,6 +65,20 @@ module ApplicationHelper
     end
   end
 
+  # Displays a link to edit group page if current user is admin
+  # Otherwise display only the group name
+  def link_to_group(group, options={})
+    if group.is_a?(Group)
+      name = h(group.name)
+      if (User.current.admin?)
+        only_path = options[:only_path].nil? ? true : options[:only_path]
+        link_to name, edit_group_path(group, :only_path => only_path)
+      else
+        name
+      end
+    end
+  end
+
   # Displays a link to +issue+ with its subject.
   # Examples:
   #
index c5c17000b592f651fcae3411ec45807b7b770011..66a2a46a3668bca4f0446c8fd15721c6faeb3265 100644 (file)
 <% end %>
 </ul>
 <% end %>
+
+<% if (User.current == @user || User.current.admin?) && @user.groups.any? %>
+<div id="groups">
+  <h3><%=l(:label_group_plural)%></h3>
+  <ul>
+  <% for group in @user.groups %>
+    <li><%= link_to_group(group) %>
+  <% end %>
+  </ul>
+</div>
+<% end %>
+
 <%= call_hook :view_account_left_bottom, :user => @user %>
 </div>
 
index b43d01214d3cafaaa0a6f77fcac7ee14d8fc363e..4c287cf3d18aaea22b0a1605e1375d41c212b638 100644 (file)
@@ -112,6 +112,9 @@ class UsersControllerTest < Redmine::ControllerTest
     get :show, :params => {:id => 2}
     assert_response :success
     assert_select 'h2', :text => /John Smith/
+
+    # groups block should not be rendeder for users which are not part of any group
+    assert_select 'div#groups', 0
   end
 
   def test_show_should_display_visible_custom_fields
@@ -206,6 +209,18 @@ class UsersControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_show_user_should_list_user_groups
+    @request.session[:user_id] = 1
+    get :show, :params => {:id => 8}
+
+    assert_select 'div#groups', 1 do
+      assert_select 'h3', :text => 'Groups'
+      assert_select 'li', 2
+      assert_select 'a[href=?]', '/groups/10/edit', :text => 'A Team'
+      assert_select 'a[href=?]', '/groups/11/edit', :text => 'B Team'
+    end
+  end
+
   def test_new
     get :new
     assert_response :success
index 2fcbaf7f0a925c2b84961fcd54db324ad4078d73..7b84cdad629c28be71cd5440a970f25a7b89d8d6 100644 (file)
@@ -1536,6 +1536,19 @@ RAW
     end
   end
 
+  def test_link_to_group_should_return_only_group_name_for_non_admin_users
+    User.current = nil
+    group = Group.find(10)
+    assert_equal "A Team", link_to_group(group)
+  end
+
+  def test_link_to_group_should_link_to_group_edit_page_for_admin_users
+    User.current = User.find(1)
+    group = Group.find(10)
+    result = link_to("A Team", "/groups/10/edit")
+    assert_equal result, link_to_group(group)
+  end
+
   def test_link_to_user_should_not_link_to_anonymous
     user = User.anonymous
     assert user.anonymous?