summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorNorwin <noerw@users.noreply.github.com>2021-02-19 10:52:11 +0000
committerGitHub <noreply@github.com>2021-02-19 12:52:11 +0200
commitd38ae597e19f58bcd732717fe09c1ea97ab8bb12 (patch)
tree839f0b3c92a4b98a7be3b8aa316925615c16c76e /routers
parent6a696b93b1e7e9dc1e7cc51d4eab2932b072170f (diff)
downloadgitea-d38ae597e19f58bcd732717fe09c1ea97ab8bb12.tar.gz
gitea-d38ae597e19f58bcd732717fe09c1ea97ab8bb12.zip
Add UI to delete tracked times (#14100)
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go4
-rw-r--r--routers/repo/issue_timetrack.go40
-rw-r--r--routers/routes/web.go1
3 files changed, 43 insertions, 2 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index fa1ee99771..a9459a10ed 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -1416,6 +1416,10 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("LoadPushCommits", err)
return
}
+ } else if comment.Type == models.CommentTypeAddTimeManual ||
+ comment.Type == models.CommentTypeStopTracking {
+ // drop error since times could be pruned from DB..
+ _ = comment.LoadTime()
}
}
diff --git a/routers/repo/issue_timetrack.go b/routers/repo/issue_timetrack.go
index 425f215110..3b13770d61 100644
--- a/routers/repo/issue_timetrack.go
+++ b/routers/repo/issue_timetrack.go
@@ -10,13 +10,13 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
+ "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/web"
)
// AddTimeManually tracks time manually
func AddTimeManually(c *context.Context) {
- form := web.GetForm(c).(*auth.AddTimeManuallyForm)
+ form := web.GetForm(c).(*forms.AddTimeManuallyForm)
issue := GetActionIssue(c)
if c.Written() {
return
@@ -48,3 +48,39 @@ func AddTimeManually(c *context.Context) {
c.Redirect(url, http.StatusSeeOther)
}
+
+// DeleteTime deletes tracked time
+func DeleteTime(c *context.Context) {
+ issue := GetActionIssue(c)
+ if c.Written() {
+ return
+ }
+ if !c.Repo.CanUseTimetracker(issue, c.User) {
+ c.NotFound("CanUseTimetracker", nil)
+ return
+ }
+
+ t, err := models.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
+ if err != nil {
+ if models.IsErrNotExist(err) {
+ c.NotFound("time not found", err)
+ return
+ }
+ c.Error(http.StatusInternalServerError, "GetTrackedTimeByID", err.Error())
+ return
+ }
+
+ // only OP or admin may delete
+ if !c.IsSigned || (!c.IsUserSiteAdmin() && c.User.ID != t.UserID) {
+ c.Error(http.StatusForbidden, "not allowed")
+ return
+ }
+
+ if err = models.DeleteTime(t); err != nil {
+ c.ServerError("DeleteTime", err)
+ return
+ }
+
+ c.Flash.Success(c.Tr("repo.issues.del_time_history", models.SecToTime(t.Time)))
+ c.Redirect(issue.HTMLURL())
+}
diff --git a/routers/routes/web.go b/routers/routes/web.go
index b3edd8f713..dd43663e35 100644
--- a/routers/routes/web.go
+++ b/routers/routes/web.go
@@ -723,6 +723,7 @@ func RegisterRoutes(m *web.Route) {
m.Combo("/comments").Post(repo.MustAllowUserComment, bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
m.Group("/times", func() {
m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually)
+ m.Post("/{timeid}/delete", repo.DeleteTime)
m.Group("/stopwatch", func() {
m.Post("/toggle", repo.IssueStopwatch)
m.Post("/cancel", repo.CancelStopwatch)