diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index ca92141157526..79ce48c4cd1d2 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -101,6 +101,21 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error { return err } } else { + //if another stopwatch is running: stop it + exists, sw, err := HasUserStopwatch(user.ID) + if err != nil { + return err + } + if exists { + issue, err := getIssueByID(x, sw.IssueID) + if err != nil { + return err + } + if err := CreateOrStopIssueStopwatch(user, issue); err != nil { + return err + } + } + // Create stopwatch sw = &Stopwatch{ UserID: user.ID,