diff --git a/controller/workitem_blackbox_test.go b/controller/workitem_blackbox_test.go index 2724dc72e3..c404ced1e8 100644 --- a/controller/workitem_blackbox_test.go +++ b/controller/workitem_blackbox_test.go @@ -558,6 +558,36 @@ func (s *WorkItemSuite) TestUpdateWorkitemWithoutReorder() { assert.Equal(s.T(), wi.Data.Attributes[workitem.SystemOrder], updated.Data.Attributes[workitem.SystemOrder]) } +// TestReorderDoesNotUpdateAnyOtherWIFields tests that no other workitem fields are updated while reorder +func (s *WorkItemSuite) TestReorderDoesNotUpdateOtherWIFields() { + fxt := tf.NewTestFixture(s.T(), s.DB, tf.CreateWorkItemEnvironment()) + + // create workitems + payload := minimumRequiredCreateWithTypeAndSpace(fxt.WorkItemTypes[0].ID, fxt.Spaces[0].ID) + originalTitle := "Original Title" + payload.Data.Attributes[workitem.SystemTitle] = originalTitle + payload.Data.Attributes[workitem.SystemState] = workitem.SystemStateClosed + _, workitem1 := test.CreateWorkitemsCreated(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, *payload.Data.Relationships.Space.Data.ID, &payload) + _, workitem2 := test.CreateWorkitemsCreated(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, *payload.Data.Relationships.Space.Data.ID, &payload) + + titleNotUpdated := "This Title Should Not Be Updated" + workitem1.Data.Attributes[workitem.SystemTitle] = titleNotUpdated + + payload2 := minimumRequiredReorderPayload() + + var dataArray []*app.WorkItem // dataArray contains the workitem(s) that have to be reordered + dataArray = append(dataArray, workitem1.Data) + payload2.Data = dataArray + payload2.Position.ID = workitem2.Data.ID // Position.ID specifies the workitem ID above or below which the workitem(s) should be placed + payload2.Position.Direction = string(workitem.DirectionAbove) + _, reorderedList := test.ReorderWorkitemsOK(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, fxt.Spaces[0].ID, &payload2) // Returns the workitems which are reordered + + require.Len(s.T(), reorderedList.Data, 1) + assert.Equal(s.T(), workitem1.Data.Attributes["version"].(int)+1, reorderedList.Data[0].Attributes["version"]) + assert.Equal(s.T(), *workitem1.Data.ID, *reorderedList.Data[0].ID) + assert.Equal(s.T(), originalTitle, reorderedList.Data[0].Attributes[workitem.SystemTitle]) +} + func (s *WorkItemSuite) TestCreateWorkItemWithoutContext() { // given s.svc = goa.New("TestCreateWorkItemWithoutContext-Service") diff --git a/workitem/workitem_repository.go b/workitem/workitem_repository.go index 37105077f4..ece0f2f403 100644 --- a/workitem/workitem_repository.go +++ b/workitem/workitem_repository.go @@ -544,24 +544,11 @@ func (r *GormWorkItemRepository) Reorder(ctx context.Context, spaceID uuid.UUID, default: return &wi, nil } - res.Version = res.Version + 1 - res.Type = wi.Type - res.Fields = Fields{} - res.ExecutionOrder = order - - for fieldName, fieldDef := range wiType.Fields { - if fieldDef.ReadOnly { - continue - } - fieldValue := wi.Fields[fieldName] - var err error - res.Fields[fieldName], err = fieldDef.ConvertToModel(fieldName, fieldValue) - if err != nil { - return nil, errors.NewBadParameterError(fieldName, fieldValue) - } - } - tx = tx.Where("Version = ?", wi.Version).Save(&res) + tx = tx.Model(&res).Select("execution_order", "version").Updates(WorkItemStorage{ + ExecutionOrder: order, + Version: res.Version + 1, + }) if err := tx.Error; err != nil { return nil, errors.NewInternalError(ctx, err) }