From ee710f5e572ab2e6725f4ea443ec2b6f4fded48b Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Thu, 7 Mar 2019 22:23:08 +0000 Subject: [PATCH] Show user groups in user profile page --- app/helpers/application_helper.rb | 14 ++++++++++++++ app/views/users/show.html.erb | 12 ++++++++++++ test/functional/users_controller_test.rb | 15 +++++++++++++++ test/helpers/application_helper_test.rb | 12 ++++++++++++ 4 files changed, 53 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8fa56ac..005c5f5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -63,6 +63,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: # diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 488e4b9..7d2d0e5 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -84,6 +84,18 @@ <% end %> <% end %> + +<% unless @user.groups.empty? %> +
+

<%=l(:label_group_plural)%>

+ +
+<% end %> + <%= call_hook :view_account_left_bottom, :user => @user %> diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 1160ec7..5626037 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -110,6 +110,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 @@ -204,6 +207,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 diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index bfefc10..60f764c 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1534,6 +1534,18 @@ RAW end end + def test_link_to_group_should_return_only_group_name_for_non_admin_users + 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 + group = Group.find(10) + User.current = User.find(1) + 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? -- 2.1.4