mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Add UI to delete tracked times (#14100)
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
6a696b93b1
commit
d38ae597e1
13 changed files with 123 additions and 4 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue