diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2024-11-10 15:31:46 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2024-11-10 15:31:46 +0000 |
commit | 6d0eba75e92898c8308a8ed0892d49bd515c45b3 (patch) | |
tree | e85b94013ad6234fa3b70f1eb2210471b0116ff4 | |
parent | 1af81684260f68c958a04df8adcd4d13b11f143f (diff) | |
download | redmine-6d0eba75e92898c8308a8ed0892d49bd515c45b3.tar.gz redmine-6d0eba75e92898c8308a8ed0892d49bd515c45b3.zip |
@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
-rw-r--r-- | app/helpers/application_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/icons_helper.rb | 5 | ||||
-rw-r--r-- | app/views/projects/settings/_members.html.erb | 2 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 2 | ||||
-rw-r--r-- | 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? %> <tr id="member-<%= member.id %>" class="member"> <td class="name icon icon-<%= member.principal.class.name.downcase %>"> - <%= principal_icon(member.principal.class.name.downcase) %> + <%= principal_icon(member.principal) %> <%= link_to_user member.principal %> </td> <td class="roles"> 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{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--edit"></use></svg>$} 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{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--group"></use></svg>} - %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 |