Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue due date api #3890

Merged
merged 52 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1a905b2
Implemented basic api endpoint to manage deadlines
kolaente May 1, 2018
794ac07
Fixed checking for permissions
kolaente May 1, 2018
cf3313b
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 2, 2018
d27bb3e
Updating a deadline from the ui is now entirely done via the api
kolaente May 2, 2018
6c32b3d
cleanup
kolaente May 2, 2018
51cd3d7
Cosmetics
kolaente May 2, 2018
11bb494
fixed lint + fmt
kolaente May 2, 2018
4a31c8a
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 2, 2018
3f67df2
Added swagger model definition for deadline response
kolaente May 3, 2018
037ce0c
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 5, 2018
6ce65e5
Updated gitea-sdk
kolaente May 5, 2018
24cb3ce
Updated gitea-sdk
kolaente May 5, 2018
16d1c50
More cleanup
kolaente May 5, 2018
996432f
Generate swagger json
kolaente May 6, 2018
7038340
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 6, 2018
1279e04
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 6, 2018
6aa29b0
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 9, 2018
ead7b64
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 9, 2018
464de27
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 9, 2018
83c9187
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 9, 2018
c2fbe8f
Fixed permission to update a deadline via api
kolaente May 9, 2018
93b71d8
Re-added form to change a deadline
kolaente May 9, 2018
b05b423
Added client-side validation + not ignore error messages from the api
kolaente May 9, 2018
6294c86
Added locale for error message
kolaente May 9, 2018
e7734b2
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente May 11, 2018
c42c28d
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 18, 2018
0bf271b
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 18, 2018
8111fdf
Merge branch 'master' into issue-due-date-api
kolaente May 20, 2018
bb848c5
Merge remote-tracking branch 'upstream/master' into issue-due-date-api
kolaente May 20, 2018
1bf3c47
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Jun 8, 2018
5ea7b84
Proper date validation
kolaente Jun 8, 2018
541519d
Fixed indention
kolaente Jun 8, 2018
d8ab59e
moved css to css file
kolaente Jun 8, 2018
bbc51dc
Merge branch 'issue-due-date-api' of https://github.com/kolaente/gite…
kolaente Jun 8, 2018
6a7bffa
Merge branch 'master' into issue-due-date-api
kolaente Jun 11, 2018
ca83a54
added documentation for error codes
kolaente Jun 12, 2018
e2212ed
Merge remote-tracking branch 'upstream/master' into issue-due-date-api
kolaente Jun 12, 2018
b63232f
Merge remote-tracking branch 'upstream/master' into issue-due-date-api
kolaente Jun 13, 2018
e55d4a1
after merge cleanup
kolaente Jun 13, 2018
4d7a636
Merge branch 'issue-due-date-api' of https://github.com/kolaente/gite…
kolaente Jun 13, 2018
ab27aff
Merge branch 'master' into issue-due-date-api
kolaente Jun 17, 2018
a09582e
Merge remote-tracking branch 'upstream/master' into issue-due-date-api
kolaente Jun 17, 2018
3a9d32a
Added swagger description
kolaente Jun 17, 2018
5a084ad
Merge branch 'issue-due-date-api' of https://github.com/kolaente/gite…
kolaente Jun 17, 2018
1884670
DO NOTHING BUT TRIGGER THAT F*CKIN CI SO IT PICKS UP THE LATEST COMMI…
kolaente Jun 17, 2018
d946547
DO NOTHING BUT TRIGGER THAT F*CKIN CI SO IT PICKS UP THE LATEST COMMI…
kolaente Jun 17, 2018
6b6203e
Merge branch 'master' into issue-due-date-api
kolaente Jun 19, 2018
10aa70e
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Jun 20, 2018
75ff80d
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
jonasfranz Jul 5, 2018
980880c
Merge branch 'master' into issue-due-date-api
lafriks Jul 13, 2018
6396a6f
Merge branch 'master' of github.com:go-gitea/gitea into issue-due-dat…
kolaente Jul 15, 2018
d0c94ec
regenerated stylesheets
kolaente Jul 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ issues.due_date_added = "added the due date %s %s"
issues.due_date_modified = "modified the due date to %s from %s %s"
issues.due_date_remove = "removed the due date %s %s"
issues.due_date_overdue = "Overdue"
issues.due_date_invalid = "The due date is invalid or out of range. Please use the format yyyy-mm-dd."

pulls.desc = Enable merge requests and code reviews.
pulls.new = New Pull Request
Expand Down
2 changes: 1 addition & 1 deletion public/css/index.css

Large diffs are not rendered by default.

