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
display retracted message on empty journals
ulfertsa6e87c9dcb26
diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rbindex d8add51f01e..90279cd3122 100644--- a/app/models/journal/aggregated_journal.rb+++ b/app/models/journal/aggregated_journal.rb@@ -1,4 +1,5 @@#-- encoding: UTF-8+#-- copyright# OpenProject is an open source project management software.# Copyright (C) 2012-2020 the OpenProject GmbHdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 160b0dae117..a61457cd4f5 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1196,6 +1196,9 @@ en:forums: "Community forum"newsletter: "Security alerts / Newsletter"+ journals:+ changes_retracted: "The changes where retracted."+links:configuration_guide: 'Configuration guide'@@ -2681,6 +2684,7 @@ en:query_menu_item_for: "Menu item for query \"%{title}\""+ # TODO: merge with work_packages top level keywork_package:updated_automatically_by_child_changes: |_Updated automatically by changing values within child work package %{child}_diff --git a/lib/api/v3/activities/activity_representer.rb b/lib/api/v3/activities/activity_representer.rbindex e24d590c128..c82e69b53c4 100644--- a/lib/api/v3/activities/activity_representer.rb+++ b/lib/api/v3/activities/activity_representer.rb@@ -68,7 +68,18 @@ module APIrender_nil: trueformattable_property :notes,- as: :comment+ as: :comment,+ getter: ->(*) {+ text = if empty?+ "_#{I18n.t(:'journals.changes_retracted')}_"+ else+ represented.notes+ end++ ::API::Decorators::Formattable.new(text,+ object: represented,+ plain: false)+ }property :details,exec_context: :decorator,@@ -80,15 +91,16 @@ module APIformattables.map { |d| { format: 'custom', raw: d[0], html: d[1] } }},render_nil: true+property :version, render_nil: truedate_time_property :created_atdef _type- if represented.notes.blank?- 'Activity'- else+ if empty? || represented.notes.present?'Activity::Comment'+ else+ 'Activity'endend@@ -105,6 +117,10 @@ module APIdef render_details(journal, no_html: false)journal.details.map { |d| journal.render_detail(d, no_html: no_html) }end++ def empty?+ represented.get_changes.empty? && represented.notes.empty?+ endendendenddiff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rbindex 4dc9e4649a3..3ec5e0da077 100644--- a/spec/factories/journal_factory.rb+++ b/spec/factories/journal_factory.rb@@ -30,12 +30,16 @@ FactoryBot.define dofactory :journal douser factory: :usercreated_at { Time.now }- sequence(:version) do |n| n + 1 end+ sequence(:version) { |n| n + 1 }factory :work_package_journal, class: Journal dojournable_type { 'WorkPackage' }activity_type { 'work_packages' }data { FactoryBot.build(:journal_work_package_journal) }++ callback(:after_stub) do |journal, options|+ journal.journable ||= options.journable || FactoryBot.build_stubbed(:work_package)+ endendfactory :wiki_content_journal, class: Journal dodiff --git a/spec/lib/api/v3/activities/activity_representer_spec.rb b/spec/lib/api/v3/activities/activity_representer_spec.rbindex 6d83cab9a61..c3e3099cee9 100644--- a/spec/lib/api/v3/activities/activity_representer_spec.rb+++ b/spec/lib/api/v3/activities/activity_representer_spec.rb@@ -29,69 +29,114 @@require 'spec_helper'describe ::API::V3::Activities::ActivityRepresenter do- let(:current_user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) }- let(:work_package) { FactoryBot.build(:work_package) }- let(:journal) { Journal::AggregatedJournal.aggregated_journals.first }- let(:project) { work_package.project }- let(:permissions) { %i(edit_own_work_package_notes) }- let(:role) { FactoryBot.create :role, permissions: permissions }+ let(:current_user) do+ FactoryBot.build_stubbed(:user).tap do |u|+ allow(u)+ .to receive(:allowed_to?) do |checked_permission, project|+ project == work_package.project && permissions.include?(checked_permission)+ end+ end+ end+ let(:other_user) { FactoryBot.build_stubbed(:user) }+ let(:work_package) { journal.journable }+ let(:notes) { "My notes" }+ let(:journal) do+ FactoryBot.build_stubbed(:work_package_journal, notes: notes).tap do |journal|+ allow(journal)+ .to receive(:notes_id)+ .and_return(journal.id)+ allow(journal)+ .to receive(:get_changes)+ .and_return(changes)+ end+ end+ let(:changes) { { subject: ["first subject", "second subject"] } }+ let(:aggregated_journal) do+ Journal::AggregatedJournal.new(journal)+ end+ let(:permissions) { %i(edit_work_package_notes) }let(:representer) { described_class.new(journal, current_user: current_user) }before do- allow(User).to receive(:current).and_return(current_user)- work_package.save!+ login_as(current_user)endcontext 'generation' dosubject(:generated) { representer.to_json }- it { is_expected.to include_json('Activity'.to_json).at_path('_type') }+ describe 'type' do+ it { is_expected.to be_json_eql('Activity::Comment'.to_json).at_path('_type') }++ context 'if notes are empty' do+ let(:notes) { '' }++ it { is_expected.to be_json_eql('Activity'.to_json).at_path('_type') }+ end++ context 'if notes and changes are empty' do+ let(:notes) { '' }+ let(:changes) { {} }++ it { is_expected.to be_json_eql('Activity::Comment'.to_json).at_path('_type') }+ end+ endit { is_expected.to have_json_type(Object).at_path('_links') }it 'should link to self' doexpect(subject).to have_json_path('_links/self/href')end- describe 'activity' do- it { is_expected.to have_json_path('id') }- it { is_expected.to have_json_path('version') }+ it { is_expected.to have_json_path('id') }+ it { is_expected.to have_json_path('version') }- it_behaves_like 'has UTC ISO 8601 date and time' do- let(:date) { journal.created_at }- let(:json_path) { 'createdAt' }- end+ it_behaves_like 'has UTC ISO 8601 date and time' do+ let(:date) { journal.created_at }+ let(:json_path) { 'createdAt' }+ end+ describe 'comment' doit_behaves_like 'API V3 formattable', 'comment' dolet(:format) { 'markdown' }let(:raw) { journal.notes }- let(:html) { "#{journal.notes}" }+ let(:html) { "<p>#{journal.notes}</p>" }end- describe 'details' do- it { is_expected.to have_json_path('details') }+ context 'if having no change and notes' do+ let(:notes) { "" }+ let(:changes) { {} }- it { is_expected.to have_json_size(journal.details.count).at_path('details') }-- it 'should render all details as formattable' do- (0..journal.details.count - 1).each do |x|- is_expected.to be_json_eql('custom'.to_json).at_path("details/#{x}/format")- is_expected.to have_json_path("details/#{x}/raw")- is_expected.to have_json_path("details/#{x}/html")- end+ it_behaves_like 'API V3 formattable', 'comment' do+ let(:format) { 'markdown' }+ let(:raw) { "_#{I18n.t(:'journals.changes_retracted')}_" }+ let(:html) { "<p><em>#{I18n.t(:'journals.changes_retracted')}</em></p>" }endend+ end- it 'should link to work package' do- expect(subject).to have_json_path('_links/workPackage/href')- end+ describe 'details' do+ it { is_expected.to have_json_path('details') }- it 'should link to user' do- expect(subject).to have_json_path('_links/user/href')- end+ it { is_expected.to have_json_size(journal.details.count).at_path('details') }- it 'should link to update' do- expect(subject).to have_json_path('_links/update/href')+ it 'should render all details as formattable' do+ (0..journal.details.count - 1).each do |x|+ is_expected.to be_json_eql('custom'.to_json).at_path("details/#{x}/format")+ is_expected.to have_json_path("details/#{x}/raw")+ is_expected.to have_json_path("details/#{x}/html")+ endendend++ it 'should link to work package' do+ expect(subject).to have_json_path('_links/workPackage/href')+ end++ it 'should link to user' do+ expect(subject).to have_json_path('_links/user/href')+ end++ it 'should link to update' do+ expect(subject).to have_json_path('_links/update/href')+ endendend