]> source.dussan.org Git - redmine.git/commitdiff
Render mentioned users with leading @ and highlight (#36699, #13919).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sat, 19 Mar 2022 10:00:30 +0000 (10:00 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sat, 19 Mar 2022 10:00:30 +0000 (10:00 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21468 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
public/stylesheets/application.css
test/helpers/application_helper_test.rb
test/unit/mailer_test.rb

index 1d2b09423e9a555255660dfe97bc3d22b18ed154..1dfa26cb26dc4c053bce870ae40cd31c1e297c22 100644 (file)
@@ -60,6 +60,7 @@ module ApplicationHelper
     case principal
     when User
       name = h(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)
@@ -1265,7 +1266,7 @@ module ApplicationHelper
           elsif sep == "@"
             name = remove_double_quotes(identifier)
             u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
-            link = link_to_user(u, :only_path => only_path, :class => 'user-mention') if u
+            link = link_to_user(u, :only_path => only_path, :class => 'user-mention', :mention => true) if u
           end
         end
         (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
index 827017c9a671df24a9f54b271f4477d4b9833b00..6a043ff2fbb3c214eea14a8ff77c420f7760a41c 100644 (file)
@@ -150,6 +150,11 @@ a img{ border: 0; }
 a.issue.closed, a.issue.closed:link, a.issue.closed:visited { color: #999; text-decoration: line-through; }
 a.project.closed, a.project.closed:link, a.project.closed:visited { color: #999; }
 a.user.locked, a.user.locked:link, a.user.locked:visited {color: #999;}
+a.user.user-mention {
+  background-color: #DDEEFF;
+  padding: 0.1em 0.1em;
+  border-radius: 0.1em;
+}
 
 #sidebar a.selected {line-height:1.7em; padding:1px 3px 2px 2px; margin-left:-2px; background-color:#9DB9D5; color:#fff; border-radius:2px;}
 #sidebar a.selected:hover {text-decoration:none;}
index f34daf55a14cf64109995622db44d3b92a94aaaa..452892e8b05b82da7cf322f5a09f6018bead4803 100644 (file)
@@ -562,12 +562,12 @@ class ApplicationHelperTest < Redmine::HelperTest
       'user:jsmith'                 => link_to_user(User.find_by_id(2)),
       'user:JSMITH'                 => link_to_user(User.find_by_id(2)),
       'user#2'                      => link_to_user(User.find_by_id(2)),
-      '@jsmith'                     => link_to_user(User.find_by_id(2), class: 'user-mention'),
-      '@jsmith.'                    => "#{link_to_user(User.find_by_id(2), class: 'user-mention')}.",
-      '@JSMITH'                     => link_to_user(User.find_by_id(2), class: 'user-mention'),
-      '@abcd@example.com'           => link_to_user(User.find_by_id(u_email_id), class: 'user-mention'),
+      '@jsmith'                     => link_to_user(User.find_by_id(2), class: 'user-mention', mention: true),
+      '@jsmith.'                    => "#{link_to_user(User.find_by_id(2), class: 'user-mention', mention: true)}.",
+      '@JSMITH'                     => link_to_user(User.find_by_id(2), class: 'user-mention', mention: true),
+      '@abcd@example.com'           => link_to_user(User.find_by_id(u_email_id), class: 'user-mention', mention: true),
       'user:abcd@example.com'       => link_to_user(User.find_by_id(u_email_id)),
-      '@foo.bar@example.com'        => link_to_user(User.find_by_id(u_email_id_2), class: 'user-mention'),
+      '@foo.bar@example.com'        => link_to_user(User.find_by_id(u_email_id_2), class: 'user-mention', mention: true),
       'user:foo.bar@example.com'    => link_to_user(User.find_by_id(u_email_id_2)),
       # invalid user
       'user:foobar'                 => 'user:foobar',
@@ -596,7 +596,7 @@ class ApplicationHelperTest < Redmine::HelperTest
       # user link format: @jsmith@somenet.foo
       raw = "@jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
       assert_match(
-        %r{<p><a class="user active user-mention".*>#{u.name}</a> should not be parsed in #{html}</p>},
+        %r{<p><a class="user active user-mention".*>@#{u.name}</a> should not be parsed in #{html}</p>},
         textilizable(raw, :project => Project.find(1))
       )
       # user link format: user:jsmith@somenet.foo
@@ -616,7 +616,7 @@ class ApplicationHelperTest < Redmine::HelperTest
       # user link format: @jsmith@somenet.foo
       raw = "@jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
       assert_match(
-        %r{<p><a class=\"user active user-mention\".*>#{u.name}</a> should not be parsed in #{html}</p>},
+        %r{<p><a class=\"user active user-mention\".*>@#{u.name}</a> should not be parsed in #{html}</p>},
         textilizable(raw, :project => Project.find(1))
       )
       # user link format: user:jsmith@somenet.foo
index 3e214b47deb33f48bc06edffcd1b69414f42c964..b82d570bc44ac54179527984563b9e3d5297a5c0 100644 (file)
@@ -195,7 +195,7 @@ class MailerTest < ActiveSupport::TestCase
     issue = Issue.generate!(:description => '@jsmith')
     assert Mailer.deliver_issue_add(issue)
     assert_select_email do
-      assert_select "a[href=?]", "http://localhost:3000/users/2", :text => 'John Smith'
+      assert_select "a[href=?]", "http://localhost:3000/users/2", :text => '@John Smith'
     end
   end