From 6d0eba75e92898c8308a8ed0892d49bd515c45b3 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 15:31:46 +0000 Subject: [PATCH] @principal_icon@ method should accept a Principal as argument (#23980). git-svn-id: https://svn.redmine.org/redmine/trunk@23230 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 4 ++-- app/helpers/icons_helper.rb | 5 ++++- app/views/projects/settings/_members.html.erb | 2 +- test/helpers/application_helper_test.rb | 2 +- test/helpers/icons_helper_test.rb | 6 ++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 806d59da1..bac8da266 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -76,7 +76,7 @@ module ApplicationHelper end css_classes += " #{options[:class]}" if css_classes && options[:class].present? - url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : h(name) + url ? link_to(principal_icon(principal).to_s + name, url, :class => css_classes) : h(name) end # Displays a link to edit group page if current user is admin @@ -657,7 +657,7 @@ module ApplicationHelper check_box_tag(name, principal.id, false, :id => nil) + (avatar(principal, :size => 16).presence || content_tag( - 'span', principal_icon(principal.class.name.downcase), + 'span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}" ) ) + principal.to_s diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index f423a2898..99006308e 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -45,7 +45,10 @@ module IconsHelper end end - def principal_icon(principal_class, **options) + def principal_icon(principal, **options) + raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal) + + principal_class = principal.class.name.downcase sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class) end diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb index bd953d247..6e13808b6 100644 --- a/app/views/projects/settings/_members.html.erb +++ b/app/views/projects/settings/_members.html.erb @@ -20,7 +20,7 @@ <% next if member.new_record? %> - <%= principal_icon(member.principal.class.name.downcase) %> + <%= principal_icon(member.principal) %> <%= link_to_user member.principal %> diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index c7e79cb66..3ffa24281 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -2027,7 +2027,7 @@ class ApplicationHelperTest < Redmine::HelperTest tags = principals_check_box_tags(name, principals) principals.each_with_index do |principal, i| assert_not_include avatar_tags[i], tags - assert_include content_tag('span', principal_icon(principal.class.name.downcase), :class => "name icon icon-#{principal.class.name.downcase}"), tags + assert_include content_tag('span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}"), tags end end end diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb index 688c6dbac..ab3e743fd 100644 --- a/test/helpers/icons_helper_test.rb +++ b/test/helpers/icons_helper_test.rb @@ -22,6 +22,8 @@ require_relative '../test_helper' class IconsHelperTest < Redmine::HelperTest include IconsHelper + fixtures :users + def test_sprite_icon_should_return_svg_with_defaults expected = %r{$} icon = sprite_icon('edit') @@ -98,8 +100,8 @@ class IconsHelperTest < Redmine::HelperTest def test_principal_icon_should_return_group_icon_for_group_classes expected = %r{} - %w(groupanonymous groupnonmember group).each do |principal_class| - assert_match expected, principal_icon(principal_class) + [Principal.find(12), Principal.find(13), Principal.find(10)].each do |principal| + assert_match expected, principal_icon(principal) end end -- 2.39.5