Skip to content

Commit

Permalink
Merge pull request #14378 from opf/implementation/50958-make-work-and…
Browse files Browse the repository at this point in the history
…-remaining-work-fields-editable-for-all-work-packages

[50958] Make work and remaining work fields editable for all work packages
  • Loading branch information
ulferts authored Dec 11, 2023
2 parents 468ca78 + 34bc774 commit 534ad12
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 250 deletions.
7 changes: 3 additions & 4 deletions modules/backlogs/lib/open_project/backlogs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#++

require 'open_project/plugins'
require_relative './patches/api/work_package_representer'
require_relative './patches/api/work_package_schema_representer'
require_relative 'patches/api/work_package_representer'
require_relative 'patches/api/work_package_schema_representer'

module OpenProject::Backlogs
class Engine < ::Rails::Engine
Expand Down Expand Up @@ -132,7 +132,6 @@ def self.settings
VersionsController
Version]

patch_with_namespace :API, :V3, :WorkPackages, :Schema, :SpecificWorkPackageSchema
patch_with_namespace :WorkPackages, :UpdateAncestors, :Loader
patch_with_namespace :BasicData, :SettingSeeder
patch_with_namespace :DemoData, :ProjectSeeder
Expand Down Expand Up @@ -172,7 +171,7 @@ def self.settings
&::OpenProject::Backlogs::Patches::API::WorkPackageSchemaRepresenter.extension)

add_api_attribute on: :work_package, ar_name: :story_points
add_api_attribute on: :work_package, ar_name: :remaining_hours, writable: ->(*) { model.leaf? }
add_api_attribute on: :work_package, ar_name: :remaining_hours

add_api_path :backlogs_type do |id|
# There is no api endpoint for this url
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch
prepend InstanceMethods
extend ClassMethods

before_validation :backlogs_before_validation, if: -> { backlogs_enabled? }

register_journal_formatted_fields(:fraction, 'remaining_hours')
register_journal_formatted_fields(:fraction, 'derived_remaining_hours')
register_journal_formatted_fields(:decimal, 'story_points')
Expand Down Expand Up @@ -130,15 +128,6 @@ def backlogs_enabled?
def in_backlogs_type?
backlogs_enabled? && WorkPackage.backlogs_types.include?(type.try(:id))
end

private

def backlogs_before_validation
if type_id == Task.type
self.estimated_hours = remaining_hours if estimated_hours.blank? && remaining_hours.present?
self.remaining_hours = estimated_hours if remaining_hours.blank? && estimated_hours.present?
end
end
end
end

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@
context 'has changed' do
let(:changed_values) { ['remaining_hours'] }

it('is invalid') do
expect(contract.errors.symbols_for(:remaining_hours)).to match_array([:error_readonly])
end
it('is valid') { expect(contract.errors.empty?).to be true }
end
end
end
Expand Down
45 changes: 0 additions & 45 deletions modules/backlogs/spec/models/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,49 +101,4 @@
end
end
end

describe 'copying remaining_hours to estimated_hours and vice versa' do
context 'providing only remaining_hours' do
before do
task.remaining_hours = 3

task.save!
end

it 'copies to estimated_hours' do
expect(task.estimated_hours)
.to eql task.remaining_hours
end
end

context 'providing only estimated_hours' do
before do
task.estimated_hours = 3

task.save!
end

it 'copies to estimated_hours' do
expect(task.remaining_hours)
.to eql task.estimated_hours
end
end

context 'providing estimated_hours and remaining_hours' do
before do
task.estimated_hours = 3
task.remaining_hours = 5

task.save!
end

it 'leaves the values unchanged' do
expect(task.remaining_hours)
.to be 5.0

expect(task.estimated_hours)
.to be 3.0
end
end
end
end

0 comments on commit 534ad12

Please sign in to comment.