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

Display message and fix relations

Klaus Zanders4e6810a07deb
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 2015cc923f7..d6c81deb4ef 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -58,8 +58,8 @@ class Journal < ApplicationRecord
store_accessor :cause, %i[type work_package_id changed_days], prefix: true
VALID_CAUSE_TYPES = %w[
work_package_predecessor_changed_times
- work_package_successor_changed_times
work_package_parent_changed_times
+ work_package_children_changed_times
working_days_changed
].freeze
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rb
index 5848f66816e..1353891fe1d 100644
--- a/app/services/work_packages/set_schedule_service.rb
+++ b/app/services/work_packages/set_schedule_service.rb
@@ -124,7 +124,7 @@ class WorkPackages::SetScheduleService
# descendants
def reschedule_by_descendants(scheduled, dependency)
set_dates(scheduled, dependency.start_date, dependency.due_date)
- assign_cause_for_journaling(scheduled, :predecessor)
+ assign_cause_for_journaling(scheduled, :children)
end
# Calculates the dates of a work package based on its follows relations.
@@ -150,7 +150,7 @@ class WorkPackages::SetScheduleService
new_start_date = [scheduled.start_date, dependency.soonest_start_date].compact.max
new_due_date = determine_due_date(scheduled, new_start_date)
set_dates(scheduled, new_start_date, new_due_date)
- assign_cause_for_journaling(scheduled, :successor)
+ assign_cause_for_journaling(scheduled, :predecessor)
end
def determine_due_date(work_package, start_date)
@@ -192,7 +192,7 @@ class WorkPackages::SetScheduleService
def assign_cause_initiated_by_work_package(work_package, relation)
type_mapping = {
parent: 'work_package_parent_changed_times',
- successor: 'work_package_successor_changed_times',
+ children: 'work_package_children_changed_times',
predecessor: 'work_package_predecessor_changed_times'
}
diff --git a/app/services/work_packages/update_service.rb b/app/services/work_packages/update_service.rb
index e361a08528f..f4f240de98c 100644
--- a/app/services/work_packages/update_service.rb
+++ b/app/services/work_packages/update_service.rb
@@ -34,7 +34,7 @@ class WorkPackages::UpdateService < BaseServices::Update
def initialize(user:, model:, contract_class: nil, contract_options: {}, cause_of_update: nil)
super(user:, model:, contract_class:, contract_options:)
- self.cause_of_update = cause_of_update || self
+ self.cause_of_update = cause_of_update || model
end
private
@@ -127,6 +127,7 @@ class WorkPackages::UpdateService < BaseServices::Update
end
def reschedule(work_package, work_packages)
+ puts "*" * 200, cause_of_update, "#" * 200
WorkPackages::SetScheduleService
.new(user:, work_package: work_packages, initiated_by: cause_of_update)
.call(work_package.saved_changes.keys.map(&:to_sym))
diff --git a/config/locales/en.yml b/config/locales/en.yml
index afbab364dfe..d3734475298 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1475,6 +1475,23 @@ en:
journals:
changes_retracted: "The changes were retracted."
+ caused_changes:
+ dates_changed: "Dates changed"
+
+ cause_descriptions:
+ work_package_predecessor_changed_times: by changes to predecessor %{link}
+ work_package_parent_changed_times: by changes to parent %{link}
+ work_package_children_changed_times: by changes to child %{link}
+ unaccessable_work_package_changed: by changes to a related work package
+ working_days_changed:
+ changed: "by changes to working days (%{changes})."
+ days:
+ working: "%{day} is now working"
+ non_working: "%{day} is now non-working"
+ dates:
+ working: "%{date} is now working"
+ non_working: "%{date} is now non-working"
+
links:
configuration_guide: 'Configuration guide'
get_in_touch: "You have questions? Get in touch with us."
diff --git a/lib/open_project/journal_formatter/cause.rb b/lib/open_project/journal_formatter/cause.rb
index d11b17ad775..0a6c528ade4 100644
--- a/lib/open_project/journal_formatter/cause.rb
+++ b/lib/open_project/journal_formatter/cause.rb
@@ -28,10 +28,71 @@
class OpenProject::JournalFormatter::Cause < JournalFormatter::Base
include ApplicationHelper
+ include WorkPackagesHelper
include OpenProject::StaticRouting::UrlHelpers
include OpenProject::ObjectLinking
def render(_key, values, _options = { html: true })
- content_tag(:pre, values.last)
+ cause = values.last
+
+ "#{content_tag(:strong, cause_type_translation(cause['type']))} #{cause_description(cause)}"
+ end
+
+ 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')
+ end
+
+ def cause_description(cause)
+ case cause['type']
+ when 'working_days_changed'
+ working_days_changed_message(cause['changed_days'])
+ else
+ related_work_package_changed_message(cause)
+ end
+ end
+
+ def related_work_package_changed_message(cause)
+ related_work_package = nil # WorkPackage.includes(:project).visible(User.current).find_by(id: cause['work_package_id'])
+
+ if related_work_package
+ I18n.t(
+ "journals.cause_descriptions.#{cause['type']}",
+ link: link_to_work_package(related_work_package)
+ )
+
+ else
+ I18n.t('journals.cause_descriptions.unaccessable_work_package_changed')
+ end
+ end
+
+ def working_days_changed_message(changed_dates)
+ day_changes_messages = changed_dates['working_days'].collect do |day, working|
+ working_day_change_message(day, working)
+ end
+ date_changes_messages = changed_dates['non_working_days'].collect do |date, working|
+ working_date_change_message(date, working)
+ end
+ I18n.t('journals.cause_descriptions.working_days_changed.changed',
+ changes: (day_changes_messages + date_changes_messages).join(', '))
+ end
+
+ def working_day_change_message(day, working)
+ I18n.t("journals.cause_descriptions.working_days_changed.days.#{working ? :working : :non_working}",
+ day: WeekDay.find_by!(day:).name)
+ end
+
+ def working_date_change_message(date, working)
+ I18n.t("journals.cause_descriptions.working_days_changed.dates.#{working ? :working : :non_working}", date:)
+ end
+
+ # we need to tell the url_helper that there is not controller to get url_options
+ # so that we can later call link_to
+ def controller
+ nil
end
end