spiral-project / ihatemoney

A simple shared budget manager web application
https://ihatemoney.org
Other
1.2k stars 268 forks source link

Logging preference is reset when using PUT API requests #1205

Open zorun opened 1 year ago

zorun commented 1 year ago

The logging preference is set to 1 by default when creating a project:

$ curl -X POST http://localhost:5000/api/projects -d 'name=machin&id=machin&password=yay&contact_email=yay@example.com'
"machine"
$ curl -u 'machin:yay' http://localhost:5000/api/projects/machin
{
    "id": "machin",
    "name": "machin",
    "contact_email": "yay@example.com",
    "logging_preference": 1,
    "members": [],
    "default_currency": "XXX"
}

However, if you update the project with PUT and don't specify this field, it gets reset to 0:

$ curl -X PUT -u 'machin:yay' http://localhost:5000/api/projects/machin -d 'name=machinchose&id=machin&current_password=yay&contact_email=yay@example.com'
"UPDATED"
$ curl -u 'machin:yay' http://localhost:5000/api/projects/machin
{
    "id": "machin",
    "name": "machinchose",
    "contact_email": "yay@example.com",
    "logging_preference": 0,
    "members": [],
    "default_currency": "XXX"
}

Same thing for the default_currency: if you don't specify it in a PUT, it gets reset to XXX.

Since older API clients won't know about new optional fields, we should not reset these fields when they are not specified.

ccczzz12345 commented 11 months ago

I tried to solve this issue by editing the put function in the ProjectHandler Class.

Screenshot 2023-12-05 at 11 40 53 PM