coopcycle-web icon indicating copy to clipboard operation
coopcycle-web copied to clipboard

Editing issues when recurrent task edit

Open AdrienSICKLO opened this issue 2 years ago • 3 comments

When editing recurrent rules, the addresses don't change. See GIF

Recurrent problem when editing

AdrienSICKLO avatar Jul 05 '22 14:07 AdrienSICKLO

It seems to be because what is stored in the task_rrule.template column in database is wrong. It contains at the same time an @id column, and properties.

Example:

{
  "@type":"hydra:Collection",
  "hydra:member":[
    {
      "@type":"Task",
      "type":"PICKUP",
      "address":{
        "@id":"\/api\/addresses\/12487",
        "streetAddress":"20 Rue du Clos Feuqui\u00e8res, Paris, France",
        "postalCode":"75015",
        "contactName":"Jean Michel",
        "telephone":"+33606060606"
      },
      "after":"00:00",
      "before":"23:59",
      "comments":"Attention!!!!!!!"
    },
    {
      "@type":"Task",
      "type":"DROPOFF",
      "address":{
        "@id":"\/api\/addresses\/12488",
        "streetAddress":"30 Rue Pirandello, Paris, France",
        "postalCode":"75013",
        "contactName":"Marie Michelle",
        "telephone":"+33606060606"
      },
      "after":"00:00",
      "before":"23:59",
      "comments":"Pourquoi?"
    }
  ]
}

So probably the code in TaskNormalizer::denormalize loads what is stored in database, and not the properties in the JSON.

https://github.com/coopcycle/coopcycle-web/blob/4a60bbfa8ea4f5cc9c65aa069e3d168bbea07b09/src/Serializer/TaskNormalizer.php#L115

alexsegura avatar Jul 06 '22 12:07 alexsegura

Hi guys, another thing maybe related to that :

When you change the address of a task created through a recurrent task, it modifies all other recurrent tasks created before and after.

Indeed, it changes the address linked to all tasks but not the address of the recurrent entity : Screenshot from 2022-07-19 17-55-55

Created task :

Screenshot from 2022-07-19 17-56-26

Task created before modification :

Screenshot from 2022-07-19 17-57-04

Task created after modification :

Screenshot from 2022-07-19 18-00-15 .

biologeek avatar Jul 19 '22 16:07 biologeek

There is some code in TaskRecurrenceRuleSubscriber that persists the adresses entered in the modal (this is why we end up with addresses with an @id).

We do this, to avoid duplicating addresses each time tasks are created.

There are 2 issues here:

  1. [x] Make sure that address is updated when editing a recurrent rule, using duplication. We need to keep the previous address untouched, and recreated a new address, to avoid losing the database links.

  2. [x] When editing a task's address, we are actually modifying the address object in database. All other tasks that are linked to this address would have their address modified as well. For most users, when they modify the address of a task, it's not obvious that they will modify all other tasks. So, when a task's address is modified, we need to create a new address, instead of updating the existing address.

alexsegura avatar Jul 22 '22 12:07 alexsegura