From 0a43e958a63642d2ece8d7aa1079008651ef26dd Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 5 Jul 2020 16:19:45 +0900 Subject: [PATCH] Show badges that indicate author or assignee in issue journal, news comments, and forum replies --- app/helpers/application_helper.rb | 2 +- app/helpers/journals_helper.rb | 15 ++++++++++++ app/helpers/messages_helper.rb | 9 +++++++ app/helpers/news_helper.rb | 9 +++++++ app/helpers/wiki_helper.rb | 2 +- app/views/issues/tabs/_history.html.erb | 2 +- app/views/messages/show.html.erb | 2 +- app/views/news/show.html.erb | 2 +- config/locales/en.yml | 5 ++-- public/stylesheets/application.css | 9 +++++++ test/helpers/journals_helper_test.rb | 16 +++++++++++++ test/helpers/messages_helper_test.rb | 31 +++++++++++++++++++++++++ test/helpers/news_helper_test.rb | 31 +++++++++++++++++++++++++ 13 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 test/helpers/messages_helper_test.rb create mode 100644 test/helpers/news_helper_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 28186124a..36ac26cfc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -642,7 +642,7 @@ module ApplicationHelper end def authoring(created, author, options={}) - l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe + l(options[:label] || :label_added_time_by, :author => link_to_user(author), :badge => options[:badge], :age => time_tag(created)).html_safe end def time_tag(time) diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index d947f8233..e752c970e 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -68,4 +68,19 @@ module JournalsHelper css_classes = journal.private_notes? ? 'badge badge-private private' : '' content_tag('span', content.html_safe, :id => "journal-#{journal.id}-private_notes", :class => css_classes) end + + def journal_user_badge(journal) + issue = journal&.journalized + return '' if issue.nil? + + # Show only "Author" badge if the user is both an author and an assignee + case journal.user + when issue.author + content_tag('span', l(:label_author), class: 'badge badge-user-author') + when issue.assigned_to + content_tag('span', l(:field_assigned_to), class: 'badge badge-user-assignee') + else + '' + end + end end diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index 51824a334..a1224d964 100644 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -18,4 +18,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module MessagesHelper + def message_user_badge(message) + return '' if message&.parent.nil? + + if message.parent.author == message.author + content_tag('span', l(:label_author), class: 'badge badge-user-author') + else + '' + end + end end diff --git a/app/helpers/news_helper.rb b/app/helpers/news_helper.rb index f807f9cc8..fc5500d6d 100644 --- a/app/helpers/news_helper.rb +++ b/app/helpers/news_helper.rb @@ -18,4 +18,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module NewsHelper + def news_comment_user_badge(comment) + return '' if comment&.commented.nil? + + if comment.commented.author == comment.author + content_tag('span', l(:label_author), class: 'badge badge-user-author') + else + '' + end + end end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 6690b04fc..d0a29a32c 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -66,6 +66,6 @@ module WikiHelper end def wiki_content_update_info(content) - l(:label_updated_time_by, :author => link_to_user(content.author), :age => time_tag(content.updated_on)).html_safe + l(:label_updated_time_by, :author => link_to_user(content.author), :age => time_tag(content.updated_on), :badge => '').html_safe end end diff --git a/app/views/issues/tabs/_history.html.erb b/app/views/issues/tabs/_history.html.erb index 0769f5725..1895bdb16 100644 --- a/app/views/issues/tabs/_history.html.erb +++ b/app/views/issues/tabs/_history.html.erb @@ -13,7 +13,7 @@

<%= avatar(journal.user) %> - <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %> + <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by, :badge => journal_user_badge(journal) %> <%= render_private_notes_indicator(journal) %>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index b8abf0321..aab5523ef 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -69,7 +69,7 @@ <%= avatar(message.author) %> <%= link_to message.subject, { :controller => 'messages', :action => 'show', :board_id => @board, :id => @topic, :r => message, :anchor => "message-#{message.id}" } %> - - <%= authoring message.created_on, message.author %> + <%= authoring message.created_on, message.author, :badge => message_user_badge(message) %>
<%= textilizable message, :content, :attachments => message.attachments %>
<%= link_to_attachments message, :author => false, :thumbnails => true %> diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 04ea54a0a..931d94486 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -42,7 +42,7 @@ :title => l(:button_delete), :class => 'icon-only icon-del' %> -

