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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix status and status attribute parsing in representer oncemore
Oliver Günther7fb86810db6c
diff --git a/lib/api/utilities/payload_representer.rb b/lib/api/utilities/payload_representer.rbindex 58c8f271307..216cc3904a7 100644--- a/lib/api/utilities/payload_representer.rb+++ b/lib/api/utilities/payload_representer.rb@@ -40,13 +40,13 @@ module APInextend- writable = property[:writable]- if writable == false+ writeable = property[:writeable]+ if writeable == falseproperty.merge!(readable: false)end# Only filter unwritable if not a lambda- unless writable&.respond_to?(:call)+ unless writeable&.respond_to?(:call)add_filter(property, UnwriteablePropertyFilter)endenddiff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex 6d83682be4c..29a09bc212a 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -46,13 +46,24 @@ module APIself_link- def to_h+ def from_hash(body)# Representable is broken when passing nil as parameters# it will set the property :status and :statusExplanation# regardless of what the setter actually does- super.tap do |result|- result.except!(:status, :statusExplanation)- result[:status] = result.delete(:status_attributes) if result.key?(:status_attributes)+ # Bug opened at https://github.com/trailblazer/representable/issues/234+ super(body).tap do |struct|+ next unless struct.respond_to?(:status_attributes)++ # Set the status attribute properly+ struct.status = struct.status_attributes++ # Remove temporary attributes workaround+ struct.delete_field(:status_attributes)++ # Remove nil status_explanation when passed as nil+ if struct.respond_to?(:status_explanation)+ struct.delete_field(:status_explanation)+ endendend@@ -193,7 +204,7 @@ module API}property :status_explanation,- writable: -> { represented.writable?(:status) },+ writeable: -> { represented.writable?(:status) },getter: ->(*) {::API::Decorators::Formattable.new(status&.explanation,object: self,diff --git a/modules/grids/spec/support/pages/grid.rb b/modules/grids/spec/support/pages/grid.rbindex dcee005e1d9..85b17d42252 100644--- a/modules/grids/spec/support/pages/grid.rb+++ b/modules/grids/spec/support/pages/grid.rb@@ -80,7 +80,7 @@ module Pagesdef within_add_widget_modal(row_number, column_number, location)area = area_of(row_number, column_number, location)area.hover- area.find('.grid--widget-add').click+ area.find('.grid--widget-add', visible: :all).clickwithin '.op-modal--portal' doyielddiff --git a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rbindex eedd04ea27f..406c1bae01d 100644--- a/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb+++ b/spec/lib/api/v3/projects/project_payload_representer_parsing_spec.rb@@ -49,11 +49,11 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' doendit 'updates code' do- project_obj = representer.from_hash(hash)- expect(project_obj.status_attributes[:code])+ project = representer.from_hash(hash)+ expect(project.status[:code]).to eql(:on_track)- expect(project_obj.status_attributes[:explanation])+ expect(project.status[:explanation]).to eql('status code explanation')end@@ -65,14 +65,14 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' doendit 'does not set code' do- project_obj = representer.from_hash(hash)- expect(project_obj.status_attributes[:code])+ project = representer.from_hash(hash)+ expect(project.status[:code]).to be_nilendit 'updates explanation' do- project_obj = representer.from_hash(hash)- expect(project_obj.status_attributes[:explanation])+ project = representer.from_hash(hash)+ expect(project.status[:explanation]).to eql('status code explanation')endend@@ -85,14 +85,14 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' doendit 'does set code' do- project_obj = representer.from_hash(hash)- expect(project_obj.status_attributes[:code])+ project = representer.from_hash(hash)+ expect(project.status[:code]).to eql :off_trackendit 'does not set explanation' do- project_obj = representer.from_hash(hash)- expect(project_obj.status_attributes[:explanation])+ project = representer.from_hash(hash)+ expect(project.status[:explanation]).to be_nilendend@@ -105,19 +105,19 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' doendit 'does set status to nil' do- project_obj = representer.from_hash(hash).to_h+ project = representer.from_hash(hash).to_h- expect(project_obj)- .to have_key(:status_attributes)+ expect(project)+ .to have_key(:status)- status_attributes = project_obj[:status_attributes]- expect(status_attributes)+ status = project[:status]+ expect(status).to have_key(:code)- expect(status_attributes)+ expect(status).not_to have_key(:explanation)- expect(status_attributes[:code])+ expect(status[:code]).to eq nilendenddiff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rbindex 64081f44b72..261e1fd8b29 100644--- a/spec/services/projects/set_attributes_service_spec.rb+++ b/spec/services/projects/set_attributes_service_spec.rb@@ -259,7 +259,7 @@ describe Projects::SetAttributesService, type: :model docontext 'with a value provided' dolet(:call_attributes) do{- status_attributes: {+ status: {code: 'on_track',explanation: 'A magic dwells in each beginning.'}@@ -290,7 +290,7 @@ describe Projects::SetAttributesService, type: :model docontext 'with a value provided' dolet(:call_attributes) do{- status_attributes: {+ status: {code: 'on_track',explanation: 'A magic dwells in each beginning.'}@@ -316,7 +316,7 @@ describe Projects::SetAttributesService, type: :model docontext 'with an invalid code' dolet(:call_attributes) do{- status_attributes: {+ status: {code: 'bogus',explanation: 'A magic dwells in each beginning.'}@@ -351,7 +351,7 @@ describe Projects::SetAttributesService, type: :model docontext 'with a value provided' dolet(:call_attributes) do{- status_attributes: {+ status: {code: 'at_risk',explanation: 'Still some magic there.'}