Skip to content

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

Adds system update cause

Marcello Rochac4202ab602f3
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 5280a0232e0..a2bb7eb39b6 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1499,6 +1499,7 @@ en:
caused_changes:
dates_changed: "Dates changed"
+ system_update: "OpenProject update"
cause_descriptions:
work_package_predecessor_changed_times: by changes to predecessor %{link}
@@ -1514,6 +1515,9 @@ en:
dates:
working: "%{date} is now working"
non_working: "%{date} is now non-working"
+ system_update:
+ file_links_journal: 'added File links to Activities'
+
links:
configuration_guide: 'Configuration guide'
diff --git a/db/migrate/20230731153909_add_file_link_journals_to_existing_containers.rb b/db/migrate/20230731153909_add_file_link_journals_to_existing_containers.rb
index 0de1594e4ec..01a362f9d97 100644
--- a/db/migrate/20230731153909_add_file_link_journals_to_existing_containers.rb
+++ b/db/migrate/20230731153909_add_file_link_journals_to_existing_containers.rb
@@ -36,7 +36,8 @@ class AddFileLinkJournalsToExistingContainers < ActiveRecord::Migration[7.0]
containers.each do |container|
next unless container.class.journaled?
- Journals::CreateService.new(container, system_user).call(notes: "File link activity added by a system update")
+ Journals::CreateService.new(container, system_user)
+ .call(cause: { type: 'system_update', feature: 'file_links_journal' })
end
end
diff --git a/lib/open_project/journal_formatter/cause.rb b/lib/open_project/journal_formatter/cause.rb
index b24a2568ae6..c6f9893915d 100644
--- a/lib/open_project/journal_formatter/cause.rb
+++ b/lib/open_project/journal_formatter/cause.rb
@@ -44,15 +44,19 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
private
- def cause_type_translation(_type)
- # currently only date changes have a cause, but in the future when other changes have a cause,
- # those can be changed here.
-
- I18n.t('journals.caused_changes.dates_changed')
+ def cause_type_translation(type)
+ case type
+ when 'system_update'
+ I18n.t("journals.caused_changes.system_update")
+ else
+ I18n.t("journals.caused_changes.dates_changed")
+ end
end
def cause_description(cause, html)
case cause['type']
+ when 'system_update'
+ system_update_message(cause)
when 'working_days_changed'
working_days_changed_message(cause['changed_days'])
else
@@ -60,6 +64,10 @@ class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
end
end
+ def system_update_message(cause)
+ I18n.t("journals.cause_descriptions.system_update.#{cause['feature']}")
+ end
+
def related_work_package_changed_message(cause, html)
related_work_package = WorkPackage.includes(:project).visible(User.current).find_by(id: cause['work_package_id'])
diff --git a/spec/lib/journal_formatter/cause_spec.rb b/spec/lib/journal_formatter/cause_spec.rb
index f88620f0430..1840a76d194 100644
--- a/spec/lib/journal_formatter/cause_spec.rb
+++ b/spec/lib/journal_formatter/cause_spec.rb
@@ -282,4 +282,31 @@ RSpec.describe OpenProject::JournalFormatter::Cause do
end
end
end
+
+ context 'when the change was caused by a system update' do
+ let(:cause) do
+ {
+ "type" => 'system_update',
+ "feature" => 'file_links_journal'
+ }
+ end
+
+ context 'when rendering HTML variant' do
+ let(:html) { true }
+
+ it do
+ expect(subject).to eq "<strong>#{I18n.t('journals.caused_changes.system_update')}</strong> " \
+ "#{I18n.t('journals.cause_descriptions.system_update.file_links_journal')}"
+ end
+ end
+
+ context 'when rendering raw variant' do
+ let(:html) { false }
+
+ it do
+ expect(subject).to eq "#{I18n.t('journals.caused_changes.system_update')} " \
+ "#{I18n.t('journals.cause_descriptions.system_update.file_links_journal')}"
+ end
+ end
+ end
end