<%= avatar(comment.author) %><%= authoring comment.created_on, comment.author %>

+

<%= avatar(comment.author) %><%= authoring comment.created_on, comment.author, :badge => news_comment_user_badge(comment) %>

<%= textilizable(comment.comments) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index c3f4925cd..b498cc655 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -895,8 +895,8 @@ en: label_missing_feeds_access_key: Missing a Atom access key label_feeds_access_key_created_on: "Atom access key created %{value} ago" label_module_plural: Modules - label_added_time_by: "Added by %{author} %{age} ago" - label_updated_time_by: "Updated by %{author} %{age} ago" + label_added_time_by: "Added by %{author} %{badge} %{age} ago" + label_updated_time_by: "Updated by %{author} %{badge} %{age} ago" label_updated_time: "Updated %{value} ago" label_jump_to_a_project: Jump to a project... label_file_plural: Files @@ -1089,6 +1089,7 @@ en: label_display_type_board: Board label_my_bookmarks: My bookmarks label_assign_to_me: Assign to me + label_author: Author button_login: Login button_submit: Submit diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 4747681f9..29a0af1a0 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1446,6 +1446,15 @@ td.gantt_selected_column .gantt_hdr,.gantt_selected_column_container { color: #1D781D; border: 1px solid #1D781D; } +.badge-user-author { + color: #205D86; + border: 1px solid #205D86; +} +.badge-user-assignee { + color: #205D86; + border: 1px solid #205D86; +} + /***** Tooltips *****/ .ui-tooltip { background: #000; diff --git a/test/helpers/journals_helper_test.rb b/test/helpers/journals_helper_test.rb index a3475c6ab..d2d933e97 100644 --- a/test/helpers/journals_helper_test.rb +++ b/test/helpers/journals_helper_test.rb @@ -49,4 +49,20 @@ class JournalsHelperTest < Redmine::HelperTest assert_kind_of Attachment, thumbnails.first assert_equal 'image.png', thumbnails.first.filename end + + def test_journal_user_badge + issue = Issue.generate!(:author_id => 1, :assigned_to_id => 2) + + journal = issue.init_journal(User.find(1), "Updated by an author") + assert_equal 'Author', journal_user_badge(journal) + + issue.clear_journal + journal = issue.init_journal(User.find(2), "Updated by an assignee") + assert_equal 'Assignee', journal_user_badge(journal) + + issue.clear_journal + issue.update_attribute(:assigned_to_id, 1) + journal = issue.init_journal(User.find(1), "The user is both an author and an assignee") + assert_equal 'Author', journal_user_badge(journal) + end end diff --git a/test/helpers/messages_helper_test.rb b/test/helpers/messages_helper_test.rb new file mode 100644 index 000000000..f05fe755d --- /dev/null +++ b/test/helpers/messages_helper_test.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2020 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class MessagesHelperTest < Redmine::HelperTest + include MessagesHelper + + fixtures :messages, :users + + def test_message_user_badge + assert_equal 'Author', message_user_badge(messages(:messages_002)) + assert_empty message_user_badge(messages(:messages_001)) + end +end diff --git a/test/helpers/news_helper_test.rb b/test/helpers/news_helper_test.rb new file mode 100644 index 000000000..7617770cd --- /dev/null +++ b/test/helpers/news_helper_test.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2020 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class NewsHelperTest < Redmine::HelperTest + include NewsHelper + + fixtures :news, :comments, :users + + def test_news_comment_user_badge + assert_equal 'Author', news_comment_user_badge(comments(:comments_002)) + assert_empty news_comment_user_badge(comments(:comments_001)) + end +end -- 2.26.2