Issue due date (#3794)
* Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
This commit is contained in:
parent
85d14cc229
commit
1a97030017
22 changed files with 416 additions and 45 deletions
|
@ -163,12 +163,19 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
// responses:
|
||||
// "201":
|
||||
// "$ref": "#/responses/Issue"
|
||||
|
||||
var deadlineUnix util.TimeStamp
|
||||
if form.Deadline != nil {
|
||||
deadlineUnix = util.TimeStamp(form.Deadline.Unix())
|
||||
}
|
||||
|
||||
issue := &models.Issue{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
Content: form.Body,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
Content: form.Body,
|
||||
DeadlineUnix: deadlineUnix,
|
||||
}
|
||||
|
||||
if ctx.Repo.IsWriter() {
|
||||
|
@ -265,6 +272,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
issue.Content = *form.Body
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if ctx.Repo.IsWriter() && form.Assignee != nil &&
|
||||
(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) {
|
||||
if len(*form.Assignee) == 0 {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
@ -236,16 +237,22 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
|||
return
|
||||
}
|
||||
|
||||
var deadlineUnix util.TimeStamp
|
||||
if form.Deadline != nil {
|
||||
deadlineUnix = util.TimeStamp(form.Deadline.Unix())
|
||||
}
|
||||
|
||||
prIssue := &models.Issue{
|
||||
RepoID: repo.ID,
|
||||
Index: repo.NextIssueIndex(),
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
MilestoneID: milestoneID,
|
||||
AssigneeID: assigneeID,
|
||||
IsPull: true,
|
||||
Content: form.Body,
|
||||
RepoID: repo.ID,
|
||||
Index: repo.NextIssueIndex(),
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
MilestoneID: milestoneID,
|
||||
AssigneeID: assigneeID,
|
||||
IsPull: true,
|
||||
Content: form.Body,
|
||||
DeadlineUnix: deadlineUnix,
|
||||
}
|
||||
pr := &models.PullRequest{
|
||||
HeadRepoID: headRepo.ID,
|
||||
|
@ -328,6 +335,16 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
|||
issue.Content = form.Body
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if ctx.Repo.IsWriter() && len(form.Assignee) > 0 &&
|
||||
(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(form.Assignee)) {
|
||||
if len(form.Assignee) == 0 {
|
||||
|
|
|
@ -1467,3 +1467,51 @@ 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
|
||||
}
|
||||
|
|
|
@ -496,6 +496,8 @@ 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue