journalize changes to the scheduling mode

pull/8539/head
ulferts 4 years ago committed by Oliver Günther
parent 0dffec6f58
commit 3a3a48e267
  1. 1
      app/models/journal.rb
  2. 2
      app/models/work_package/journalized.rb
  3. 7
      config/locales/en.yml
  4. 5
      db/migrate/20200803081038_journalize_scheduling_mode.rb
  5. 8
      lib/open_project/journal_formatter/diff.rb
  6. 36
      lib/open_project/journal_formatter/schedule_manually.rb
  7. 2
      lib/plugins/acts_as_journalized/lib/journal_formatter/attribute.rb
  8. 3
      spec/features/work_packages/scheduling/scheduling_mode_spec.rb
  9. 61
      spec/lib/journal_formatter/schedule_manually_spec.rb
  10. 26
      spec/models/work_package/work_package_acts_as_journalized_spec.rb

@ -37,6 +37,7 @@ class Journal < ApplicationRecord
register_journal_formatter :diff, OpenProject::JournalFormatter::Diff
register_journal_formatter :attachment, OpenProject::JournalFormatter::Attachment
register_journal_formatter :custom_field, OpenProject::JournalFormatter::CustomField
register_journal_formatter :schedule_manually, OpenProject::JournalFormatter::ScheduleManually
# Make sure each journaled model instance only has unique version ids
validates_uniqueness_of :version, scope: [:journable_id, :journable_type]

@ -93,6 +93,7 @@ module WorkPackage::Journalized
register_on_journal_formatter(:fraction, 'derived_estimated_hours')
register_on_journal_formatter(:decimal, 'done_ratio')
register_on_journal_formatter(:diff, 'description')
register_on_journal_formatter(:schedule_manually, 'schedule_manually')
register_on_journal_formatter(:attachment, /attachments_?\d+/)
register_on_journal_formatter(:custom_field, /custom_fields_\d+/)
@ -101,7 +102,6 @@ module WorkPackage::Journalized
:status_id, :type_id,
:assigned_to_id, :priority_id,
:category_id, :version_id,
:planning_element_status_id,
:author_id, :responsible_id
register_on_journal_formatter :datetime, :start_date, :due_date
register_on_journal_formatter :plaintext, :subject

@ -543,7 +543,7 @@ en:
parent_work_package: "Parent"
priority: "Priority"
progress: "Progress (%)"
schedule_manually: "Schedule manually"
schedule_manually: "Manual scheduling"
spent_hours: "Spent time"
spent_time: "Spent time"
subproject: "Subproject"
@ -2165,6 +2165,10 @@ en:
warnings:
cannot_annotate: "This file cannot be annotated."
scheduling:
activated: 'activated'
deactivated: 'deactivated'
search_input_placeholder: "Search ..."
setting_email_delivery_method: "Email delivery method"
@ -2377,6 +2381,7 @@ en:
text_journal_deleted_with_diff: "%{label} deleted (%{link})"
text_journal_set_to: "%{label} set to %{value}"
text_journal_set_with_diff: "%{label} set (%{link})"
text_journal_label_value: "%{label} %{value}"
text_latest_note: "The latest comment is: %{note}"
text_length_between: "Length between %{min} and %{max} characters."
text_line_separated: "Multiple values allowed (one line for each value)."

@ -0,0 +1,5 @@
class JournalizeSchedulingMode < ActiveRecord::Migration[6.0]
def change
add_column :work_package_journals, :schedule_manually, :boolean, default: false
end
end

@ -55,12 +55,10 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
if value.blank?
l(:text_journal_deleted_with_diff, label: label, link: link)
elsif old_value.present?
l(:text_journal_changed_with_diff, label: label, link: link)
else
if old_value.present?
l(:text_journal_changed_with_diff, label: label, link: link)
else
l(:text_journal_set_with_diff, label: label, link: link)
end
l(:text_journal_set_with_diff, label: label, link: link)
end
end

@ -0,0 +1,36 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
class OpenProject::JournalFormatter::ScheduleManually < JournalFormatter::Base
def render(key, values, options = { no_html: false })
label_text = options[:no_html] ? label(key) : content_tag('strong', label(key))
activated_text = values.last ? I18n.t('scheduling.activated') : I18n.t('scheduling.deactivated')
I18n.t(:text_journal_label_value, label: label_text, value: activated_text)
end
end

@ -22,11 +22,9 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
module JournalFormatter
class Attribute < Base
private

@ -113,6 +113,9 @@ describe 'scheduling mode',
work_packages_page.expect_and_dismiss_notification message: 'Successful update.'
# Changing the scheduling mode is journalized
work_packages_page.expect_activity_message("Manual scheduling activated")
expect_dates(wp, '2016-01-05', '2016-01-10')
expect(wp.schedule_manually).to be_truthy

@ -0,0 +1,61 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe OpenProject::JournalFormatter::ScheduleManually do
let(:klass) { described_class }
let(:id) { 1 }
let(:journal) do
OpenStruct.new(id: id, journable: WorkPackage.new)
end
let(:instance) { klass.new(journal) }
let(:key) { 'schedule_manually' }
describe '#render' do
describe 'with the first value being true, and the second false' do
let(:expected) do
I18n.t(:text_journal_label_value,
label: "<strong>Manual scheduling</strong>",
value: 'deactivated')
end
it { expect(instance.render(key, [true, false])).to eq(expected) }
end
describe 'with the first value being false, and the second true' do
let(:expected) do
I18n.t(:text_journal_label_value,
label: "<strong>Manual scheduling</strong>",
value: 'activated')
end
it { expect(instance.render(key, [false, true])).to eq(expected) }
end
end
end

@ -69,11 +69,16 @@ describe WorkPackage, type: :model do
.to match_array [nil, work_package.project_id]
end
it 'notes the description to project' do
it 'notes the description' do
expect(Journal.first.details[:description])
.to match_array [nil, work_package.description]
end
it 'notes the scheduling mode' do
expect(Journal.first.details[:schedule_manually])
.to match_array [nil, false]
end
it 'has the timestamp of the work package update time for created_at' do
# This seemingly unnecessary reload leads to the updated_at having the same
# precision as the created_at of the Journal. It is database dependent, so it would work without
@ -173,6 +178,7 @@ describe WorkPackage, type: :model do
work_package.assigned_to = User.current
work_package.responsible = User.current
work_package.parent = parent_work_package
work_package.schedule_manually = true
work_package.save!
end
@ -183,7 +189,7 @@ describe WorkPackage, type: :model do
it 'contains all changes' do
%i(subject description type_id status_id priority_id
start_date due_date estimated_hours assigned_to_id
responsible_id parent_id).each do |a|
responsible_id parent_id schedule_manually).each do |a|
expect(subject).to have_key(a.to_s), "Missing change for #{a}"
end
end
@ -217,6 +223,22 @@ describe WorkPackage, type: :model do
it_behaves_like 'new value'
end
end
context 'schedule_manually' do
let(:property) { 'schedule_manually' }
context 'old_value' do
let(:expected_value) { false }
it_behaves_like 'old value'
end
context 'new value' do
let(:expected_value) { true }
it_behaves_like 'new value'
end
end
end
describe 'adding journal with a missing journal and an existing journal' do

Loading…
Cancel
Save