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

[#36129] Changing position in backlog creates activity of custom field removal that didn\'t happen

Andreas Pfohldeaf67af0556
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rb
index 1b96e44e885..3ad742f82f8 100644
--- a/app/services/journals/create_service.rb
+++ b/app/services/journals/create_service.rb
@@ -308,6 +308,10 @@ module Journals
journable_id: journable.id)
end
+ def journable_class_name
+ journable.class.base_class.name
+ end
+
def insert_attachable_sql
attachable_sql = <<~SQL
INSERT INTO
@@ -329,7 +333,7 @@ module Journals
sanitize(attachable_sql,
journable_id: journable.id,
- journable_class_name: journable.class.name)
+ journable_class_name:)
end
def insert_customizable_sql
@@ -355,7 +359,7 @@ module Journals
sanitize(customizable_sql,
journable_id: journable.id,
- journable_class_name: journable.class.name)
+ journable_class_name:)
end
def select_max_journal_sql(predecessor)
@@ -421,7 +425,7 @@ module Journals
sanitize(attachable_changes_sql,
journable_id: journable.id,
- container_type: journable.class.name)
+ container_type: journable_class_name)
end
def customizable_changes_sql
@@ -448,7 +452,7 @@ module Journals
SQL
sanitize(customizable_changes_sql,
- customized_type: journable.class.name,
+ customized_type: journable_class_name,
journable_id: journable.id)
end
diff --git a/modules/backlogs/spec/models/task_spec.rb b/modules/backlogs/spec/models/task_spec.rb
index 8dd2087861a..b70d0acad6d 100644
--- a/modules/backlogs/spec/models/task_spec.rb
+++ b/modules/backlogs/spec/models/task_spec.rb
@@ -42,7 +42,62 @@ describe Task do
before do
allow(Setting)
.to receive(:plugin_openproject_backlogs)
- .and_return({ 'task_type' => task_type.id.to_s })
+ .and_return({ 'task_type' => task_type.id.to_s })
+ end
+
+ describe 'having custom journables', with_settings: { journal_aggregation_time_minutes: 0 } do
+ let(:user) { create(:user) }
+ let(:role) { create(:role, permissions: %i[add_work_packages manage_subtasks manage_work_packages view_work_packages]) }
+ let(:member) { create(:member, principal: user, project:, roles: [role]) }
+
+ before do
+ project.members << member
+ end
+
+ describe 'with unchanged custom field' do
+ let(:custom_field) { create(:work_package_custom_field, name: 'TestingCustomField', field_format: 'text') }
+
+ before do
+ project.work_package_custom_fields << custom_field
+ task_type.custom_fields << custom_field
+ end
+
+ it 'must have the same journal when resaved' do
+ task.custom_field_values = { custom_field.id => 'Example CF text' }
+ task.save!
+
+ expect(task.journals.last.customizable_journals.count).to eq 1
+ customizable_journal = task.journals.last.customizable_journals.first
+
+ attributes = { id: task.id, parent_id: task.parent_id, status_id: task.status_id }
+ result = WorkPackages::UpdateService.new(user:, model: task).call(**attributes)
+
+ expect(result).to be_success
+ task.reload
+
+ expect(task.journals.last.customizable_journals.first).to eq customizable_journal
+ end
+ end
+
+ describe 'with attachment' do
+ let(:attachment) { build(:attachment) }
+
+ it 'must have the same journal when resaved' do
+ task.attachments << attachment
+ task.save!
+
+ expect(task.journals.last.attachable_journals.count).to eq 1
+ attachable_journal = task.journals.last.attachable_journals.first
+
+ attributes = { id: task.id, parent_id: task.parent_id, status_id: task.status_id }
+ result = WorkPackages::UpdateService.new(user:, model: task).call(**attributes)
+
+ expect(result).to be_success
+ task.reload
+
+ expect(task.journals.last.attachable_journals.first).to eq attachable_journal
+ end
+ end
end
describe 'copying remaining_hours to estimated_hours and vice versa' do