Fix deleting task relations
While the request body of a DELETE request *can* have data in it, it is not really supported and pretty much undocumented. As such, it doesn't work in all clients and probably broke with recent updates. This fixes this by moving all parts of the task relation used to identify it in the url. More Info: https://stackoverflow.com/a/299696/10924593
This commit is contained in:
parent
3afedc25f0
commit
eb3a945678
5 changed files with 92 additions and 47 deletions
|
@ -81,9 +81,9 @@ type TaskRelation struct {
|
||||||
// The ID of the "base" task, the task which has a relation to another.
|
// The ID of the "base" task, the task which has a relation to another.
|
||||||
TaskID int64 `xorm:"bigint not null" json:"task_id" param:"task"`
|
TaskID int64 `xorm:"bigint not null" json:"task_id" param:"task"`
|
||||||
// The ID of the other task, the task which is being related.
|
// The ID of the other task, the task which is being related.
|
||||||
OtherTaskID int64 `xorm:"bigint not null" json:"other_task_id"`
|
OtherTaskID int64 `xorm:"bigint not null" json:"other_task_id" param:"otherTask"`
|
||||||
// The kind of the relation.
|
// The kind of the relation.
|
||||||
RelationKind RelationKind `xorm:"varchar(50) not null" json:"relation_kind"`
|
RelationKind RelationKind `xorm:"varchar(50) not null" json:"relation_kind" param:"relationKind"`
|
||||||
|
|
||||||
CreatedByID int64 `xorm:"bigint not null" json:"-"`
|
CreatedByID int64 `xorm:"bigint not null" json:"-"`
|
||||||
// The user who created this relation
|
// The user who created this relation
|
||||||
|
@ -196,16 +196,18 @@ func (rel *TaskRelation) Create(s *xorm.Session, a web.Auth) error {
|
||||||
// @Security JWTKeyAuth
|
// @Security JWTKeyAuth
|
||||||
// @Param relation body models.TaskRelation true "The relation object"
|
// @Param relation body models.TaskRelation true "The relation object"
|
||||||
// @Param taskID path int true "Task ID"
|
// @Param taskID path int true "Task ID"
|
||||||
|
// @Param relationKind path string true "The kind of the relation. See the TaskRelation type for more info."
|
||||||
|
// @Param otherTaskID path int true "The id of the other task."
|
||||||
// @Success 200 {object} models.Message "The task relation was successfully deleted."
|
// @Success 200 {object} models.Message "The task relation was successfully deleted."
|
||||||
// @Failure 400 {object} web.HTTPError "Invalid task relation object provided."
|
// @Failure 400 {object} web.HTTPError "Invalid task relation object provided."
|
||||||
// @Failure 404 {object} web.HTTPError "The task relation was not found."
|
// @Failure 404 {object} web.HTTPError "The task relation was not found."
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /tasks/{taskID}/relations [delete]
|
// @Router /tasks/{taskID}/relations/{relationKind}/{otherTaskId} [delete]
|
||||||
func (rel *TaskRelation) Delete(s *xorm.Session, a web.Auth) error {
|
func (rel *TaskRelation) Delete(s *xorm.Session, a web.Auth) error {
|
||||||
// Check if the relation exists
|
// Check if the relation exists
|
||||||
exists, err := s.
|
exists, err := s.
|
||||||
Cols("task_id", "other_task_id", "relation_kind").
|
Where("task_id = ? AND other_task_id = ? AND relation_kind = ?", rel.TaskID, rel.OtherTaskID, rel.RelationKind).
|
||||||
Get(rel)
|
Exist(&TaskRelation{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,7 @@ func registerAPIRoutes(a *echo.Group) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
a.PUT("/tasks/:task/relations", taskRelationHandler.CreateWeb)
|
a.PUT("/tasks/:task/relations", taskRelationHandler.CreateWeb)
|
||||||
a.DELETE("/tasks/:task/relations", taskRelationHandler.DeleteWeb)
|
a.DELETE("/tasks/:task/relations/:relationKind/:otherTask", taskRelationHandler.DeleteWeb)
|
||||||
|
|
||||||
if config.ServiceEnableTaskAttachments.GetBool() {
|
if config.ServiceEnableTaskAttachments.GetBool() {
|
||||||
taskAttachmentHandler := &handler.WebHandler{
|
taskAttachmentHandler := &handler.WebHandler{
|
||||||
|
|
|
@ -5313,7 +5313,9 @@ var doc = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
"/tasks/{taskID}/relations/{relationKind}/{otherTaskId}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
|
@ -5346,6 +5348,20 @@ var doc = `{
|
||||||
"name": "taskID",
|
"name": "taskID",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "The kind of the relation. See the TaskRelation type for more info.",
|
||||||
|
"name": "relationKind",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "The id of the other task.",
|
||||||
|
"name": "otherTaskID",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
|
@ -5296,7 +5296,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
"/tasks/{taskID}/relations/{relationKind}/{otherTaskId}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
|
@ -5329,6 +5331,20 @@
|
||||||
"name": "taskID",
|
"name": "taskID",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "The kind of the relation. See the TaskRelation type for more info.",
|
||||||
|
"name": "relationKind",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "The id of the other task.",
|
||||||
|
"name": "otherTaskID",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
|
@ -4542,45 +4542,6 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- labels
|
- labels
|
||||||
/tasks/{taskID}/relations:
|
/tasks/{taskID}/relations:
|
||||||
delete:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
parameters:
|
|
||||||
- description: The relation object
|
|
||||||
in: body
|
|
||||||
name: relation
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/models.TaskRelation'
|
|
||||||
- description: Task ID
|
|
||||||
in: path
|
|
||||||
name: taskID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: The task relation was successfully deleted.
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/models.Message'
|
|
||||||
"400":
|
|
||||||
description: Invalid task relation object provided.
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/web.HTTPError'
|
|
||||||
"404":
|
|
||||||
description: The task relation was not found.
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/web.HTTPError'
|
|
||||||
"500":
|
|
||||||
description: Internal error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/models.Message'
|
|
||||||
security:
|
|
||||||
- JWTKeyAuth: []
|
|
||||||
summary: Remove a task relation
|
|
||||||
tags:
|
|
||||||
- task
|
|
||||||
put:
|
put:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
|
@ -4617,6 +4578,56 @@ paths:
|
||||||
summary: Create a new relation between two tasks
|
summary: Create a new relation between two tasks
|
||||||
tags:
|
tags:
|
||||||
- task
|
- task
|
||||||
|
/tasks/{taskID}/relations/{relationKind}/{otherTaskId}:
|
||||||
|
delete:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- description: The relation object
|
||||||
|
in: body
|
||||||
|
name: relation
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.TaskRelation'
|
||||||
|
- description: Task ID
|
||||||
|
in: path
|
||||||
|
name: taskID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
- description: The kind of the relation. See the TaskRelation type for more info.
|
||||||
|
in: path
|
||||||
|
name: relationKind
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: The id of the other task.
|
||||||
|
in: path
|
||||||
|
name: otherTaskID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: The task relation was successfully deleted.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.Message'
|
||||||
|
"400":
|
||||||
|
description: Invalid task relation object provided.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/web.HTTPError'
|
||||||
|
"404":
|
||||||
|
description: The task relation was not found.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/web.HTTPError'
|
||||||
|
"500":
|
||||||
|
description: Internal error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.Message'
|
||||||
|
security:
|
||||||
|
- JWTKeyAuth: []
|
||||||
|
summary: Remove a task relation
|
||||||
|
tags:
|
||||||
|
- task
|
||||||
/tasks/all:
|
/tasks/all:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
|
Loading…
Reference in a new issue