From 15cba1514106ead216a5fc4b3d9de666cbac6cc4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 05:16:04 +0100 Subject: [PATCH 01/76] git ignore fuse tmp files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6f644d1cd7d61..115c9a715302f 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,4 @@ prime/ *.snap-build *_source.tar.bz2 .DS_Store +.fuse_* From 81e5ea63f94fc7e87a77220b05e6387c1d44a55f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 28 Nov 2019 17:55:30 +0100 Subject: [PATCH 02/76] Deprecate old "times" API --- models/issue_tracked_time.go | 6 ++--- modules/structs/issue_tracked_time.go | 8 +++--- routers/api/v1/api.go | 8 +++--- routers/api/v1/repo/issue_tracked_time.go | 32 +++++++++++++---------- routers/api/v1/swagger/issue.go | 16 ++++++------ templates/swagger/v1_json.tmpl | 20 ++++++++------ 6 files changed, 49 insertions(+), 41 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index f616836c85e17..a234d3b3bcb28 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -29,9 +29,9 @@ func (t *TrackedTime) AfterLoad() { t.Created = time.Unix(t.CreatedUnix, 0).In(setting.DefaultUILocation) } -// APIFormat converts TrackedTime to API format -func (t *TrackedTime) APIFormat() *api.TrackedTime { - return &api.TrackedTime{ +// APIFormatDeprecated converts TrackedTime to deprecated API format +func (t *TrackedTime) APIFormatDeprecated() *api.TrackedTimeDeprecated { + return &api.TrackedTimeDeprecated{ ID: t.ID, IssueID: t.IssueID, UserID: t.UserID, diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index be90b36267bf3..4c007bf749915 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -8,8 +8,8 @@ import ( "time" ) -// TrackedTime worked time for an issue / pr -type TrackedTime struct { +// TrackedTimeDeprecated worked time for an issue / pr +type TrackedTimeDeprecated struct { ID int64 `json:"id"` // swagger:strfmt date-time Created time.Time `json:"created"` @@ -19,8 +19,8 @@ type TrackedTime struct { IssueID int64 `json:"issue_id"` } -// TrackedTimes represent a list of tracked times -type TrackedTimes []*TrackedTime +// TrackedTimesDeprecated represent a list of tracked times +type TrackedTimesDeprecated []*TrackedTimeDeprecated // AddTimeOption options for adding time to an issue type AddTimeOption struct { diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index cd5fc1f3eb27d..0a14d9c945e56 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -582,7 +582,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Delete("", user.Unstar) }, repoAssignment()) }) - m.Get("/times", repo.ListMyTrackedTimes) + m.Get("/times", repo.ListMyTrackedTimesDeprecated) m.Get("/subscriptions", user.GetMyWatchedRepos) @@ -649,8 +649,8 @@ func RegisterRoutes(m *macaron.Macaron) { Delete(repo.DeleteDeploykey) }, reqToken(), reqAdmin()) m.Group("/times", func() { - m.Combo("").Get(repo.ListTrackedTimesByRepository) - m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUser) + m.Combo("").Get(repo.ListTrackedTimesByRepositoryDeprecated) + m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUserDeprecated) }, mustEnableIssues) m.Group("/issues", func() { m.Combo("").Get(repo.ListIssues). @@ -684,7 +684,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Delete("/:id", reqToken(), repo.DeleteIssueLabel) }) m.Group("/times", func() { - m.Combo("").Get(repo.ListTrackedTimes). + m.Combo("").Get(repo.ListTrackedTimesDeprecated). Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTime) }) m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index c38ea05c363f7..0d2daa7db6035 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -10,19 +10,20 @@ import ( api "code.gitea.io/gitea/modules/structs" ) -func trackedTimesToAPIFormat(trackedTimes []*models.TrackedTime) []*api.TrackedTime { - apiTrackedTimes := make([]*api.TrackedTime, len(trackedTimes)) +func trackedTimesToAPIFormatDeprecated(trackedTimes []*models.TrackedTime) []*api.TrackedTimeDeprecated { + apiTrackedTimes := make([]*api.TrackedTimeDeprecated, len(trackedTimes)) for i, trackedTime := range trackedTimes { - apiTrackedTimes[i] = trackedTime.APIFormat() + apiTrackedTimes[i] = trackedTime.APIFormatDeprecated() } return apiTrackedTimes } // ListTrackedTimes list all the tracked times of an issue -func ListTrackedTimes(ctx *context.APIContext) { +func ListTrackedTimesDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/issues/{id}/times issue issueTrackedTimes // --- // summary: List an issue's tracked times + // deprecated: true // produces: // - application/json // parameters: @@ -64,7 +65,7 @@ func ListTrackedTimes(ctx *context.APIContext) { ctx.Error(500, "GetTrackedTimesByIssue", err) return } - apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes) + apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) ctx.JSON(200, &apiTrackedTimes) } @@ -100,7 +101,7 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { // "$ref": "#/definitions/AddTimeOption" // responses: // "200": - // "$ref": "#/responses/TrackedTime" + // "$ref": "#/responses/empty" // "400": // "$ref": "#/responses/error" // "403": @@ -123,19 +124,20 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { ctx.Status(403) return } - trackedTime, err := models.AddTime(ctx.User, issue, form.Time) + _, err = models.AddTime(ctx.User, issue, form.Time) if err != nil { ctx.Error(500, "AddTime", err) return } - ctx.JSON(200, trackedTime.APIFormat()) + ctx.Status(200) } // ListTrackedTimesByUser lists all tracked times of the user -func ListTrackedTimesByUser(ctx *context.APIContext) { +func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times/{user} user userTrackedTimes // --- // summary: List a user's tracked times in a repo + // deprecated: true // produces: // - application/json // parameters: @@ -181,15 +183,16 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { ctx.Error(500, "GetTrackedTimesByUser", err) return } - apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes) + apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) ctx.JSON(200, &apiTrackedTimes) } // ListTrackedTimesByRepository lists all tracked times of the repository -func ListTrackedTimesByRepository(ctx *context.APIContext) { +func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times repository repoTrackedTimes // --- // summary: List a repo's tracked times + // deprecated: true // produces: // - application/json // parameters: @@ -216,15 +219,16 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { ctx.Error(500, "GetTrackedTimesByUser", err) return } - apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes) + apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) ctx.JSON(200, &apiTrackedTimes) } // ListMyTrackedTimes lists all tracked times of the current user -func ListMyTrackedTimes(ctx *context.APIContext) { +func ListMyTrackedTimesDeprecated(ctx *context.APIContext) { // swagger:operation GET /user/times user userCurrentTrackedTimes // --- // summary: List the current user's tracked times + // deprecated: true // produces: // - application/json // responses: @@ -235,6 +239,6 @@ func ListMyTrackedTimes(ctx *context.APIContext) { ctx.Error(500, "GetTrackedTimesByUser", err) return } - apiTrackedTimes := trackedTimesToAPIFormat(trackedTimes) + apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) ctx.JSON(200, &apiTrackedTimes) } diff --git a/routers/api/v1/swagger/issue.go b/routers/api/v1/swagger/issue.go index a78c2982fd706..2799ef6c83689 100644 --- a/routers/api/v1/swagger/issue.go +++ b/routers/api/v1/swagger/issue.go @@ -64,18 +64,18 @@ type swaggerResponseMilestoneList struct { Body []api.Milestone `json:"body"` } -// TrackedTime -// swagger:response TrackedTime -type swaggerResponseTrackedTime struct { +// TrackedTimeDeprecated +// swagger:response TrackedTimeDeprecated +type swaggerResponseTrackedTimeDeprecated struct { // in:body - Body api.TrackedTime `json:"body"` + Body api.TrackedTimeDeprecated `json:"body"` } -// TrackedTimeList -// swagger:response TrackedTimeList -type swaggerResponseTrackedTimeList struct { +// TrackedTimeListDeprecated +// swagger:response TrackedTimeListDeprecated +type swaggerResponseTrackedTimeListDeprecated struct { // in:body - Body []api.TrackedTime `json:"body"` + Body []api.TrackedTimeDeprecated `json:"body"` } // IssueDeadline diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 9c8db28817aba..be385dd709f3c 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3168,6 +3168,7 @@ ], "summary": "List an issue's tracked times", "operationId": "issueTrackedTimes", + "deprecated": true, "parameters": [ { "type": "string", @@ -3243,7 +3244,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTime" + "$ref": "#/responses/empty" }, "400": { "$ref": "#/responses/error" @@ -5994,6 +5995,7 @@ ], "summary": "List a repo's tracked times", "operationId": "repoTrackedTimes", + "deprecated": true, "parameters": [ { "type": "string", @@ -6027,6 +6029,7 @@ ], "summary": "List a user's tracked times in a repo", "operationId": "userTrackedTimes", + "deprecated": true, "parameters": [ { "type": "string", @@ -7218,6 +7221,7 @@ ], "summary": "List the current user's tracked times", "operationId": "userCurrentTrackedTimes", + "deprecated": true, "responses": { "200": { "$ref": "#/responses/TrackedTimeList" @@ -10943,7 +10947,7 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "TrackedTime": { + "TrackedTimeDeprecated": { "description": "TrackedTime worked time for an issue / pr", "type": "object", "properties": { @@ -11598,18 +11602,18 @@ "$ref": "#/definitions/TopicName" } }, - "TrackedTime": { - "description": "TrackedTime", + "TrackedTimeDeprecated": { + "description": "TrackedTimeDeprecated", "schema": { - "$ref": "#/definitions/TrackedTime" + "$ref": "#/definitions/TrackedTimeDeprecated" } }, - "TrackedTimeList": { - "description": "TrackedTimeList", + "TrackedTimeListDeprecated": { + "description": "TrackedTimeListDeprecated", "schema": { "type": "array", "items": { - "$ref": "#/definitions/TrackedTime" + "$ref": "#/definitions/TrackedTimeDeprecated" } } }, From e14d62b3c2f7c55e6e9ec37662d93ced6847fae3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 28 Nov 2019 18:25:14 +0100 Subject: [PATCH 03/76] add new times api struct --- models/issue_tracked_time.go | 43 ++++++++++++- modules/structs/issue_tracked_time.go | 17 ++++++ routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 27 +++++---- routers/api/v1/swagger/issue.go | 14 +++++ templates/swagger/v1_json.tmpl | 74 +++++++++++++++++++++-- 6 files changed, 156 insertions(+), 21 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index a234d3b3bcb28..364674c80d581 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -24,6 +24,9 @@ type TrackedTime struct { Time int64 `json:"time"` } +// TrackedTimeList is a List ful of TrackedTime's +type TrackedTimeList []*TrackedTime + // AfterLoad is invoked from XORM after setting the values of all fields of this object. func (t *TrackedTime) AfterLoad() { t.Created = time.Unix(t.CreatedUnix, 0).In(setting.DefaultUILocation) @@ -40,6 +43,44 @@ func (t *TrackedTime) APIFormatDeprecated() *api.TrackedTimeDeprecated { } } +// APIFormat converts TrackedTime to API format +func (t *TrackedTime) APIFormat() *api.TrackedTime { + user, err := GetUserByID(t.UserID) + if err != nil { + return nil + } + issue, err := GetIssueByID(t.IssueID) + if err != nil { + return nil + } + err = issue.LoadRepo() + if err != nil { + return nil + } + return &api.TrackedTime{ + ID: t.ID, + IssueID: t.IssueID, + IssueIndex: issue.Index, + UserID: t.UserID, + UserName: user.Name, + Time: t.Time, + Created: t.Created, + Repo: issue.Repo.FullName(), + } +} + +// APIFormat converts TrackedTime to API format +func (tl TrackedTimeList) APIFormat() api.TrackedTimeList { + var result api.TrackedTimeList + for _, t := range tl { + i := t.APIFormat() + if i != nil { + result = append(result, i) + } + } + return result +} + // FindTrackedTimesOptions represent the filters for tracked times. If an ID is 0 it will be ignored. type FindTrackedTimesOptions struct { IssueID int64 @@ -75,7 +116,7 @@ func (opts *FindTrackedTimesOptions) ToSession(e Engine) *xorm.Session { } // GetTrackedTimes returns all tracked times that fit to the given options. -func GetTrackedTimes(options FindTrackedTimesOptions) (trackedTimes []*TrackedTime, err error) { +func GetTrackedTimes(options FindTrackedTimesOptions) (trackedTimes TrackedTimeList, err error) { err = options.ToSession(x).Find(&trackedTimes) return } diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index 4c007bf749915..754c06b16b2e5 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -28,3 +28,20 @@ type AddTimeOption struct { // required: true Time int64 `json:"time" binding:"Required"` } + +// TrackedTime worked time for an issue / pr +type TrackedTime struct { + ID int64 `json:"id"` + // swagger:strfmt date-time + Created time.Time `json:"created"` + // Time in seconds + Time int64 `json:"time"` + UserID int64 `json:"user_id"` + UserName string `json:"user_name"` + IssueID int64 `json:"issue_id"` + IssueIndex int64 `json:"issue_index"` + Repo string `json:"repository"` +} + +// TrackedTimeList represent a list of tracked times +type TrackedTimeList []*TrackedTime diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 0a14d9c945e56..57a68195b1783 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -685,7 +685,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Group("/times", func() { m.Combo("").Get(repo.ListTrackedTimesDeprecated). - Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTime) + Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTimeDeprecated) }) m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) m.Group("/stopwatch", func() { diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 0d2daa7db6035..126eca1f45522 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -18,7 +18,7 @@ func trackedTimesToAPIFormatDeprecated(trackedTimes []*models.TrackedTime) []*ap return apiTrackedTimes } -// ListTrackedTimes list all the tracked times of an issue +// ListTrackedTimesDeprecated list all the tracked times of an issue func ListTrackedTimesDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/issues/{id}/times issue issueTrackedTimes // --- @@ -45,7 +45,7 @@ func ListTrackedTimesDeprecated(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeList" + // "$ref": "#/responses/TrackedTimeListDeprecated" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.NotFound("Timetracker is disabled") return @@ -69,11 +69,12 @@ func ListTrackedTimesDeprecated(ctx *context.APIContext) { ctx.JSON(200, &apiTrackedTimes) } -// AddTime adds time manual to the given issue -func AddTime(ctx *context.APIContext, form api.AddTimeOption) { +// AddTimeDeprecated adds time manual to the given issue +func AddTimeDeprecated(ctx *context.APIContext, form api.AddTimeOption) { // swagger:operation Post /repos/{owner}/{repo}/issues/{id}/times issue issueAddTime // --- // summary: Add a tracked time to a issue + // deprecated: true // consumes: // - application/json // produces: @@ -101,7 +102,7 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { // "$ref": "#/definitions/AddTimeOption" // responses: // "200": - // "$ref": "#/responses/empty" + // "$ref": "#/responses/TrackedTimeDeprecated" // "400": // "$ref": "#/responses/error" // "403": @@ -124,15 +125,15 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { ctx.Status(403) return } - _, err = models.AddTime(ctx.User, issue, form.Time) + trackedTime, err := models.AddTime(ctx.User, issue, form.Time) if err != nil { ctx.Error(500, "AddTime", err) return } - ctx.Status(200) + ctx.JSON(200, trackedTime.APIFormatDeprecated()) } -// ListTrackedTimesByUser lists all tracked times of the user +// ListTrackedTimesByUserDeprecated lists all tracked times of the user func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times/{user} user userTrackedTimes // --- @@ -158,7 +159,7 @@ func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeList" + // "$ref": "#/responses/TrackedTimeListDeprecated" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) return @@ -187,7 +188,7 @@ func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { ctx.JSON(200, &apiTrackedTimes) } -// ListTrackedTimesByRepository lists all tracked times of the repository +// ListTrackedTimesByRepositoryDeprecated lists all tracked times of the repository func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times repository repoTrackedTimes // --- @@ -208,7 +209,7 @@ func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeList" + // "$ref": "#/responses/TrackedTimeListDeprecated" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) return @@ -223,7 +224,7 @@ func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { ctx.JSON(200, &apiTrackedTimes) } -// ListMyTrackedTimes lists all tracked times of the current user +// ListMyTrackedTimesDeprecated lists all tracked times of the current user func ListMyTrackedTimesDeprecated(ctx *context.APIContext) { // swagger:operation GET /user/times user userCurrentTrackedTimes // --- @@ -233,7 +234,7 @@ func ListMyTrackedTimesDeprecated(ctx *context.APIContext) { // - application/json // responses: // "200": - // "$ref": "#/responses/TrackedTimeList" + // "$ref": "#/responses/TrackedTimeListDeprecated" trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: ctx.User.ID}) if err != nil { ctx.Error(500, "GetTrackedTimesByUser", err) diff --git a/routers/api/v1/swagger/issue.go b/routers/api/v1/swagger/issue.go index 2799ef6c83689..b7f485e9896e7 100644 --- a/routers/api/v1/swagger/issue.go +++ b/routers/api/v1/swagger/issue.go @@ -78,6 +78,20 @@ type swaggerResponseTrackedTimeListDeprecated struct { Body []api.TrackedTimeDeprecated `json:"body"` } +// TrackedTime +// swagger:response TrackedTime +type swaggerResponseTrackedTime struct { + // in:body + Body api.TrackedTime `json:"body"` +} + +// TrackedTimeList +// swagger:response TrackedTimeList +type swaggerResponseTrackedTimeList struct { + // in:body + Body []api.TrackedTime `json:"body"` +} + // IssueDeadline // swagger:response IssueDeadline type swaggerIssueDeadline struct { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index be385dd709f3c..9427e459cd29d 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3195,7 +3195,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTimeList" + "$ref": "#/responses/TrackedTimeListDeprecated" } } }, @@ -3211,6 +3211,7 @@ ], "summary": "Add a tracked time to a issue", "operationId": "issueAddTime", + "deprecated": true, "parameters": [ { "type": "string", @@ -3244,7 +3245,7 @@ ], "responses": { "200": { - "$ref": "#/responses/empty" + "$ref": "#/responses/TrackedTimeDeprecated" }, "400": { "$ref": "#/responses/error" @@ -6014,7 +6015,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTimeList" + "$ref": "#/responses/TrackedTimeListDeprecated" } } } @@ -6055,7 +6056,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTimeList" + "$ref": "#/responses/TrackedTimeListDeprecated" } } } @@ -7224,7 +7225,7 @@ "deprecated": true, "responses": { "200": { - "$ref": "#/responses/TrackedTimeList" + "$ref": "#/responses/TrackedTimeListDeprecated" } } } @@ -10947,9 +10948,55 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "TrackedTimeDeprecated": { + "TrackedTime": { "description": "TrackedTime worked time for an issue / pr", "type": "object", + "properties": { + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "issue_id": { + "type": "integer", + "format": "int64", + "x-go-name": "IssueID" + }, + "issue_index": { + "type": "integer", + "format": "int64", + "x-go-name": "IssueIndex" + }, + "repository": { + "type": "string", + "x-go-name": "Repo" + }, + "time": { + "description": "Time in seconds", + "type": "integer", + "format": "int64", + "x-go-name": "Time" + }, + "user_id": { + "type": "integer", + "format": "int64", + "x-go-name": "UserID" + }, + "user_name": { + "type": "string", + "x-go-name": "UserName" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, + "TrackedTimeDeprecated": { + "description": "TrackedTimeDeprecated worked time for an issue / pr", + "type": "object", "properties": { "created": { "type": "string", @@ -11602,12 +11649,27 @@ "$ref": "#/definitions/TopicName" } }, + "TrackedTime": { + "description": "TrackedTime", + "schema": { + "$ref": "#/definitions/TrackedTime" + } + }, "TrackedTimeDeprecated": { "description": "TrackedTimeDeprecated", "schema": { "$ref": "#/definitions/TrackedTimeDeprecated" } }, + "TrackedTimeList": { + "description": "TrackedTimeList", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/TrackedTime" + } + } + }, "TrackedTimeListDeprecated": { "description": "TrackedTimeListDeprecated", "schema": { From 79468291903fe0270c2b59bae9845d9f4aa6404f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 07:09:37 +0100 Subject: [PATCH 04/76] update "GET /user/times" --- routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 10 ++++------ templates/swagger/v1_json.tmpl | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 57a68195b1783..af708b72bc1d9 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -582,7 +582,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Delete("", user.Unstar) }, repoAssignment()) }) - m.Get("/times", repo.ListMyTrackedTimesDeprecated) + m.Get("/times", repo.ListMyTrackedTimes) m.Get("/subscriptions", user.GetMyWatchedRepos) diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 126eca1f45522..d7d70923d6ba2 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -224,22 +224,20 @@ func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { ctx.JSON(200, &apiTrackedTimes) } -// ListMyTrackedTimesDeprecated lists all tracked times of the current user -func ListMyTrackedTimesDeprecated(ctx *context.APIContext) { +// ListMyTrackedTimes lists all tracked times of the current user +func ListMyTrackedTimes(ctx *context.APIContext) { // swagger:operation GET /user/times user userCurrentTrackedTimes // --- // summary: List the current user's tracked times - // deprecated: true // produces: // - application/json // responses: // "200": - // "$ref": "#/responses/TrackedTimeListDeprecated" + // "$ref": "#/responses/TrackedTimeList" trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: ctx.User.ID}) if err != nil { ctx.Error(500, "GetTrackedTimesByUser", err) return } - apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) - ctx.JSON(200, &apiTrackedTimes) + ctx.JSON(200, trackedTimes.APIFormat()) } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 9427e459cd29d..0b6fe9fa64b47 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -7222,10 +7222,9 @@ ], "summary": "List the current user's tracked times", "operationId": "userCurrentTrackedTimes", - "deprecated": true, "responses": { "200": { - "$ref": "#/responses/TrackedTimeListDeprecated" + "$ref": "#/responses/TrackedTimeList" } } } From d8c0c4ebba27719e4e25b0b2cca3595a7497ec28 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 07:22:52 +0100 Subject: [PATCH 05/76] update "GET /repos/{owner}/{repo}/times" --- routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 24 ++++++++++++++--------- templates/swagger/v1_json.tmpl | 3 +-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index af708b72bc1d9..238d6e82b1612 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -649,7 +649,7 @@ func RegisterRoutes(m *macaron.Macaron) { Delete(repo.DeleteDeploykey) }, reqToken(), reqAdmin()) m.Group("/times", func() { - m.Combo("").Get(repo.ListTrackedTimesByRepositoryDeprecated) + m.Combo("").Get(repo.ListTrackedTimesByRepository) m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUserDeprecated) }, mustEnableIssues) m.Group("/issues", func() { diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index d7d70923d6ba2..1a4c993f7745a 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -188,12 +188,11 @@ func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { ctx.JSON(200, &apiTrackedTimes) } -// ListTrackedTimesByRepositoryDeprecated lists all tracked times of the repository -func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { +// ListTrackedTimesByRepository lists all tracked times of the repository +func ListTrackedTimesByRepository(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times repository repoTrackedTimes // --- // summary: List a repo's tracked times - // deprecated: true // produces: // - application/json // parameters: @@ -209,19 +208,26 @@ func ListTrackedTimesByRepositoryDeprecated(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeListDeprecated" + // "$ref": "#/responses/TrackedTimeList" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) return } - trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{ - RepositoryID: ctx.Repo.Repository.ID}) + + opts := models.FindTrackedTimesOptions{ + RepositoryID: ctx.Repo.Repository.ID, + } + + if !ctx.IsUserRepoAdmin() && !ctx.User.IsAdmin { + opts.UserID = ctx.User.ID + } + + trackedTimes, err := models.GetTrackedTimes(opts) if err != nil { - ctx.Error(500, "GetTrackedTimesByUser", err) + ctx.Error(500, "GetTrackedTimes", err) return } - apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) - ctx.JSON(200, &apiTrackedTimes) + ctx.JSON(200, trackedTimes.APIFormat()) } // ListMyTrackedTimes lists all tracked times of the current user diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 0b6fe9fa64b47..b373715524dfd 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5996,7 +5996,6 @@ ], "summary": "List a repo's tracked times", "operationId": "repoTrackedTimes", - "deprecated": true, "parameters": [ { "type": "string", @@ -6015,7 +6014,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTimeListDeprecated" + "$ref": "#/responses/TrackedTimeList" } } } From 760179089153368cf63f33e59cd5b0f052c23acf Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 07:39:37 +0100 Subject: [PATCH 06/76] corect swagger description (id -> index) --- routers/api/v1/api.go | 7 +- routers/api/v1/repo/issue_tracked_time.go | 27 +++++--- templates/swagger/v1_json.tmpl | 81 ++++++++++++----------- 3 files changed, 61 insertions(+), 54 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 238d6e82b1612..687e2ac0041b6 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -683,10 +683,9 @@ func RegisterRoutes(m *macaron.Macaron) { Delete(reqToken(), repo.ClearIssueLabels) m.Delete("/:id", reqToken(), repo.DeleteIssueLabel) }) - m.Group("/times", func() { - m.Combo("").Get(repo.ListTrackedTimesDeprecated). - Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTimeDeprecated) - }) + m.Combo("/times", reqToken()). + Get(repo.ListTrackedTimes). + Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTimeDeprecated) m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) m.Group("/stopwatch", func() { m.Post("/start", reqToken(), repo.StartIssueStopwatch) diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 1a4c993f7745a..b986c62027ed4 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -18,12 +18,11 @@ func trackedTimesToAPIFormatDeprecated(trackedTimes []*models.TrackedTime) []*ap return apiTrackedTimes } -// ListTrackedTimesDeprecated list all the tracked times of an issue -func ListTrackedTimesDeprecated(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/issues/{id}/times issue issueTrackedTimes +// ListTrackedTimes list all the tracked times of an issue +func ListTrackedTimes(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/issues/{index}/times issue issueTrackedTimes // --- // summary: List an issue's tracked times - // deprecated: true // produces: // - application/json // parameters: @@ -37,7 +36,7 @@ func ListTrackedTimesDeprecated(ctx *context.APIContext) { // description: name of the repo // type: string // required: true - // - name: id + // - name: index // in: path // description: index of the issue // type: integer @@ -45,7 +44,7 @@ func ListTrackedTimesDeprecated(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeListDeprecated" + // "$ref": "#/responses/TrackedTimeList" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.NotFound("Timetracker is disabled") return @@ -60,13 +59,21 @@ func ListTrackedTimesDeprecated(ctx *context.APIContext) { return } - trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}) + opts := models.FindTrackedTimesOptions{ + RepositoryID: ctx.Repo.Repository.ID, + IssueID: issue.ID, + } + + if !ctx.IsUserRepoAdmin() && !ctx.User.IsAdmin { + opts.UserID = ctx.User.ID + } + + trackedTimes, err := models.GetTrackedTimes(opts) if err != nil { - ctx.Error(500, "GetTrackedTimesByIssue", err) + ctx.Error(500, "GetTrackedTimes", err) return } - apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) - ctx.JSON(200, &apiTrackedTimes) + ctx.JSON(200, trackedTimes.APIFormat()) } // AddTimeDeprecated adds time manual to the given issue diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index b373715524dfd..37b191a513ba0 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3159,46 +3159,6 @@ } }, "/repos/{owner}/{repo}/issues/{id}/times": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "issue" - ], - "summary": "List an issue's tracked times", - "operationId": "issueTrackedTimes", - "deprecated": true, - "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", - "format": "int64", - "description": "index of the issue", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/TrackedTimeListDeprecated" - } - } - }, "post": { "consumes": [ "application/json" @@ -4239,6 +4199,47 @@ } } }, + "/repos/{owner}/{repo}/issues/{index}/times": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "issue" + ], + "summary": "List an issue's tracked times", + "operationId": "issueTrackedTimes", + "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", + "format": "int64", + "description": "index of the issue", + "name": "index", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/TrackedTimeList" + } + } + } + }, "/repos/{owner}/{repo}/keys": { "get": { "produces": [ From 7e5b5b01270de55e557b5b14d0724b7451c26530 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 07:47:41 +0100 Subject: [PATCH 07/76] update time POST --- routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 13 ++- templates/swagger/v1_json.tmpl | 113 +++++++++++----------- 3 files changed, 62 insertions(+), 66 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 687e2ac0041b6..37244ed342762 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -685,7 +685,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Combo("/times", reqToken()). Get(repo.ListTrackedTimes). - Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTimeDeprecated) + Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTime) m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) m.Group("/stopwatch", func() { m.Post("/start", reqToken(), repo.StartIssueStopwatch) diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index b986c62027ed4..d8e52038a155a 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -76,12 +76,11 @@ func ListTrackedTimes(ctx *context.APIContext) { ctx.JSON(200, trackedTimes.APIFormat()) } -// AddTimeDeprecated adds time manual to the given issue -func AddTimeDeprecated(ctx *context.APIContext, form api.AddTimeOption) { - // swagger:operation Post /repos/{owner}/{repo}/issues/{id}/times issue issueAddTime +// AddTime adds time manual to the given issue +func AddTime(ctx *context.APIContext, form api.AddTimeOption) { + // swagger:operation Post /repos/{owner}/{repo}/issues/{index}/times issue issueAddTime // --- // summary: Add a tracked time to a issue - // deprecated: true // consumes: // - application/json // produces: @@ -97,7 +96,7 @@ func AddTimeDeprecated(ctx *context.APIContext, form api.AddTimeOption) { // description: name of the repo // type: string // required: true - // - name: id + // - name: index // in: path // description: index of the issue to add tracked time to // type: integer @@ -109,7 +108,7 @@ func AddTimeDeprecated(ctx *context.APIContext, form api.AddTimeOption) { // "$ref": "#/definitions/AddTimeOption" // responses: // "200": - // "$ref": "#/responses/TrackedTimeDeprecated" + // "$ref": "#/responses/TrackedTime" // "400": // "$ref": "#/responses/error" // "403": @@ -137,7 +136,7 @@ func AddTimeDeprecated(ctx *context.APIContext, form api.AddTimeOption) { ctx.Error(500, "AddTime", err) return } - ctx.JSON(200, trackedTime.APIFormatDeprecated()) + ctx.JSON(200, trackedTime.APIFormat()) } // ListTrackedTimesByUserDeprecated lists all tracked times of the user diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 37b191a513ba0..acefd16b8acc1 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3158,64 +3158,6 @@ } } }, - "/repos/{owner}/{repo}/issues/{id}/times": { - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "issue" - ], - "summary": "Add a tracked time to a issue", - "operationId": "issueAddTime", - "deprecated": true, - "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", - "format": "int64", - "description": "index of the issue to add tracked time to", - "name": "id", - "in": "path", - "required": true - }, - { - "name": "body", - "in": "body", - "schema": { - "$ref": "#/definitions/AddTimeOption" - } - } - ], - "responses": { - "200": { - "$ref": "#/responses/TrackedTimeDeprecated" - }, - "400": { - "$ref": "#/responses/error" - }, - "403": { - "$ref": "#/responses/error" - } - } - } - }, "/repos/{owner}/{repo}/issues/{index}": { "get": { "produces": [ @@ -4238,6 +4180,61 @@ "$ref": "#/responses/TrackedTimeList" } } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "issue" + ], + "summary": "Add a tracked time to a issue", + "operationId": "issueAddTime", + "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", + "format": "int64", + "description": "index of the issue to add tracked time to", + "name": "index", + "in": "path", + "required": true + }, + { + "name": "body", + "in": "body", + "schema": { + "$ref": "#/definitions/AddTimeOption" + } + } + ], + "responses": { + "200": { + "$ref": "#/responses/TrackedTime" + }, + "400": { + "$ref": "#/responses/error" + }, + "403": { + "$ref": "#/responses/error" + } + } } }, "/repos/{owner}/{repo}/keys": { From c06805dcfa76189223640fef1cbf304d10afd510 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 08:25:09 +0100 Subject: [PATCH 08/76] add reset func --- models/issue_tracked_time.go | 25 +++++++++ routers/api/v1/repo/issue_tracked_time.go | 63 +++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index 364674c80d581..fe4b58f84695d 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -172,3 +172,28 @@ func TotalTimes(options FindTrackedTimesOptions) (map[*User]string, error) { } return totalTimes, nil } + +// DeleteTimes deletes times for issue +func DeleteTimes(opts FindTrackedTimesOptions) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + ttl, err := GetTrackedTimes(opts) + if err != nil { + return err + } + + if err := deleteTimes(sess, &ttl); err != nil { + return err + } + + return sess.Commit() +} + +func deleteTimes(e *xorm.Session, ttl *TrackedTimeList) error { + _, err := e.Delete(ttl) + return err +} diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index d8e52038a155a..acb96f02b7318 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -139,6 +139,69 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { ctx.JSON(200, trackedTime.APIFormat()) } +// ResetIssueTime reset time manual to the given issue +func ResetIssueTime(ctx *context.APIContext) { + // swagger:operation Delete /repos/{owner}/{repo}/issues/{index}/times issue issueResetTime + // --- + // summary: Reset a tracked time of an issue + // 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 add tracked time to + // type: integer + // format: int64 + // required: true + // responses: + // "200": + // "$ref": "#/responses/empty" + // "400": + // "$ref": "#/responses/error" + // "403": + // "$ref": "#/responses/error" + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrIssueNotExist(err) { + ctx.NotFound(err) + } else { + ctx.Error(500, "GetIssueByIndex", err) + } + return + } + + if !ctx.Repo.CanUseTimetracker(issue, ctx.User) { + if !ctx.Repo.Repository.IsTimetrackerEnabled() { + ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) + return + } + ctx.Status(403) + return + } + + err = models.DeleteTimes(models.FindTrackedTimesOptions{ + IssueID: issue.ID, + UserID: ctx.User.ID, + }) + if err != nil { + ctx.Error(500, "AddTime", err) + return + } + ctx.Status(200) +} + // ListTrackedTimesByUserDeprecated lists all tracked times of the user func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times/{user} user userTrackedTimes From 261222d5f0f6a23482db18bec3943c3f38510878 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 08:33:02 +0100 Subject: [PATCH 09/76] AddTimeOption -> EditTimeOption --- modules/structs/issue_tracked_time.go | 7 +- routers/api/v1/api.go | 3 +- routers/api/v1/repo/issue_tracked_time.go | 15 ++-- routers/api/v1/swagger/options.go | 2 +- templates/swagger/v1_json.tmpl | 90 ++++++++++++++++++----- 5 files changed, 88 insertions(+), 29 deletions(-) diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index 754c06b16b2e5..5d74500dd83b2 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -22,11 +22,12 @@ type TrackedTimeDeprecated struct { // TrackedTimesDeprecated represent a list of tracked times type TrackedTimesDeprecated []*TrackedTimeDeprecated -// AddTimeOption options for adding time to an issue -type AddTimeOption struct { +// EditTimeOption options for adding/deleting time to an issue +type EditTimeOption struct { // time in seconds // required: true - Time int64 `json:"time" binding:"Required"` + Time int64 `json:"time" binding:"Required"` + Negative bool `json:"negative"` } // TrackedTime worked time for an issue / pr diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 37244ed342762..85a8c972b0117 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -685,7 +685,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Combo("/times", reqToken()). Get(repo.ListTrackedTimes). - Post(reqToken(), bind(api.AddTimeOption{}), repo.AddTime) + Post(bind(api.EditTimeOption{}), repo.EditTime). + Delete(repo.ResetIssueTime) m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline) m.Group("/stopwatch", func() { m.Post("/start", reqToken(), repo.StartIssueStopwatch) diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index acb96f02b7318..520bcac736341 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -76,11 +76,11 @@ func ListTrackedTimes(ctx *context.APIContext) { ctx.JSON(200, trackedTimes.APIFormat()) } -// AddTime adds time manual to the given issue -func AddTime(ctx *context.APIContext, form api.AddTimeOption) { - // swagger:operation Post /repos/{owner}/{repo}/issues/{index}/times issue issueAddTime +// EditTime adds/remove time manual to the given issue +func EditTime(ctx *context.APIContext, form api.EditTimeOption) { + // swagger:operation Post /repos/{owner}/{repo}/issues/{index}/times issue issueEditTime // --- - // summary: Add a tracked time to a issue + // summary: Edit the tracked time to a issue // consumes: // - application/json // produces: @@ -105,7 +105,7 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { // - name: body // in: body // schema: - // "$ref": "#/definitions/AddTimeOption" + // "$ref": "#/definitions/EditTimeOption" // responses: // "200": // "$ref": "#/responses/TrackedTime" @@ -131,6 +131,11 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { ctx.Status(403) return } + + if form.Negative { + form.Time = form.Time * -1 + } + trackedTime, err := models.AddTime(ctx.User, issue, form.Time) if err != nil { ctx.Error(500, "AddTime", err) diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go index 80e4bf422a93c..9cd14cf7edfa3 100644 --- a/routers/api/v1/swagger/options.go +++ b/routers/api/v1/swagger/options.go @@ -95,7 +95,7 @@ type swaggerParameterBodies struct { EditTeamOption api.EditTeamOption // in:body - AddTimeOption api.AddTimeOption + EditTimeOption api.EditTimeOption // in:body CreateUserOption api.CreateUserOption diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index acefd16b8acc1..1058a1215887d 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4191,8 +4191,8 @@ "tags": [ "issue" ], - "summary": "Add a tracked time to a issue", - "operationId": "issueAddTime", + "summary": "Edit the tracked time to a issue", + "operationId": "issueEditTime", "parameters": [ { "type": "string", @@ -4220,7 +4220,7 @@ "name": "body", "in": "body", "schema": { - "$ref": "#/definitions/AddTimeOption" + "$ref": "#/definitions/EditTimeOption" } } ], @@ -4235,6 +4235,54 @@ "$ref": "#/responses/error" } } + }, + "delete": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "issue" + ], + "summary": "Reset a tracked time of an issue", + "operationId": "issueResetTime", + "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", + "format": "int64", + "description": "index of the issue to add tracked time to", + "name": "index", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/empty" + }, + "400": { + "$ref": "#/responses/error" + }, + "403": { + "$ref": "#/responses/error" + } + } } }, "/repos/{owner}/{repo}/keys": { @@ -7755,22 +7803,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "AddTimeOption": { - "description": "AddTimeOption options for adding time to an issue", - "type": "object", - "required": [ - "time" - ], - "properties": { - "time": { - "description": "time in seconds", - "type": "integer", - "format": "int64", - "x-go-name": "Time" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "AnnotatedTag": { "description": "AnnotatedTag represents an annotated tag", "type": "object", @@ -9191,6 +9223,26 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "EditTimeOption": { + "description": "EditTimeOption options for adding/deleting time to an issue", + "type": "object", + "required": [ + "time" + ], + "properties": { + "negative": { + "type": "boolean", + "x-go-name": "Negative" + }, + "time": { + "description": "time in seconds", + "type": "integer", + "format": "int64", + "x-go-name": "Time" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "EditUserOption": { "description": "EditUserOption edit user options", "type": "object", From e5ece6b098a96a0eae3a0eca99208f9f9ae8c0e0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 2 Dec 2019 13:27:19 +0100 Subject: [PATCH 10/76] make delete work + forbidden to remove more time on issue than you have --- models/issue_tracked_time.go | 31 ++++++++++++++--------- routers/api/v1/repo/issue_tracked_time.go | 25 +++++++++++++----- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index fe4b58f84695d..3d301da5184d9 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -121,6 +121,19 @@ func GetTrackedTimes(options FindTrackedTimesOptions) (trackedTimes TrackedTimeL return } +// GetTrackedSeconds return sum of seconds +func GetTrackedSeconds(options FindTrackedTimesOptions) (trackedSeconds int64, err error) { + var trackedTimes TrackedTimeList + err = options.ToSession(x).Find(&trackedTimes) + if err != nil { + return 0, err + } + for _, t := range trackedTimes { + trackedSeconds += t.Time + } + return trackedSeconds, nil +} + // AddTime will add the given time (in seconds) to the issue func AddTime(user *User, issue *Issue, time int64) (*TrackedTime, error) { tt := &TrackedTime{ @@ -173,27 +186,21 @@ func TotalTimes(options FindTrackedTimesOptions) (map[*User]string, error) { return totalTimes, nil } -// DeleteTimes deletes times for issue -func DeleteTimes(opts FindTrackedTimesOptions) error { +// DeleteIssueUserTimes deletes times for issue +func DeleteIssueUserTimes(issue *Issue, user *User) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err } - ttl, err := GetTrackedTimes(opts) + _, err := sess.Delete(TrackedTime{ + IssueID: issue.ID, + UserID: user.ID, + }) if err != nil { return err } - if err := deleteTimes(sess, &ttl); err != nil { - return err - } - return sess.Commit() } - -func deleteTimes(e *xorm.Session, ttl *TrackedTimeList) error { - _, err := e.Delete(ttl) - return err -} diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 520bcac736341..ceb7e04fb1636 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -132,11 +132,25 @@ func EditTime(ctx *context.APIContext, form api.EditTimeOption) { return } + value := form.Time + if form.Negative { - form.Time = form.Time * -1 + availableTime, err := models.GetTrackedSeconds(models.FindTrackedTimesOptions{ + IssueID: issue.ID, + UserID: ctx.User.ID, + }) + if err != nil { + ctx.Error(500, "GetTrackedSecounds", err) + return + } + if value > availableTime { + ctx.Error(403, "EditTime: forbidden to remove more time on issue than you have", nil) + return + } + value *= -1 } - trackedTime, err := models.AddTime(ctx.User, issue, form.Time) + trackedTime, err := models.AddTime(ctx.User, issue, value) if err != nil { ctx.Error(500, "AddTime", err) return @@ -196,12 +210,9 @@ func ResetIssueTime(ctx *context.APIContext) { return } - err = models.DeleteTimes(models.FindTrackedTimesOptions{ - IssueID: issue.ID, - UserID: ctx.User.ID, - }) + err = models.DeleteIssueUserTimes(issue, ctx.User) if err != nil { - ctx.Error(500, "AddTime", err) + ctx.Error(500, "DeleteIssueUserTimes", err) return } ctx.Status(200) From 88c61477abf69545e85a981dbabf64fa6d38cc20 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 6 Dec 2019 03:00:25 +0100 Subject: [PATCH 11/76] return full issue instead of issue_index --- models/issue_tracked_time.go | 15 +++++++-------- modules/structs/issue_tracked_time.go | 11 +++++------ templates/swagger/v1_json.tmpl | 12 +++--------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index 3d301da5184d9..0d754fa09b9f9 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -58,14 +58,13 @@ func (t *TrackedTime) APIFormat() *api.TrackedTime { return nil } return &api.TrackedTime{ - ID: t.ID, - IssueID: t.IssueID, - IssueIndex: issue.Index, - UserID: t.UserID, - UserName: user.Name, - Time: t.Time, - Created: t.Created, - Repo: issue.Repo.FullName(), + ID: t.ID, + IssueID: t.IssueID, + Issue: issue.APIFormat(), + UserID: t.UserID, + UserName: user.Name, + Time: t.Time, + Created: t.Created, } } diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index 5d74500dd83b2..c7b9abebaf8ba 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -36,12 +36,11 @@ type TrackedTime struct { // swagger:strfmt date-time Created time.Time `json:"created"` // Time in seconds - Time int64 `json:"time"` - UserID int64 `json:"user_id"` - UserName string `json:"user_name"` - IssueID int64 `json:"issue_id"` - IssueIndex int64 `json:"issue_index"` - Repo string `json:"repository"` + Time int64 `json:"time"` + UserID int64 `json:"user_id"` + UserName string `json:"user_name"` + IssueID int64 `json:"issue_id"` + Issue *Issue `json:"issue"` } // TrackedTimeList represent a list of tracked times diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 1058a1215887d..31719f8c6b6c9 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -11010,20 +11010,14 @@ "format": "int64", "x-go-name": "ID" }, + "issue": { + "$ref": "#/definitions/Issue" + }, "issue_id": { "type": "integer", "format": "int64", "x-go-name": "IssueID" }, - "issue_index": { - "type": "integer", - "format": "int64", - "x-go-name": "IssueIndex" - }, - "repository": { - "type": "string", - "x-go-name": "Repo" - }, "time": { "description": "Time in seconds", "type": "integer", From a64cc393206b205a8c9c72c42ee0beff619e3236 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 8 Dec 2019 23:14:45 +0100 Subject: [PATCH 12/76] dont Deprecate TimesByUser and remove useles stuff --- modules/structs/issue_tracked_time.go | 14 -------------- routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 16 +++------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index c7b9abebaf8ba..c99e914ed4868 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -8,20 +8,6 @@ import ( "time" ) -// TrackedTimeDeprecated worked time for an issue / pr -type TrackedTimeDeprecated struct { - ID int64 `json:"id"` - // swagger:strfmt date-time - Created time.Time `json:"created"` - // Time in seconds - Time int64 `json:"time"` - UserID int64 `json:"user_id"` - IssueID int64 `json:"issue_id"` -} - -// TrackedTimesDeprecated represent a list of tracked times -type TrackedTimesDeprecated []*TrackedTimeDeprecated - // EditTimeOption options for adding/deleting time to an issue type EditTimeOption struct { // time in seconds diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 85a8c972b0117..cde6068752f56 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -650,7 +650,7 @@ func RegisterRoutes(m *macaron.Macaron) { }, reqToken(), reqAdmin()) m.Group("/times", func() { m.Combo("").Get(repo.ListTrackedTimesByRepository) - m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUserDeprecated) + m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUser) }, mustEnableIssues) m.Group("/issues", func() { m.Combo("").Get(repo.ListIssues). diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index ceb7e04fb1636..79a7e4434a6ee 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -10,14 +10,6 @@ import ( api "code.gitea.io/gitea/modules/structs" ) -func trackedTimesToAPIFormatDeprecated(trackedTimes []*models.TrackedTime) []*api.TrackedTimeDeprecated { - apiTrackedTimes := make([]*api.TrackedTimeDeprecated, len(trackedTimes)) - for i, trackedTime := range trackedTimes { - apiTrackedTimes[i] = trackedTime.APIFormatDeprecated() - } - return apiTrackedTimes -} - // ListTrackedTimes list all the tracked times of an issue func ListTrackedTimes(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/issues/{index}/times issue issueTrackedTimes @@ -218,12 +210,11 @@ func ResetIssueTime(ctx *context.APIContext) { ctx.Status(200) } -// ListTrackedTimesByUserDeprecated lists all tracked times of the user -func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { +// ListTrackedTimesByUser lists all tracked times of the user +func ListTrackedTimesByUser(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/times/{user} user userTrackedTimes // --- // summary: List a user's tracked times in a repo - // deprecated: true // produces: // - application/json // parameters: @@ -269,8 +260,7 @@ func ListTrackedTimesByUserDeprecated(ctx *context.APIContext) { ctx.Error(500, "GetTrackedTimesByUser", err) return } - apiTrackedTimes := trackedTimesToAPIFormatDeprecated(trackedTimes) - ctx.JSON(200, &apiTrackedTimes) + ctx.JSON(200, trackedTimes.APIFormat()) } // ListTrackedTimesByRepository lists all tracked times of the repository From 9d71a375a5d483715b30bc050a43f82d1ab30c67 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 8 Dec 2019 23:17:28 +0100 Subject: [PATCH 13/76] new Delete func & optimize --- models/issue_tracked_time.go | 29 +++++++------ routers/api/v1/repo/issue_tracked_time.go | 2 +- routers/api/v1/swagger/issue.go | 14 ------- templates/swagger/v1_json.tmpl | 51 +---------------------- 4 files changed, 16 insertions(+), 80 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index 0d754fa09b9f9..4b4ef90950b69 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -32,17 +32,6 @@ func (t *TrackedTime) AfterLoad() { t.Created = time.Unix(t.CreatedUnix, 0).In(setting.DefaultUILocation) } -// APIFormatDeprecated converts TrackedTime to deprecated API format -func (t *TrackedTime) APIFormatDeprecated() *api.TrackedTimeDeprecated { - return &api.TrackedTimeDeprecated{ - ID: t.ID, - IssueID: t.IssueID, - UserID: t.UserID, - Time: t.Time, - Created: t.Created, - } -} - // APIFormat converts TrackedTime to API format func (t *TrackedTime) APIFormat() *api.TrackedTime { user, err := GetUserByID(t.UserID) @@ -187,16 +176,26 @@ func TotalTimes(options FindTrackedTimesOptions) (map[*User]string, error) { // DeleteIssueUserTimes deletes times for issue func DeleteIssueUserTimes(issue *Issue, user *User) error { + time := TrackedTime{ + IssueID: issue.ID, + UserID: user.ID, + } + return deleteTime(&time) +} + +// DeleteTime delete a time +func DeleteTime(time *TrackedTime) error { + return deleteTime(time) +} + +func deleteTime(time *TrackedTime) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err } - _, err := sess.Delete(TrackedTime{ - IssueID: issue.ID, - UserID: user.ID, - }) + _, err := sess.Delete(time) if err != nil { return err } diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 79a7e4434a6ee..04d628df2bd79 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -235,7 +235,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { // required: true // responses: // "200": - // "$ref": "#/responses/TrackedTimeListDeprecated" + // "$ref": "#/responses/TrackedTimeList" if !ctx.Repo.Repository.IsTimetrackerEnabled() { ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) return diff --git a/routers/api/v1/swagger/issue.go b/routers/api/v1/swagger/issue.go index b7f485e9896e7..a78c2982fd706 100644 --- a/routers/api/v1/swagger/issue.go +++ b/routers/api/v1/swagger/issue.go @@ -64,20 +64,6 @@ type swaggerResponseMilestoneList struct { Body []api.Milestone `json:"body"` } -// TrackedTimeDeprecated -// swagger:response TrackedTimeDeprecated -type swaggerResponseTrackedTimeDeprecated struct { - // in:body - Body api.TrackedTimeDeprecated `json:"body"` -} - -// TrackedTimeListDeprecated -// swagger:response TrackedTimeListDeprecated -type swaggerResponseTrackedTimeListDeprecated struct { - // in:body - Body []api.TrackedTimeDeprecated `json:"body"` -} - // TrackedTime // swagger:response TrackedTime type swaggerResponseTrackedTime struct { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 31719f8c6b6c9..9ae0dd28534c6 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -6075,7 +6075,6 @@ ], "summary": "List a user's tracked times in a repo", "operationId": "userTrackedTimes", - "deprecated": true, "parameters": [ { "type": "string", @@ -6101,7 +6100,7 @@ ], "responses": { "200": { - "$ref": "#/responses/TrackedTimeListDeprecated" + "$ref": "#/responses/TrackedTimeList" } } } @@ -11036,39 +11035,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "TrackedTimeDeprecated": { - "description": "TrackedTimeDeprecated worked time for an issue / pr", - "type": "object", - "properties": { - "created": { - "type": "string", - "format": "date-time", - "x-go-name": "Created" - }, - "id": { - "type": "integer", - "format": "int64", - "x-go-name": "ID" - }, - "issue_id": { - "type": "integer", - "format": "int64", - "x-go-name": "IssueID" - }, - "time": { - "description": "Time in seconds", - "type": "integer", - "format": "int64", - "x-go-name": "Time" - }, - "user_id": { - "type": "integer", - "format": "int64", - "x-go-name": "UserID" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "UpdateFileOptions": { "description": "UpdateFileOptions options for updating files\nNote: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)", "type": "object", @@ -11697,12 +11663,6 @@ "$ref": "#/definitions/TrackedTime" } }, - "TrackedTimeDeprecated": { - "description": "TrackedTimeDeprecated", - "schema": { - "$ref": "#/definitions/TrackedTimeDeprecated" - } - }, "TrackedTimeList": { "description": "TrackedTimeList", "schema": { @@ -11712,15 +11672,6 @@ } } }, - "TrackedTimeListDeprecated": { - "description": "TrackedTimeListDeprecated", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/TrackedTimeDeprecated" - } - } - }, "User": { "description": "User", "schema": { From b6239c018caa8a70718466cdf0c4152a5078bea7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 8 Dec 2019 23:59:44 +0100 Subject: [PATCH 14/76] add Created to EditTimeOption --- models/issue_tracked_time.go | 19 ++++++++++++++++--- modules/structs/issue_tracked_time.go | 2 ++ routers/api/v1/repo/issue_tracked_time.go | 9 ++++++++- templates/swagger/v1_json.tmpl | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/models/issue_tracked_time.go b/models/issue_tracked_time.go index 4b4ef90950b69..356fbfb64b910 100644 --- a/models/issue_tracked_time.go +++ b/models/issue_tracked_time.go @@ -123,11 +123,24 @@ func GetTrackedSeconds(options FindTrackedTimesOptions) (trackedSeconds int64, e } // AddTime will add the given time (in seconds) to the issue -func AddTime(user *User, issue *Issue, time int64) (*TrackedTime, error) { +func AddTime(user *User, issue *Issue, amount int64) (*TrackedTime, error) { + return addTime(user, issue, amount, time.Now()) +} + +// AddTimeCreatedAt will add the given time (in seconds) to the issue at a specific time +func AddTimeCreatedAt(user *User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) { + return addTime(user, issue, amount, created) +} + +func addTime(user *User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) { + if created.IsZero() { + created = time.Now() + } tt := &TrackedTime{ IssueID: issue.ID, UserID: user.ID, - Time: time, + Time: amount, + Created: created, } if _, err := x.Insert(tt); err != nil { return nil, err @@ -139,7 +152,7 @@ func AddTime(user *User, issue *Issue, time int64) (*TrackedTime, error) { Issue: issue, Repo: issue.Repo, Doer: user, - Content: SecToTime(time), + Content: SecToTime(amount), Type: CommentTypeAddTimeManual, }); err != nil { return nil, err diff --git a/modules/structs/issue_tracked_time.go b/modules/structs/issue_tracked_time.go index c99e914ed4868..4d78c339d171f 100644 --- a/modules/structs/issue_tracked_time.go +++ b/modules/structs/issue_tracked_time.go @@ -14,6 +14,8 @@ type EditTimeOption struct { // required: true Time int64 `json:"time" binding:"Required"` Negative bool `json:"negative"` + // swagger:strfmt date-time + Created time.Time `json:"created"` } // TrackedTime worked time for an issue / pr diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 04d628df2bd79..220186fc35c49 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -5,6 +5,8 @@ package repo import ( + "time" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" @@ -142,7 +144,12 @@ func EditTime(ctx *context.APIContext, form api.EditTimeOption) { value *= -1 } - trackedTime, err := models.AddTime(ctx.User, issue, value) + created := time.Time{} + if !form.Created.IsZero() { + created = form.Created + } + + trackedTime, err := models.AddTimeCreatedAt(ctx.User, issue, value, created) if err != nil { ctx.Error(500, "AddTime", err) return diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 9ae0dd28534c6..b6ac597b23967 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -9229,6 +9229,11 @@ "time" ], "properties": { + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, "negative": { "type": "boolean", "x-go-name": "Negative" From 5bb0b2c2cc4b9ac04ade7b688fde87510f2734be Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 Dec 2019 00:42:33 +0100 Subject: [PATCH 15/76] add CommentTypeDeleteTimeManual --- models/issue_comment.go | 4 +++- options/locale/locale_en-US.ini | 1 + templates/repo/issue/view_content/comments.tmpl | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 5843689f1bbb4..884d7401cc6b2 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -82,6 +82,8 @@ const ( CommentTypeLock // Unlocks a previously locked issue CommentTypeUnlock + // Delete time manual for time tracking + CommentTypeDeleteTimeManual ) // CommentTag defines comment tag type @@ -98,7 +100,7 @@ const ( // Comment represents a comment in commit and issue page. type Comment struct { ID int64 `xorm:"pk autoincr"` - Type CommentType `xorm:"index"` + Type CommentType `xorm:"INDEX"` PosterID int64 `xorm:"INDEX"` Poster *User `xorm:"-"` OriginalAuthor string diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 98133cdab3bfb..5385a2ed42a6d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -959,6 +959,7 @@ issues.add_time = Manually Add Time issues.add_time_short = Add Time issues.add_time_cancel = Cancel issues.add_time_history = `added spent time %s` +issues.del_time_history= `deleted spent time %s` issues.add_time_hours = Hours issues.add_time_minutes = Minutes issues.add_time_sum_to_small = No time was entered. diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 49d2e9bc5f71b..70145e4f9fccc 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -411,5 +411,17 @@ {{$.i18n.Tr "repo.issues.unlock_comment" $createdStr | Safe}} + {{else if eq .Type 25}} +