Skip to content

Feature: Timetracking #2211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 102 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
74774a4
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
f385727
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
e05eb96
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
5cb36ca
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
2dd674e
Replacing in-line link generation with HTMLURL. (+gofmt)
jonasfranz May 4, 2017
716bf81
Replaced action-based model with nil-based model. (+gofmt)
jonasfranz May 4, 2017
edaa576
Replaced mailIssueActionToParticipants with mailIssueCommentToPartici…
jonasfranz May 4, 2017
b0e22ab
Updating comment for mailIssueCommentToParticipants
jonasfranz May 4, 2017
fd70385
Merge branch 'master' of github.com:JonasFranzDEV/gitea
jonasfranz Jun 13, 2017
3c6d4fc
Merge branch 'master' of https://github.com/JonasFranzDEV/gitea
jonasfranz Jun 15, 2017
36ae732
Added link to comment in "Dashboard"
jonasfranz Jun 15, 2017
1826b2b
Added migration
jonasfranz Jun 17, 2017
bb33f2e
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
3f1c85c
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
5791853
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
deddcda
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
70d8dd9
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
3b99726
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
9e18513
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
0e20e81
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
8818bc7
Added improved links to comments in feed entries. (+ gofmt) Signed-o…
jonasfranz Jun 18, 2017
3e1241c
Fixes #1956 by filtering for deleted comments that are referenced in …
jonasfranz Jun 22, 2017
3ee3dc3
Fixes #1956 by filtering for deleted comments.
jonasfranz Jun 23, 2017
56a64e3
Fixes #1956 by filtering for deleted comments.
jonasfranz Jun 25, 2017
ce6de8a
Merge remote-tracking branch 'root/master'
jonasfranz Jul 24, 2017
c8d270b
Adding design draft (not functional)
jonasfranz Jul 24, 2017
6db864a
Adding design draft (not functional)
jonasfranz Jul 24, 2017
b213c99
Adding translations and improving design
jonasfranz Jul 24, 2017
79d5c74
Implementing stopwatch (for timetracking)
jonasfranz Jul 25, 2017
286dd9b
Implementing timetracking feature
jonasfranz Jul 25, 2017
cff9234
Only showing total time spent if theire is something to show.
jonasfranz Jul 25, 2017
615b3dd
Adding license headers.
jonasfranz Jul 25, 2017
a1dff21
Improved error handling for "Add Time Manual"
jonasfranz Jul 25, 2017
251d50e
Improved error handling for "Add Time Manual"
jonasfranz Jul 25, 2017
3945c0e
Adding @sapks 's changes, refactoring
jonasfranz Jul 25, 2017
0347bb3
Adding API for feature tracking
jonasfranz Jul 25, 2017
c1943c1
Adding DISABLE/ENABLE option to Repository settings page
jonasfranz Jul 25, 2017
edf850d
Improving translations + adding German translation
jonasfranz Jul 25, 2017
9bd4821
Removing repo_unit and using IssuesSetting for disabling/enabling tim…
jonasfranz Jul 25, 2017
d26f4da
Merge pull request #1 from JonasFranzDEV/feature/timetracking
jonasfranz Jul 25, 2017
8675986
Fixing vendor/ folder
jonasfranz Jul 26, 2017
47d3187
Changing timtracking routes by adding subgroups /times and /times/sto…
jonasfranz Jul 26, 2017
ce3c380
Restricting write access to timetracking based on the repo settings
jonasfranz Jul 26, 2017
871a6eb
Restricting write access to timetracking based on the repo settings
jonasfranz Jul 26, 2017
15faf72
Fixed minor permissions bug.
jonasfranz Jul 26, 2017
906b4c9
Removed German translations
jonasfranz Jul 26, 2017
08b0e63
Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo
jonasfranz Jul 26, 2017
3b25d8e
Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo
jonasfranz Jul 26, 2017
b1dfaa7
Removing unused Get...ByID functions
jonasfranz Jul 26, 2017
fcec528
Moving IsTimetrackerEnabled from context.Repository to models.Repository
jonasfranz Jul 26, 2017
2fa55de
Adding a seperate file for issue related repo functions
jonasfranz Jul 26, 2017
4ed6614
Fixed GetUserByParams return 404
jonasfranz Jul 26, 2017
078f59f
Moving /users/:username/times to /repos/:username/:reponame/times/:us…
jonasfranz Jul 27, 2017
3d3b94a
Updating sdk-dependency
jonasfranz Jul 27, 2017
c3b5ecc
Updating swagger.v1.json
jonasfranz Jul 27, 2017
13fb0e3
Adding warning if user has already a running stopwatch (auto-timetrac…
jonasfranz Jul 27, 2017
497f214
Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrack…
jonasfranz Jul 28, 2017
43762a0
Merge branch 'master' into feature/timetracking
jonasfranz Jul 28, 2017
6563b5b
Correcting spelling mistake
jonasfranz Jul 28, 2017
b42380c
Updating code.gitea.io/sdk
jonasfranz Jul 28, 2017
4a97d69
Updating vendor.json
jonasfranz Jul 28, 2017
a69b5cd
Updating vendor.json
jonasfranz Jul 28, 2017
9023d24
Changing GET stopwatch/toggle to POST stopwatch/toggle
jonasfranz Jul 29, 2017
2f97858
Changing GET stopwatch/cancel to POST stopwatch/cancel
jonasfranz Jul 29, 2017
6eb51db
Added migration for stopwatches/timetracking
jonasfranz Jul 30, 2017
88d1167
Fixed migration by chaging x.Iterate to x.Find
jonasfranz Jul 30, 2017
f50e0d2
Resorted imports
jonasfranz Jul 31, 2017
55ee4e4
Moved Add Time Manually form to repo_form.go
jonasfranz Jul 31, 2017
10be62f
Added integration test
jonasfranz Aug 1, 2017
77db940
Resorted imports
jonasfranz Aug 1, 2017
76d7509
gofmt
jonasfranz Aug 1, 2017
f051c45
Adding integration test by @lafriks
jonasfranz Aug 1, 2017
c2fa07b
Using last event instead of a fixed event
jonasfranz Aug 1, 2017
0d8d3d5
Adding another integration test by @lafriks
jonasfranz Aug 1, 2017
a8eba6a
Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" wa…
jonasfranz Aug 4, 2017
48e8365
Returning TrackedTime instead of AddTimeOption at AddTime.
jonasfranz Aug 12, 2017
abea9a7
Updating SDK from go-gitea/go-sdk#69
jonasfranz Aug 12, 2017
ba3895a
Merge branch 'master' into feature/timetracking
jonasfranz Aug 12, 2017
17a9a6b
Resetting Go-SDK back to default repository
jonasfranz Aug 14, 2017
44f9898
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Aug 21, 2017
36db650
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Aug 21, 2017
28cdef6
Fixing test-vendor by changing ini back to original repository
jonasfranz Aug 21, 2017
2dabf41
Adding "tags" to swagger spec
jonasfranz Aug 21, 2017
4063041
govendor sync
jonasfranz Aug 22, 2017
3222a0f
Removed duplicate
jonasfranz Aug 23, 2017
3840adf
Merge branches 'feature/timetracking' and 'master' of https://github.…
jonasfranz Aug 28, 2017
4727c4b
Formatting templates
jonasfranz Aug 28, 2017
b502d9b
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Aug 28, 2017
528dd2d
Updating swagger spec
jonasfranz Aug 28, 2017
16de1d2
Fixing integration test caused be translation-changes
jonasfranz Aug 29, 2017
83a73d4
Removed encoding issues in local_en-US.ini.
jonasfranz Aug 31, 2017
3d117fc
Moved unit.IssuesConfig().EnableTimetracker into a != nil check
jonasfranz Sep 2, 2017
e2244a8
Improved javascript by checking if data-context exists
jonasfranz Sep 2, 2017
52be3f5
Replaced manual comment creation with CreateComment
jonasfranz Sep 3, 2017
17684f5
Replaced int>string>duration parsing with int>duration parsing
jonasfranz Sep 4, 2017
3142af3
Fixed encoding issues
jonasfranz Sep 4, 2017
3e08048
Removed unused imports
jonasfranz Sep 4, 2017
63a47bc
Merge branch 'master' into feature/timetracking
bkcsoft Sep 6, 2017
c8ed915
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Sep 8, 2017
8cb778c
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Sep 10, 2017
86346e6
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Sep 12, 2017
d73b085
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz Sep 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false
; Default value for AllowCreateOrganization
; New user will have rights set to create organizations depending on this setting
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Default value for EnableTimetracking
; Repositories will use timetracking by default depending on this setting
DEFAULT_ENABLE_TIMETRACKING = true
; Default value for AllowOnlyContributorsToTrackTime
; Only users with write permissions could track time if this is true
DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true
; Default value for the domain part of the user's email address in the git log
; if he has set KeepEmailPrivate true. The user's email replaced with a
; concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS.
Expand Down
84 changes: 84 additions & 0 deletions integrations/timetracking_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
"net/http"
"path"
"testing"

"github.com/stretchr/testify/assert"
)

