Skip to content

Commit

Permalink
Add cause when changes are written
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Mar 17, 2024
1 parent aa67a9e commit 289e789
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Journal < ApplicationRecord
work_package_children_changed_times
work_package_related_changed_times
working_days_changed
default_attribute_written
system_update
].freeze

Expand Down
9 changes: 9 additions & 0 deletions app/services/work_packages/set_attributes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def set_calculated_attributes(attributes)
update_project_dependent_attributes
reassign_invalid_status_if_type_changed
set_templated_description
set_cause_for_readonly_attributes
end

def derivable_attribute
Expand Down Expand Up @@ -416,4 +417,12 @@ def parent_due_later_than_start?

(due && !start) || ((due && start) && (due > start))
end

def set_cause_for_readonly_attributes
return unless work_package.changes.keys.intersect?(%w(created_at updated_at author))

work_package.journal_cause = {
"type" => "default_attribute_written"
}
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ en:
changes_retracted: "The changes were retracted."

caused_changes:
default_attribute_written: "Read-only attributes written"
dates_changed: "Dates changed"
system_update: "OpenProject system update:"

Expand Down
11 changes: 8 additions & 3 deletions lib/open_project/journal_formatter/cause.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ def render(_key, values, options = { html: true })
private

def cause_type_translation(type)
mapped_type = mapped_cause_type(type)
I18n.t("journals.caused_changes.#{mapped_type}", default: mapped_type)
end

def mapped_cause_type(type)
case type
when 'system_update'
I18n.t("journals.caused_changes.system_update")
when /changed_times/, "working_days_changed"
"dates_changed"
else
I18n.t("journals.caused_changes.dates_changed")
type
end
end

Expand Down

0 comments on commit 289e789

Please sign in to comment.