OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Do not display user in user activity list
Christophe Bliard9132b2ff4762
diff --git a/app/components/activity_item_component.html.erb b/app/components/activity_item_component.html.erbindex 1a035af67a2..ad5fbe70ba6 100644--- a/app/components/activity_item_component.html.erb+++ b/app/components/activity_item_component.html.erb@@ -2,14 +2,14 @@<div class="op-activity-list--item-title"><%= link_to format_activity_title(@event.event_title), @event.event_path %><% if display_belonging_project? -%>- (Project: <%= content_tag('span', link_to(@event.project.name, @event.project), class: 'project') %>)+ (<%= I18n.t('events.title.project', name: content_tag('span', link_to(@event.project.name, @event.project), class: 'project')).html_safe %>)<% end -%></div>- <div class="op-activity-list--item-subtitle">- <%= @journal.initial? ? "created by" : "updated by" %>- <%= avatar(@event.event_author, size: 'mini') %> <span class="spot-caption spot-caption_bold"><%= link_to_user(@event.event_author) %></span>- on <%= format_time(@event.event_datetime.to_time, true) %>- </div>+ <%=+ render(ActivityItemSubtitleComponent.new(user: @display_user && @event.event_author,+ datetime: @event.event_datetime,+ is_creation: @journal.initial?))+ %><% if @event.event_description.present? -%><div class="op-activity-list--item-description"><%= truncate_formatted_text(@event.event_description) %>diff --git a/app/components/activity_item_component.rb b/app/components/activity_item_component.rbindex 141a993db69..e67753b16a7 100644--- a/app/components/activity_item_component.rb+++ b/app/components/activity_item_component.rb@@ -35,10 +35,11 @@ class ActivityItemComponent < ViewComponent::Base:truncate_formatted_text,to: :helpers- def initialize(event:, journal:)+ def initialize(event:, journal:, display_user: true)super()@event = event@journal = journal+ @display_user = display_userenddef display_belonging_project?@@ -48,11 +49,12 @@ class ActivityItemComponent < ViewComponent::Basedef show_details?return false if @journal.initial?- @journal.details.present?+ rendered_details.present?enddef rendered_details- @journal.details+ @rendered_details ||=+ @journal.details.map { |detail| @journal.render_detail(detail) }.compactenddiff --git a/app/components/activity_item_subtitle_component.html.erb b/app/components/activity_item_subtitle_component.html.erbnew file mode 100644index 00000000000..c01dbdfecd1--- /dev/null+++ b/app/components/activity_item_subtitle_component.html.erb@@ -0,0 +1,8 @@+<div class="op-activity-list--item-subtitle">+ <%=+ I18n.t(i18n_key,+ user: user_html,+ datetime: datetime_html+ ).html_safe+ %>+</div>diff --git a/app/components/activity_item_subtitle_component.rb b/app/components/activity_item_subtitle_component.rbnew file mode 100644index 00000000000..d192d2367fc--- /dev/null+++ b/app/components/activity_item_subtitle_component.rb@@ -0,0 +1,59 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class ActivityItemSubtitleComponent < ViewComponent::Base+ def initialize(user:, datetime:, is_creation:)+ super()+ @user = user+ @datetime = datetime+ @is_creation = is_creation+ end++ def user_html+ return unless @user++ [+ helpers.avatar(@user, size: 'mini'),+ helpers.content_tag('span', helpers.link_to_user(@user), class: %w[spot-caption spot-caption_bold])+ ].join(' ')+ end++ def datetime_html+ helpers.format_time(@datetime)+ end++ def i18n_key+ i18n_key = 'activity.item.'.dup+ i18n_key << (@is_creation ? 'created_' : 'updated_')+ i18n_key << 'by_' if @user+ i18n_key << 'on'+ i18n_key+ end+enddiff --git a/app/components/activity_list_component.html.erb b/app/components/activity_list_component.html.erbindex bcc67a5beda..2630161ccbc 100644--- a/app/components/activity_list_component.html.erb+++ b/app/components/activity_list_component.html.erb@@ -1,6 +1,6 @@<ul class="op-activity-list"><% @events.each do |event| -%><% journal = @journals_by_id[event.event_id] -%>- <%= render(ActivityItemComponent.new(event:, journal:)) %>+ <%= render(ActivityItemComponent.new(event:, journal:, display_user: @display_user)) %><% end -%></ul>diff --git a/app/components/activity_list_component.rb b/app/components/activity_list_component.rbindex 2fddd5508a1..e2d41e07860 100644--- a/app/components/activity_list_component.rb+++ b/app/components/activity_list_component.rb@@ -29,9 +29,10 @@#++class ActivityListComponent < ViewComponent::Base- def initialize(events:, journals_by_id:)+ def initialize(events:, journals_by_id:, display_user: true)super()@events = events.sort { |x, y| y.event_datetime <=> x.event_datetime }@journals_by_id = journals_by_id+ @display_user = display_userendenddiff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erbindex 48754937f9b..8f59fd168d4 100644--- a/app/views/users/show.html.erb+++ b/app/views/users/show.html.erb@@ -84,7 +84,7 @@ See COPYRIGHT and LICENSE files for more details.<% @events_by_day.sort_by { |day, _events| day }.reverse_each do |day, events| -%><h4 class="op-activity-days--header"><%= format_activity_day(day) %></h3>- <%= render(ActivityListComponent.new(events:, journals_by_id: @journals_by_id)) %>+ <%= render(ActivityListComponent.new(events:, journals_by_id: @journals_by_id, display_user: false)) %><% end -%></div>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 8fbb699262a..ed4021634e9 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -981,8 +981,11 @@ en:field_erroneous_label: "This field is invalid: %{full_errors}\nPlease enter a valid value."activity:- created: "Created: %{title}"- updated: "Updated: %{title}"+ item:+ created_by_on: "created by %{user} on %{datetime}"+ created_on: "created on %{datetime}"+ updated_by_on: "updated by %{user} on %{datetime}"+ updated_on: "updated on %{datetime}"filter:changeset: "Changesets"message: "Forums"diff --git a/spec/components/activity_item_component_spec.rb b/spec/components/activity_item_component_spec.rbindex bb2c3f15071..763eec37b8f 100644--- a/spec/components/activity_item_component_spec.rb+++ b/spec/components/activity_item_component_spec.rb@@ -42,7 +42,7 @@ RSpec.describe ActivityItemComponent, type: :component do)endlet(:project) { build_stubbed(:project) }- let(:journal) { build_stubbed(:project_journal, journable: project) }+ let(:journal) { build_stubbed(:work_package_journal) }it 'renders the title escaped' doevent.event_title = 'Hello <b>World</b>!'@@ -50,4 +50,11 @@ RSpec.describe ActivityItemComponent, type: :component doexpect(page).to have_css('.op-activity-list--item-title', text: 'Hello <b>World</b>!')end++ it 'renders the project name to which the event belongs, escaped' do+ event.project.name = 'Project <b>name</b> with HTML'+ render_inline(described_class.new(event:, journal:))++ expect(page).to have_css('.op-activity-list--item-title', text: '(Project: Project <b>name</b> with HTML)')+ endenddiff --git a/spec/components/activity_item_subtitle_component_spec.rb b/spec/components/activity_item_subtitle_component_spec.rbnew file mode 100644index 00000000000..0ce1e822e83--- /dev/null+++ b/spec/components/activity_item_subtitle_component_spec.rb@@ -0,0 +1,67 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "rails_helper"++RSpec.describe ActivityItemSubtitleComponent, type: :component do+ include Redmine::I18n++ let(:datetime) { Time.current }++ subject { render_inline(described_class.new(user:, datetime:, is_creation:)) }++ context 'on creation with a user' do+ let(:is_creation) { true }+ let(:user) { build_stubbed(:user) }++ it { is_expected.to have_text("created by #{user.name} on #{format_time(datetime)}") }+ end++ context 'on creation without a user' do+ let(:is_creation) { true }+ let(:user) { nil }++ it { is_expected.to have_text("created on #{format_time(datetime)}") }+ end++ context 'on update with a user' do+ let(:is_creation) { false }+ let(:user) { build_stubbed(:user) }++ it { is_expected.to have_text("updated by #{user.name} on #{format_time(datetime)}") }+ end++ context 'on update without a user' do+ let(:is_creation) { false }+ let(:user) { nil }++ it { is_expected.to have_text("updated on #{format_time(datetime)}") }+ end+end