func TestViewTimetrackingControls(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", true)
//user2/repo1
}

func TestNotViewTimetrackingControls(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user5")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", false)
//user2/repo1
}
func TestViewTimetrackingControlsDisabled(t *testing.T) {
prepareTestEnv(t)
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "user3", "repo3", "1", false)
}

func testViewTimetrackingControls(t *testing.T, session *TestSession, user, repo, issue string, canTrackTime bool) {
req := NewRequest(t, "GET", path.Join(user, repo, "issues", issue))
resp := session.MakeRequest(t, req, http.StatusOK)

htmlDoc := NewHTMLParser(t, resp.Body)

htmlDoc.AssertElement(t, ".timetrack .start-add .start", canTrackTime)
htmlDoc.AssertElement(t, ".timetrack .start-add .add-time", canTrackTime)

req = NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", issue, "times", "stopwatch", "toggle"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
})
if canTrackTime {
resp = session.MakeRequest(t, req, http.StatusSeeOther)

req = NewRequest(t, "GET", RedirectURL(t, resp))
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)

events := htmlDoc.doc.Find(".event > span.text")
assert.Contains(t, events.Last().Text(), "started working")

htmlDoc.AssertElement(t, ".timetrack .stop-cancel .stop", true)
htmlDoc.AssertElement(t, ".timetrack .stop-cancel .cancel", true)

req = NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", issue, "times", "stopwatch", "toggle"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
})
resp = session.MakeRequest(t, req, http.StatusSeeOther)

req = NewRequest(t, "GET", RedirectURL(t, resp))
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)

events = htmlDoc.doc.Find(".event > span.text")
assert.Contains(t, events.Last().Text(), "stopped working")
htmlDoc.AssertElement(t, ".event .detail .octicon-clock", true)
} else {
session.MakeRequest(t, req, http.StatusNotFound)
}
}

// AssertElement check if element by selector exists or does not exist depending on checkExists
func (doc *HTMLDoc) AssertElement(t testing.TB, selector string, checkExists bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reusable helper, could we move it to integrations/html_helper.go?

sel := doc.doc.Find(selector)
if checkExists {
assert.Equal(t, 1, sel.Length())
} else {
assert.Equal(t, 0, sel.Length())
}
}
44 changes: 44 additions & 0 deletions models/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,50 @@ func (err ErrCommentNotExist) Error() string {
return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
}

// _________ __ __ .__
// / _____// |_ ____ ________ _ _______ _/ |_ ____ | |__
// \_____ \\ __\/ _ \\____ \ \/ \/ /\__ \\ __\/ ___\| | \
// / \| | ( <_> ) |_> > / / __ \| | \ \___| Y \
// /_______ /|__| \____/| __/ \/\_/ (____ /__| \___ >___| /
// \/ |__| \/ \/ \/

// ErrStopwatchNotExist represents a "Stopwatch Not Exist" kind of error.
type ErrStopwatchNotExist struct {
ID int64
}

// IsErrStopwatchNotExist checks if an error is a ErrStopwatchNotExist.
func IsErrStopwatchNotExist(err error) bool {
_, ok := err.(ErrStopwatchNotExist)
return ok
}

func (err ErrStopwatchNotExist) Error() string {
return fmt.Sprintf("stopwatch does not exist [id: %d]", err.ID)
}

