mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
121 lines
2.7 KiB
Go
121 lines
2.7 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/hanzoai/git/models/db"
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
"github.com/hanzoai/git/modules/util"
|
|
"github.com/hanzoai/git/modules/web"
|
|
"github.com/hanzoai/git/services/context"
|
|
"github.com/hanzoai/git/services/forms"
|
|
issue_service "github.com/hanzoai/git/services/issue"
|
|
)
|
|
|
|
// AddTimeManually tracks time manually
|
|
func AddTimeManually(c *context.Context) {
|
|
form := web.GetForm(c).(*forms.AddTimeManuallyForm)
|
|
issue := GetActionIssue(c)
|
|
if c.Written() {
|
|
return
|
|
}
|
|
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
|
|
c.NotFound(nil)
|
|
return
|
|
}
|
|
|
|
if c.HasError() {
|
|
c.JSONError(c.GetErrMsg())
|
|
return
|
|
}
|
|
|
|
total := time.Duration(form.Hours)*time.Hour + time.Duration(form.Minutes)*time.Minute
|
|
|
|
if total <= 0 {
|
|
c.JSONError(c.Tr("repo.issues.add_time_sum_to_small"))
|
|
return
|
|
}
|
|
|
|
if _, err := issues_model.AddTime(c, c.Doer, issue, int64(total.Seconds()), time.Now()); err != nil {
|
|
c.ServerError("AddTime", err)
|
|
return
|
|
}
|
|
|
|
c.JSONRedirect("")
|
|
}
|
|
|
|
// DeleteTime deletes tracked time
|
|
func DeleteTime(c *context.Context) {
|
|
issue := GetActionIssue(c)
|
|
if c.Written() {
|
|
return
|
|
}
|
|
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
|
|
c.NotFound(nil)
|
|
return
|
|
}
|
|
|
|
t, err := issues_model.GetTrackedTimeByID(c, issue.ID, c.PathParamInt64("timeid"))
|
|
if err != nil {
|
|
if db.IsErrNotExist(err) {
|
|
c.NotFound(err)
|
|
return
|
|
}
|
|
c.HTTPError(http.StatusInternalServerError, "GetTrackedTimeByID", err.Error())
|
|
return
|
|
}
|
|
|
|
// only OP or admin may delete
|
|
if !c.IsSigned || (!c.IsUserSiteAdmin() && c.Doer.ID != t.UserID) {
|
|
c.HTTPError(http.StatusForbidden, "not allowed")
|
|
return
|
|
}
|
|
|
|
if err = issues_model.DeleteTime(c, t); err != nil {
|
|
c.ServerError("DeleteTime", err)
|
|
return
|
|
}
|
|
|
|
c.Flash.Success(c.Tr("repo.issues.del_time_history", util.SecToHours(t.Time)))
|
|
c.JSONRedirect("")
|
|
}
|
|
|
|
func UpdateIssueTimeEstimate(ctx *context.Context) {
|
|
issue := GetActionIssue(ctx)
|
|
if ctx.Written() {
|
|
return
|
|
}
|
|
|
|
if !ctx.IsSigned || (!issue.IsPoster(ctx.Doer.ID) && !ctx.Repo.Permission.CanWriteIssuesOrPulls(issue.IsPull)) {
|
|
ctx.HTTPError(http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
timeStr := strings.TrimSpace(ctx.FormString("time_estimate"))
|
|
|
|
total, err := util.TimeEstimateParse(timeStr)
|
|
if err != nil {
|
|
ctx.JSONError(ctx.Tr("repo.issues.time_estimate_invalid"))
|
|
return
|
|
}
|
|
|
|
// No time changed
|
|
if issue.TimeEstimate == total {
|
|
ctx.JSONRedirect("")
|
|
return
|
|
}
|
|
|
|
if err := issue_service.ChangeTimeEstimate(ctx, issue, ctx.Doer, total); err != nil {
|
|
ctx.ServerError("ChangeTimeEstimate", err)
|
|
return
|
|
}
|
|
|
|
ctx.JSONRedirect("")
|
|
}
|