From f26f9c279dc28652d1204a0fbd6bd9a1ed505491 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 15:36:46 +0000 Subject: [PATCH] Merged r23227 - r23231 from trunk to 6.0-stable (#23980). git-svn-id: https://svn.redmine.org/redmine/branches/6.0-stable@23232 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/assets/images/icons.svg | 4 ++++ app/helpers/application_helper.rb | 12 ++++++------ app/helpers/icons_helper.rb | 17 ++++++++++------- app/views/projects/settings/_members.html.erb | 2 +- config/icon_source.yml | 2 ++ test/helpers/application_helper_test.rb | 6 +++--- test/helpers/icons_helper_test.rb | 6 ++++-- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/assets/images/icons.svg b/app/assets/images/icons.svg index c94249ba8..84d68904a 100644 --- a/app/assets/images/icons.svg +++ b/app/assets/images/icons.svg @@ -247,6 +247,10 @@ + + + + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4a02d8376..bac8da266 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,23 +60,23 @@ module ApplicationHelper only_path = options[:only_path].nil? ? true : options[:only_path] case principal when User - name = h(principal.name(options[:format])) - name = "@".html_safe + name if options[:mention] + name = principal.name(options[:format]) + name = "@#{name}" if options[:mention] css_classes = '' if principal.active? || (User.current.admin? && principal.logged?) url = user_url(principal, :only_path => only_path) css_classes += principal.css_classes end when Group - name = h(principal.to_s) + name = principal.to_s url = group_url(principal, :only_path => only_path) css_classes = principal.css_classes else - name = h(principal.to_s) + name = principal.to_s 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) : 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 5654f3a2f..99006308e 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -36,20 +36,23 @@ module IconsHelper end end - def file_icon(entry, name, size: DEFAULT_ICON_SIZE, css_class: nil) + def file_icon(entry, name, **options) if entry.is_dir? - sprite_icon("folder", name, size: size, css_class: css_class) + sprite_icon("folder", name, **options) else icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(name)) - sprite_icon(icon_name, name, size: size, css_class: css_class) + sprite_icon(icon_name, name, **options) end end - def principal_icon(principal_class, size: DEFAULT_ICON_SIZE, css_class: nil) - sprite_icon('group', size: size, css_class: css_class) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class) + 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 - def activity_event_type_icon(event_type, size: DEFAULT_ICON_SIZE, css_class: nil) + def activity_event_type_icon(event_type, **options) icon_name = case event_type when 'reply' 'comments' @@ -61,7 +64,7 @@ module IconsHelper event_type end - sprite_icon(icon_name, size: size, css_class: css_class) + sprite_icon(icon_name, **options) end private 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/config/icon_source.yml b/config/icon_source.yml index 05d024718..a97b4bcb9 100644 --- a/config/icon_source.yml +++ b/config/icon_source.yml @@ -195,3 +195,5 @@ svg: chevrons-right - name: chevrons-left svg: chevrons-left +- name: key + svg: key diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index a2c4ac82f..3ffa24281 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1868,8 +1868,8 @@ class ApplicationHelperTest < Redmine::HelperTest def test_link_to_principal_should_link_to_group group = Group.find(10) - result = link_to('A Team', '/groups/10', :class => 'group') - assert_equal result, link_to_principal(group) + result = %r{A Team} + assert_match result, link_to_principal(group) end def test_link_to_principal_should_return_string_representation_for_unknown_type_principal @@ -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