44 changes: 37 additions & 7 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2375,14 +2375,44 @@ function initTopicbar() {
},
});
}
function toggleDuedateForm() {
$('#add_deadline_form').fadeToggle(150);
function toggleDeadlineForm() {
$('#deadlineForm').fadeToggle(150);
}

function deleteDueDate(url) {
$.post(url, {
'_csrf': csrf,
},function( data ) {
window.location.reload();
function setDeadline() {
var deadline = $('#deadlineDate').val();
updateDeadline(deadline);
}

function updateDeadline(deadlineString) {
$('#deadline-err-invalid-date').hide();
$('#deadline-loader').addClass('loading');

var realDeadline = null;
if (deadlineString !== '') {

var newDate = Date.parse(deadlineString)

if (isNaN(newDate)) {
$('#deadline-loader').removeClass('loading');
$('#deadline-err-invalid-date').show();
return false;
}
realDeadline = new Date(newDate);
}

$.ajax($('#update-issue-deadline-form').attr('action') + '/deadline', {
data: JSON.stringify({
'due_date': realDeadline,
}),
contentType: 'application/json',
type: 'POST',
success: function () {
window.location.reload();
},
error: function () {
$('#deadline-loader').removeClass('loading');
$('#deadline-err-invalid-date').show();
}
});
}
7 changes: 7 additions & 0 deletions public/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
}
}
}

#deadlineForm input{
width: 12.8rem;
border-radius: 4px 0 0 4px;
border-right: 0;
white-space: nowrap;
}
}
.header-wrapper {
background-color: #FAFAFA;
Expand Down
95 changes: 95 additions & 0 deletions public/swagger.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,68 @@
}
}
},
"/repos/{owner}/{repo}/issues/{index}/deadline": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"issue"
],
"summary": "Set an issue deadline. If set to null, the deadline is deleted.",
"operationId": "issueEditIssueDeadline",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "index of the issue to create or update a deadline on",
"name": "index",
"in": "path",
"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"
}
}
}
}
},
"/repos/{owner}/{repo}/issues/{index}/labels": {
"get": {
"produces": [
Expand Down Expand Up @@ -6112,6 +6174,21 @@
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
},
"EditDeadlineOption": {
"description": "EditDeadlineOption options for creating a deadline",
"type": "object",
"required": [
"due_date"
],
"properties": {
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
}
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
},
"EditHookOption": {
"description": "EditHookOption options when modify one hook",
"type": "object",
Expand Down Expand Up @@ -6602,6 +6679,18 @@
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
},
"IssueDeadline": {
"description": "IssueDeadline represents an issue deadline",
"type": "object",
"properties": {
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
}
},
"x-go-package": "code.gitea.io/gitea/vendor/code.gitea.io/sdk/gitea"
},
"IssueLabelsOption": {
"description": "IssueLabelsOption a collection of labels",
"type": "object",
Expand Down Expand Up @@ -7598,6 +7687,12 @@
"$ref": "#/definitions/Issue"
}
},
"IssueDeadline": {
"description": "IssueDeadline",
"schema": {
"$ref": "#/definitions/IssueDeadline"
}
},
"IssueList": {
"description": "IssueList",
"schema": {
Expand Down
2 changes: 2 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,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() {
Expand Down
71 changes: 70 additions & 1 deletion routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to validation function of the form.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What validation in what form? You mean the form I use to change the deadline in the frontend?

deadlineUnix = util.TimeStamp(form.Deadline.Unix())
}

Expand Down Expand Up @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to validation function of form.

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})
}
7 changes: 7 additions & 0 deletions routers/api/v1/swagger/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 2 additions & 0 deletions routers/api/v1/swagger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 0 additions & 48 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1490,51 +1490,3 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
"html": html,
})
}

// UpdateDeadline adds or updates a deadline
func UpdateDeadline(ctx *context.Context, form auth.DeadlineForm) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}

if ctx.HasError() {
ctx.ServerError("ChangeIssueDeadline", errors.New(ctx.GetErrMsg()))
return
}

// Make unix of deadline string
deadline, err := time.ParseInLocation("2006-01-02", form.DateString, time.Local)
if err != nil {
ctx.Flash.Error(ctx.Tr("repo.issues.invalid_due_date_format"))
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
return
}

if err = models.UpdateIssueDeadline(issue, util.TimeStamp(deadline.Unix()), ctx.User); err != nil {
ctx.Flash.Error(ctx.Tr("repo.issues.error_modifying_due_date"))
}

ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
return
}

// RemoveDeadline removes a deadline
func RemoveDeadline(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}

if ctx.HasError() {
ctx.ServerError("RemoveIssueDeadline", errors.New(ctx.GetErrMsg()))
return
}

if err := models.UpdateIssueDeadline(issue, 0, ctx.User); err != nil {
ctx.Flash.Error(ctx.Tr("repo.issues.error_removing_due_date"))
}

ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
return
}
2 changes: 0 additions & 2 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ func RegisterRoutes(m *macaron.Macaron) {
})
})
m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction)
m.Post("/deadline/update", reqRepoWriter, bindIgnErr(auth.DeadlineForm{}), repo.UpdateDeadline)
m.Post("/deadline/delete", reqRepoWriter, repo.RemoveDeadline)
})

m.Post("/labels", reqRepoWriter, repo.UpdateIssueLabel)
Expand Down
Loading