// ___________ __ .______________.__
// \__ ___/___________ ____ | | __ ____ __| _/\__ ___/|__| _____ ____
// | | \_ __ \__ \ _/ ___\| |/ // __ \ / __ | | | | |/ \_/ __ \
// | | | | \// __ \\ \___| <\ ___// /_/ | | | | | Y Y \ ___/
// |____| |__| (____ /\___ >__|_ \\___ >____ | |____| |__|__|_| /\___ >
// \/ \/ \/ \/ \/ \/ \/

// ErrTrackedTimeNotExist represents a "TrackedTime Not Exist" kind of error.
type ErrTrackedTimeNotExist struct {
ID int64
}

// IsErrTrackedTimeNotExist checks if an error is a ErrTrackedTimeNotExist.
func IsErrTrackedTimeNotExist(err error) bool {
_, ok := err.(ErrTrackedTimeNotExist)
return ok
}

func (err ErrTrackedTimeNotExist) Error() string {
return fmt.Sprintf("tracked time does not exist [id: %d]", err.ID)
}

// .____ ___. .__
// | | _____ \_ |__ ____ | |
// | | \__ \ | __ \_/ __ \| |
Expand Down
3 changes: 3 additions & 0 deletions models/fixtures/comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
issue_id: 1 # in repo_id 1
label_id: 1
content: "1"
created_unix: 946684810
-
id: 2
type: 0 # comment
poster_id: 3 # user not watching (see watch.yml)
issue_id: 1 # in repo_id 1
content: "good work!"
created_unix: 946684811
-
id: 3
type: 0 # comment
poster_id: 5 # user not watching (see watch.yml)
issue_id: 1 # in repo_id 1
content: "meh..."
created_unix: 946684812
13 changes: 13 additions & 0 deletions models/fixtures/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@
content: content5
is_closed: true
is_pull: false
-
id: 6
repo_id: 3
index: 1
poster_id: 1
assignee_id: 1
name: issue6
content: content6
is_closed: false
is_pull: false
num_comments: 0
created_unix: 946684800
updated_unix: 978307200
4 changes: 2 additions & 2 deletions models/fixtures/repo_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
repo_id: 1
type: 2
index: 1
config: "{}"
config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}"
created_unix: 946684810

-
Expand Down Expand Up @@ -51,7 +51,7 @@
repo_id: 3
type: 2
index: 1
config: "{}"
config: "{\"EnableTimetracker\":false,\"AllowOnlyContributorsToTrackTime\":false}"
created_unix: 946684810

-
Expand Down
2 changes: 1 addition & 1 deletion models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
lower_name: repo3
name: repo3
is_private: true
num_issues: 0
num_issues: 1
num_closed_issues: 0
num_pulls: 0
num_closed_pulls: 0
Expand Down
11 changes: 11 additions & 0 deletions models/fixtures/stopwatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-
id: 1
user_id: 1
issue_id: 1
created_unix: 1500988502

-
id: 2
user_id: 2
issue_id: 2
created_unix: 1500988502
34 changes: 34 additions & 0 deletions models/fixtures/tracked_time.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-
id: 1
user_id: 1
issue_id: 1
time: 400
created_unix: 946684800

-
id: 2
user_id: 2
issue_id: 2
time: 3661
created_unix: 946684801

-
id: 3
user_id: 2
issue_id: 2
time: 1
created_unix: 946684802

-
id: 4
user_id: -1
issue_id: 4
time: 1
created_unix: 946684802

-
id: 5
user_id: 2
issue_id: 5
time: 1
created_unix: 946684802
9 changes: 8 additions & 1 deletion models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const (
CommentTypeChangeTitle
// Delete Branch
CommentTypeDeleteBranch
// Start a stopwatch for time tracking
CommentTypeStartTracking
// Stop a stopwatch for time tracking
CommentTypeStopTracking
// Add time manual for time tracking
CommentTypeAddTimeManual
// Cancel a stopwatch for time tracking
CommentTypeCancelTracking
)

// CommentTag defines comment tag type
Expand Down Expand Up @@ -672,7 +680,6 @@ func DeleteComment(comment *Comment) error {
return err
}
}

if _, err := sess.Where("comment_id = ?", comment.ID).Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems duplicated with line 683?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, line 683 is not needed. Line 685 already has same code

return err
}
Expand Down
Loading