labels are not assigned/created together with task #1186

Open
opened 4 months ago by k2s · 5 comments
k2s commented 4 months ago

I created test script based on attachment_from_scratch.sh

#!/usr/bin/env bash

curl -X POST http://localhost:3456/api/v1/register -H 'Content-Type: application/json' -d '{"username":"demo","password":"demo","email":"demo@example.com"}'

BEARER=`curl -X POST -H 'Content-Type: application/json' -d '{"username": "demo", "password":"demo"}' localhost:3456/api/v1/login | jq -r '.token'`
echo "Bearer: $BEARER"

# create first list
curl -X PUT localhost:3456/api/v1/namespaces/1/lists  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"list"}'

# create labels
curl -X PUT localhost:3456/api/v1/labels  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"created with label"}'
curl -X PUT localhost:3456/api/v1/labels  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"label assigned later"}'

# craete simple task
curl -X PUT localhost:3456/api/v1/lists/1  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"simple task"}'

# create task with existing labels
curl -X PUT localhost:3456/api/v1/lists/1  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task with existing label", "labels": [{"id": 1}]}'

# create task with new label 
curl -X PUT localhost:3456/api/v1/lists/1  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task with new label", "labels": [{"title": "label created with task"}]}'

# craete task and then set label
ID=`curl -X PUT localhost:3456/api/v1/lists/1  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task and later label"}' | jq -r '.id'`
curl -X POST localhost:3456/api/v1/tasks/${ID}/labels/bulk  -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"labels": [{"id": 2}]}'

Only 1 task will have label assigned. Correct would be if 3 would have label assigned.

I created test script based on `attachment_from_scratch.sh` ``` #!/usr/bin/env bash curl -X POST http://localhost:3456/api/v1/register -H 'Content-Type: application/json' -d '{"username":"demo","password":"demo","email":"demo@example.com"}' BEARER=`curl -X POST -H 'Content-Type: application/json' -d '{"username": "demo", "password":"demo"}' localhost:3456/api/v1/login | jq -r '.token'` echo "Bearer: $BEARER" # create first list curl -X PUT localhost:3456/api/v1/namespaces/1/lists -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"list"}' # create labels curl -X PUT localhost:3456/api/v1/labels -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"created with label"}' curl -X PUT localhost:3456/api/v1/labels -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"label assigned later"}' # craete simple task curl -X PUT localhost:3456/api/v1/lists/1 -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"simple task"}' # create task with existing labels curl -X PUT localhost:3456/api/v1/lists/1 -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task with existing label", "labels": [{"id": 1}]}' # create task with new label curl -X PUT localhost:3456/api/v1/lists/1 -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task with new label", "labels": [{"title": "label created with task"}]}' # craete task and then set label ID=`curl -X PUT localhost:3456/api/v1/lists/1 -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"title":"task and later label"}' | jq -r '.id'` curl -X POST localhost:3456/api/v1/tasks/${ID}/labels/bulk -H 'Content-Type: application/json' -H "Authorization: Bearer $BEARER" -d '{"labels": [{"id": 2}]}' ``` Only 1 task will have label assigned. Correct would be if 3 would have label assigned.
k2s changed title from labels are not assigned/created together whith to labels are not assigned/created together with task 4 months ago
Owner

Which one is assigned as expected, the last one?

For creating a task and passing the label along this is simply not implemented.

Changing the labels during updates is a bit more complicated: https://kolaente.dev/vikunja/api/src/branch/main/pkg/models/tasks.go#L1050-L1065
Now, it's been a while since I wrote that comment so it might be time to revisit the mechanism.

Which one is assigned as expected, the last one? For creating a task and passing the label along this is simply not implemented. Changing the labels during updates is a bit more complicated: https://kolaente.dev/vikunja/api/src/branch/main/pkg/models/tasks.go#L1050-L1065 Now, it's been a while since I wrote that comment so it might be time to revisit the mechanism.
Poster

The last one works. I would expect that all 3 requests containing labels should work.

It is not so important for user interaction, but it makes diferrence when mass importing.

Was not thinking about permission problem, but should we not simply:

  • if labels array is provided on task create/update
  • we should check permission (was not looking in code how it is done for now) for all labels
  • refuse the whole request if at least access to 1 label is restricted

The task with new label request is different problem, it requires to get or create label.

All this is only about bulk operation efficiency and not very critical.

It should be at least documented in https://try.vikunja.io/api/v1/docs#tag/task.

The last one works. I would expect that all 3 requests containing `labels` should work. It is not so important for user interaction, but it makes diferrence when mass importing. Was not thinking about permission problem, but should we not simply: * if labels array is provided on task create/update * we should check permission (was not looking in code how it is done for now) for all labels * refuse the whole request if at least access to 1 label is restricted The `task with new label` request is different problem, it requires to get or create label. All this is only about bulk operation efficiency and not very critical. It should be at least documented in https://try.vikunja.io/api/v1/docs#tag/task.
Owner

We actually do have the current user in the Update context so that we could implement adding labels while creating a task. As I said, it's been a while since I wrote that comment :)

As you outlined it is the way to go. I'd just like to check if there's an existing label and use that before creating a new one - or we could delegate that to the client and only check if there's an ID present in the label object and if that's the case check if the user can use that label and use it. If not, create and add it.

+1 for this should be documented.

Now, if we allow this for labels during creation, what about other related entities like assignees?

We actually do have the current user in the `Update` context so that we could implement adding labels while creating a task. As I said, it's been a while since I wrote that comment :) As you outlined it is the way to go. I'd just like to check if there's an existing label and use that before creating a new one - or we could delegate that to the client and only check if there's an ID present in the label object and if that's the case check if the user can use that label and use it. If not, create and add it. +1 for this should be documented. Now, if we allow this for labels during creation, what about other related entities like assignees?
Poster

My opinion:

  • assignees - only existing by ID
  • attachments - also create new
  • labels - also create new
  • related_tasks - only existing
  • subscription - only existing user
My opinion: * assignees - only existing by ID * attachments - also create new * labels - also create new * related_tasks - only existing * subscription - only existing user
Owner

I think that makes sense.

Just a note, a user can only subscribe themselves to a task, it is not possible to subscribe other people to a task or list.

I think that makes sense. Just a note, a user can only subscribe themselves to a task, it is not possible to subscribe other people to a task or list.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/api#1186
Loading…
There is no content yet.