diff options
author | kolaente <konrad@kola-entertainments.de> | 2018-07-16 14:43:00 +0200 |
---|---|---|
committer | Jonas Franz <info@jonasfranz.software> | 2018-07-16 14:43:00 +0200 |
commit | ef6813abc9277f29515cb571c4c4ddc373482e58 (patch) | |
tree | cba04950ada22fd5a46cb388677dc263340a93dc /routers/api | |
parent | 55d9ddf24a2d3c608395055e47ba321a4a4739c4 (diff) | |
download | gitea-ef6813abc9277f29515cb571c4c4ddc373482e58.tar.gz gitea-ef6813abc9277f29515cb571c4c4ddc373482e58.zip |
Issue due date api (#3890)
* Implemented basic api endpoint to manage deadlines
* Fixed checking for permissions
* Updating a deadline from the ui is now entirely done via the api
* cleanup
* Cosmetics
* fixed lint + fmt
* Added swagger model definition for deadline response
* Updated gitea-sdk
* Updated gitea-sdk
* More cleanup
* Generate swagger json
* Merge branch 'master' of https://github.com/go-gitea/gitea into issue-due-date-api
# Conflicts:
# public/swagger.v1.json
* Fixed permission to update a deadline via api
* Re-added form to change a deadline
* Added client-side validation + not ignore error messages from the api
* Added locale for error message
* Merge branch 'master' of https://github.com/go-gitea/gitea
# Conflicts:
# models/issue_comment.go
* Proper date validation
* Fixed indention
* moved css to css file
* added documentation for error codes
* after merge cleanup
* Added swagger description
* DO NOTHING BUT TRIGGER THAT F*CKIN CI SO IT PICKS UP THE LATEST COMMIT AS IT SHOULD
* DO NOTHING BUT TRIGGER THAT F*CKIN CI SO IT PICKS UP THE LATEST COMMIT AS IT SHOULD
* regenerated stylesheets
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 71 | ||||
-rw-r--r-- | routers/api/v1/swagger/issue.go | 7 | ||||
-rw-r--r-- | routers/api/v1/swagger/options.go | 2 |
4 files changed, 81 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 689ea22cca..3174e56374 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -447,6 +447,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Combo("").Get(repo.ListTrackedTimes). Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTime) }) + + m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) }) }, mustEnableIssues) m.Group("/labels", func() { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 7be39166d2..76f58b244e 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -278,7 +278,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { // Update the deadline var deadlineUnix util.TimeStamp - if form.Deadline != nil && !form.Deadline.IsZero() { + if form.Deadline != nil && !form.Deadline.IsZero() && ctx.Repo.IsWriter() { deadlineUnix = util.TimeStamp(form.Deadline.Unix()) } @@ -338,3 +338,72 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { } ctx.JSON(201, issue.APIFormat()) } + +// UpdateIssueDeadline updates an issue deadline +func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) { + // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/deadline issue issueEditIssueDeadline + // --- + // summary: Set an issue deadline. If set to null, the deadline is deleted. + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: index + // in: path + // description: index of the issue to create or update a deadline on + // type: integer + // required: true + // - name: body + // in: body + // schema: + // "$ref": "#/definitions/EditDeadlineOption" + // responses: + // "201": + // "$ref": "#/responses/IssueDeadline" + // "403": + // description: Not repo writer + // schema: + // "$ref": "#/responses/forbidden" + // "404": + // description: Issue not found + // schema: + // "$ref": "#/responses/empty" + + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrIssueNotExist(err) { + ctx.Status(404) + } else { + ctx.Error(500, "GetIssueByIndex", err) + } + return + } + + if !ctx.Repo.IsWriter() { + ctx.Status(403) + return + } + + var deadlineUnix util.TimeStamp + if form.Deadline != nil && !form.Deadline.IsZero() { + deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + } + + if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { + ctx.Error(500, "UpdateIssueDeadline", err) + return + } + + ctx.JSON(201, api.IssueDeadline{Deadline: form.Deadline}) +} diff --git a/routers/api/v1/swagger/issue.go b/routers/api/v1/swagger/issue.go index 0d4e40616a..16711e9b7e 100644 --- a/routers/api/v1/swagger/issue.go +++ b/routers/api/v1/swagger/issue.go @@ -77,3 +77,10 @@ type swaggerResponseTrackedTimeList struct { // in:body Body []api.TrackedTime `json:"body"` } + +// IssueDeadline +// swagger:response IssueDeadline +type swaggerIssueDeadline struct { + // in:body + Body api.IssueDeadline `json:"body"` +} diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go index 4f2461f465..177fe415f1 100644 --- a/routers/api/v1/swagger/options.go +++ b/routers/api/v1/swagger/options.go @@ -32,6 +32,8 @@ type swaggerParameterBodies struct { CreateIssueOption api.CreateIssueOption // in:body EditIssueOption api.EditIssueOption + // in:body + EditDeadlineOption api.EditDeadlineOption // in:body CreateIssueCommentOption api.CreateIssueCommentOption |