You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue.go 41 kB

11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
10 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
9 years ago
9 years ago
9 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "io"
  10. "io/ioutil"
  11. "net/http"
  12. "strconv"
  13. "strings"
  14. "time"
  15. "github.com/Unknwon/com"
  16. "github.com/Unknwon/paginater"
  17. "code.gitea.io/git"
  18. "code.gitea.io/gitea/models"
  19. "code.gitea.io/gitea/modules/auth"
  20. "code.gitea.io/gitea/modules/base"
  21. "code.gitea.io/gitea/modules/context"
  22. "code.gitea.io/gitea/modules/indexer"
  23. "code.gitea.io/gitea/modules/log"
  24. "code.gitea.io/gitea/modules/markup/markdown"
  25. "code.gitea.io/gitea/modules/notification"
  26. "code.gitea.io/gitea/modules/setting"
  27. "code.gitea.io/gitea/modules/util"
  28. )
  29. const (
  30. tplIssues base.TplName = "repo/issue/list"
  31. tplIssueNew base.TplName = "repo/issue/new"
  32. tplIssueView base.TplName = "repo/issue/view"
  33. tplMilestone base.TplName = "repo/issue/milestones"
  34. tplMilestoneNew base.TplName = "repo/issue/milestone_new"
  35. tplMilestoneEdit base.TplName = "repo/issue/milestone_edit"
  36. tplReactions base.TplName = "repo/issue/view_content/reactions"
  37. issueTemplateKey = "IssueTemplate"
  38. )
  39. var (
  40. // ErrFileTypeForbidden not allowed file type error
  41. ErrFileTypeForbidden = errors.New("File type is not allowed")
  42. // ErrTooManyFiles upload too many files
  43. ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
  44. // IssueTemplateCandidates issue templates
  45. IssueTemplateCandidates = []string{
  46. "ISSUE_TEMPLATE.md",
  47. "issue_template.md",
  48. ".gitea/ISSUE_TEMPLATE.md",
  49. ".gitea/issue_template.md",
  50. ".github/ISSUE_TEMPLATE.md",
  51. ".github/issue_template.md",
  52. }
  53. )
  54. // MustEnableIssues check if repository enable internal issues
  55. func MustEnableIssues(ctx *context.Context) {
  56. if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
  57. !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
  58. ctx.NotFound("MustEnableIssues", nil)
  59. return
  60. }
  61. unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
  62. if err == nil {
  63. ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL)
  64. return
  65. }
  66. }
  67. // MustAllowPulls check if repository enable pull requests
  68. func MustAllowPulls(ctx *context.Context) {
  69. if !ctx.Repo.Repository.AllowsPulls() {
  70. ctx.NotFound("MustAllowPulls", nil)
  71. return
  72. }
  73. // User can send pull request if owns a forked repository.
  74. if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
  75. ctx.Repo.PullRequest.Allowed = true
  76. ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
  77. }
  78. }
  79. // Issues render issues page
  80. func Issues(ctx *context.Context) {
  81. isPullList := ctx.Params(":type") == "pulls"
  82. if isPullList {
  83. MustAllowPulls(ctx)
  84. if ctx.Written() {
  85. return
  86. }
  87. ctx.Data["Title"] = ctx.Tr("repo.pulls")
  88. ctx.Data["PageIsPullList"] = true
  89. } else {
  90. MustEnableIssues(ctx)
  91. if ctx.Written() {
  92. return
  93. }
  94. ctx.Data["Title"] = ctx.Tr("repo.issues")
  95. ctx.Data["PageIsIssueList"] = true
  96. }
  97. viewType := ctx.Query("type")
  98. sortType := ctx.Query("sort")
  99. types := []string{"all", "your_repositories", "assigned", "created_by", "mentioned"}
  100. if !com.IsSliceContainsStr(types, viewType) {
  101. viewType = "all"
  102. }
  103. var (
  104. assigneeID = ctx.QueryInt64("assignee")
  105. posterID int64
  106. mentionedID int64
  107. forceEmpty bool
  108. )
  109. if ctx.IsSigned {
  110. switch viewType {
  111. case "created_by":
  112. posterID = ctx.User.ID
  113. case "mentioned":
  114. mentionedID = ctx.User.ID
  115. }
  116. }
  117. repo := ctx.Repo.Repository
  118. selectLabels := ctx.Query("labels")
  119. milestoneID := ctx.QueryInt64("milestone")
  120. isShowClosed := ctx.Query("state") == "closed"
  121. keyword := strings.Trim(ctx.Query("q"), " ")
  122. if bytes.Contains([]byte(keyword), []byte{0x00}) {
  123. keyword = ""
  124. }
  125. var issueIDs []int64
  126. var err error
  127. if len(keyword) > 0 {
  128. issueIDs, err = indexer.SearchIssuesByKeyword(repo.ID, keyword)
  129. if len(issueIDs) == 0 {
  130. forceEmpty = true
  131. }
  132. }
  133. var issueStats *models.IssueStats
  134. if forceEmpty {
  135. issueStats = &models.IssueStats{}
  136. } else {
  137. var err error
  138. issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
  139. RepoID: repo.ID,
  140. Labels: selectLabels,
  141. MilestoneID: milestoneID,
  142. AssigneeID: assigneeID,
  143. MentionedID: mentionedID,
  144. PosterID: posterID,
  145. IsPull: isPullList,
  146. IssueIDs: issueIDs,
  147. })
  148. if err != nil {
  149. ctx.ServerError("GetIssueStats", err)
  150. return
  151. }
  152. }
  153. page := ctx.QueryInt("page")
  154. if page <= 1 {
  155. page = 1
  156. }
  157. var total int
  158. if !isShowClosed {
  159. total = int(issueStats.OpenCount)
  160. } else {
  161. total = int(issueStats.ClosedCount)
  162. }
  163. pager := paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  164. ctx.Data["Page"] = pager
  165. var issues []*models.Issue
  166. if forceEmpty {
  167. issues = []*models.Issue{}
  168. } else {
  169. issues, err = models.Issues(&models.IssuesOptions{
  170. RepoIDs: []int64{repo.ID},
  171. AssigneeID: assigneeID,
  172. PosterID: posterID,
  173. MentionedID: mentionedID,
  174. MilestoneID: milestoneID,
  175. Page: pager.Current(),
  176. PageSize: setting.UI.IssuePagingNum,
  177. IsClosed: util.OptionalBoolOf(isShowClosed),
  178. IsPull: util.OptionalBoolOf(isPullList),
  179. Labels: selectLabels,
  180. SortType: sortType,
  181. IssueIDs: issueIDs,
  182. })
  183. if err != nil {
  184. ctx.ServerError("Issues", err)
  185. return
  186. }
  187. }
  188. // Get posters.
  189. for i := range issues {
  190. // Check read status
  191. if !ctx.IsSigned {
  192. issues[i].IsRead = true
  193. } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
  194. ctx.ServerError("GetIsRead", err)
  195. return
  196. }
  197. }
  198. ctx.Data["Issues"] = issues
  199. // Get milestones.
  200. ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)
  201. if err != nil {
  202. ctx.ServerError("GetAllRepoMilestones", err)
  203. return
  204. }
  205. // Get assignees.
  206. ctx.Data["Assignees"], err = repo.GetAssignees()
  207. if err != nil {
  208. ctx.ServerError("GetAssignees", err)
  209. return
  210. }
  211. if ctx.QueryInt64("assignee") == 0 {
  212. assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
  213. }
  214. ctx.Data["IssueStats"] = issueStats
  215. ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64()
  216. ctx.Data["ViewType"] = viewType
  217. ctx.Data["SortType"] = sortType
  218. ctx.Data["MilestoneID"] = milestoneID
  219. ctx.Data["AssigneeID"] = assigneeID
  220. ctx.Data["IsShowClosed"] = isShowClosed
  221. ctx.Data["Keyword"] = keyword
  222. if isShowClosed {
  223. ctx.Data["State"] = "closed"
  224. } else {
  225. ctx.Data["State"] = "open"
  226. }
  227. ctx.HTML(200, tplIssues)
  228. }
  229. // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
  230. func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
  231. var err error
  232. ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
  233. if err != nil {
  234. ctx.ServerError("GetMilestones", err)
  235. return
  236. }
  237. ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
  238. if err != nil {
  239. ctx.ServerError("GetMilestones", err)
  240. return
  241. }
  242. ctx.Data["Assignees"], err = repo.GetAssignees()
  243. if err != nil {
  244. ctx.ServerError("GetAssignees", err)
  245. return
  246. }
  247. }
  248. // RetrieveRepoMetas find all the meta information of a repository
  249. func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
  250. if !ctx.Repo.IsWriter() {
  251. return nil
  252. }
  253. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  254. if err != nil {
  255. ctx.ServerError("GetLabelsByRepoID", err)
  256. return nil
  257. }
  258. ctx.Data["Labels"] = labels
  259. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  260. if ctx.Written() {
  261. return nil
  262. }
  263. brs, err := ctx.Repo.GitRepo.GetBranches()
  264. if err != nil {
  265. ctx.ServerError("GetBranches", err)
  266. return nil
  267. }
  268. ctx.Data["Branches"] = brs
  269. // Contains true if the user can create issue dependencies
  270. ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User)
  271. return labels
  272. }
  273. func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (string, bool) {
  274. var r io.Reader
  275. var bytes []byte
  276. if ctx.Repo.Commit == nil {
  277. var err error
  278. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
  279. if err != nil {
  280. return "", false
  281. }
  282. }
  283. entry, err := ctx.Repo.Commit.GetTreeEntryByPath(filename)
  284. if err != nil {
  285. return "", false
  286. }
  287. if entry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
  288. return "", false
  289. }
  290. r, err = entry.Blob().Data()
  291. if err != nil {
  292. return "", false
  293. }
  294. bytes, err = ioutil.ReadAll(r)
  295. if err != nil {
  296. return "", false
  297. }
  298. return string(bytes), true
  299. }
  300. func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles []string) {
  301. for _, filename := range possibleFiles {
  302. content, found := getFileContentFromDefaultBranch(ctx, filename)
  303. if found {
  304. ctx.Data[ctxDataKey] = content
  305. return
  306. }
  307. }
  308. }
  309. // NewIssue render createing issue page
  310. func NewIssue(ctx *context.Context) {
  311. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  312. ctx.Data["PageIsIssueList"] = true
  313. ctx.Data["RequireHighlightJS"] = true
  314. ctx.Data["RequireSimpleMDE"] = true
  315. ctx.Data["RequireTribute"] = true
  316. setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
  317. renderAttachmentSettings(ctx)
  318. RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  319. if ctx.Written() {
  320. return
  321. }
  322. ctx.HTML(200, tplIssueNew)
  323. }
  324. // ValidateRepoMetas check and returns repository's meta informations
  325. func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64, []int64, int64) {
  326. var (
  327. repo = ctx.Repo.Repository
  328. err error
  329. )
  330. labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  331. if ctx.Written() {
  332. return nil, nil, 0
  333. }
  334. if !ctx.Repo.IsWriter() {
  335. return nil, nil, 0
  336. }
  337. var labelIDs []int64
  338. hasSelected := false
  339. // Check labels.
  340. if len(form.LabelIDs) > 0 {
  341. labelIDs, err = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
  342. if err != nil {
  343. return nil, nil, 0
  344. }
  345. labelIDMark := base.Int64sToMap(labelIDs)
  346. for i := range labels {
  347. if labelIDMark[labels[i].ID] {
  348. labels[i].IsChecked = true
  349. hasSelected = true
  350. }
  351. }
  352. }
  353. ctx.Data["Labels"] = labels
  354. ctx.Data["HasSelectedLabel"] = hasSelected
  355. ctx.Data["label_ids"] = form.LabelIDs
  356. // Check milestone.
  357. milestoneID := form.MilestoneID
  358. if milestoneID > 0 {
  359. ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
  360. if err != nil {
  361. ctx.ServerError("GetMilestoneByID", err)
  362. return nil, nil, 0
  363. }
  364. ctx.Data["milestone_id"] = milestoneID
  365. }
  366. // Check assignees
  367. var assigneeIDs []int64
  368. if len(form.AssigneeIDs) > 0 {
  369. assigneeIDs, err = base.StringsToInt64s(strings.Split(form.AssigneeIDs, ","))
  370. if err != nil {
  371. return nil, nil, 0
  372. }
  373. // Check if the passed assignees actually exists and has write access to the repo
  374. for _, aID := range assigneeIDs {
  375. _, err = repo.GetUserIfHasWriteAccess(aID)
  376. if err != nil {
  377. ctx.ServerError("GetUserIfHasWriteAccess", err)
  378. return nil, nil, 0
  379. }
  380. }
  381. }
  382. // Keep the old assignee id thingy for compatibility reasons
  383. if form.AssigneeID > 0 {
  384. assigneeIDs = append(assigneeIDs, form.AssigneeID)
  385. }
  386. return labelIDs, assigneeIDs, milestoneID
  387. }
  388. // NewIssuePost response for creating new issue
  389. func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
  390. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  391. ctx.Data["PageIsIssueList"] = true
  392. ctx.Data["RequireHighlightJS"] = true
  393. ctx.Data["RequireSimpleMDE"] = true
  394. ctx.Data["ReadOnly"] = false
  395. renderAttachmentSettings(ctx)
  396. var (
  397. repo = ctx.Repo.Repository
  398. attachments []string
  399. )
  400. labelIDs, assigneeIDs, milestoneID := ValidateRepoMetas(ctx, form)
  401. if ctx.Written() {
  402. return
  403. }
  404. if setting.AttachmentEnabled {
  405. attachments = form.Files
  406. }
  407. if ctx.HasError() {
  408. ctx.HTML(200, tplIssueNew)
  409. return
  410. }
  411. issue := &models.Issue{
  412. RepoID: repo.ID,
  413. Title: form.Title,
  414. PosterID: ctx.User.ID,
  415. Poster: ctx.User,
  416. MilestoneID: milestoneID,
  417. Content: form.Content,
  418. Ref: form.Ref,
  419. }
  420. if err := models.NewIssue(repo, issue, labelIDs, assigneeIDs, attachments); err != nil {
  421. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  422. ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
  423. return
  424. }
  425. ctx.ServerError("NewIssue", err)
  426. return
  427. }
  428. notification.Service.NotifyIssue(issue, ctx.User.ID)
  429. log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
  430. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  431. }
  432. // commentTag returns the CommentTag for a comment in/with the given repo, poster and issue
  433. func commentTag(repo *models.Repository, poster *models.User, issue *models.Issue) (models.CommentTag, error) {
  434. if repo.IsOwnedBy(poster.ID) {
  435. return models.CommentTagOwner, nil
  436. } else if repo.Owner.IsOrganization() {
  437. isOwner, err := repo.Owner.IsOwnedBy(poster.ID)
  438. if err != nil {
  439. return models.CommentTagNone, err
  440. } else if isOwner {
  441. return models.CommentTagOwner, nil
  442. }
  443. }
  444. if poster.IsWriterOfRepo(repo) {
  445. return models.CommentTagWriter, nil
  446. } else if poster.ID == issue.PosterID {
  447. return models.CommentTagPoster, nil
  448. }
  449. return models.CommentTagNone, nil
  450. }
  451. // ViewIssue render issue view page
  452. func ViewIssue(ctx *context.Context) {
  453. ctx.Data["RequireHighlightJS"] = true
  454. ctx.Data["RequireDropzone"] = true
  455. ctx.Data["RequireTribute"] = true
  456. renderAttachmentSettings(ctx)
  457. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  458. if err != nil {
  459. if models.IsErrIssueNotExist(err) {
  460. ctx.NotFound("GetIssueByIndex", err)
  461. } else {
  462. ctx.ServerError("GetIssueByIndex", err)
  463. }
  464. return
  465. }
  466. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  467. var iw *models.IssueWatch
  468. var exists bool
  469. if ctx.User != nil {
  470. iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
  471. if err != nil {
  472. ctx.ServerError("GetIssueWatch", err)
  473. return
  474. }
  475. if !exists {
  476. iw = &models.IssueWatch{
  477. UserID: ctx.User.ID,
  478. IssueID: issue.ID,
  479. IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
  480. }
  481. }
  482. }
  483. ctx.Data["IssueWatch"] = iw
  484. // Make sure type and URL matches.
  485. if ctx.Params(":type") == "issues" && issue.IsPull {
  486. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  487. return
  488. } else if ctx.Params(":type") == "pulls" && !issue.IsPull {
  489. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  490. return
  491. }
  492. if issue.IsPull {
  493. MustAllowPulls(ctx)
  494. if ctx.Written() {
  495. return
  496. }
  497. ctx.Data["PageIsPullList"] = true
  498. ctx.Data["PageIsPullConversation"] = true
  499. } else {
  500. MustEnableIssues(ctx)
  501. if ctx.Written() {
  502. return
  503. }
  504. ctx.Data["PageIsIssueList"] = true
  505. }
  506. issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
  507. ctx.Repo.Repository.ComposeMetas()))
  508. repo := ctx.Repo.Repository
  509. // Get more information if it's a pull request.
  510. if issue.IsPull {
  511. if issue.PullRequest.HasMerged {
  512. ctx.Data["DisableStatusChange"] = issue.PullRequest.HasMerged
  513. PrepareMergedViewPullInfo(ctx, issue)
  514. } else {
  515. PrepareViewPullInfo(ctx, issue)
  516. }
  517. if ctx.Written() {
  518. return
  519. }
  520. }
  521. // Metas.
  522. // Check labels.
  523. labelIDMark := make(map[int64]bool)
  524. for i := range issue.Labels {
  525. labelIDMark[issue.Labels[i].ID] = true
  526. }
  527. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  528. if err != nil {
  529. ctx.ServerError("GetLabelsByRepoID", err)
  530. return
  531. }
  532. hasSelected := false
  533. for i := range labels {
  534. if labelIDMark[labels[i].ID] {
  535. labels[i].IsChecked = true
  536. hasSelected = true
  537. }
  538. }
  539. ctx.Data["HasSelectedLabel"] = hasSelected
  540. ctx.Data["Labels"] = labels
  541. // Check milestone and assignee.
  542. if ctx.Repo.IsWriter() {
  543. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  544. if ctx.Written() {
  545. return
  546. }
  547. }
  548. if ctx.IsSigned {
  549. // Update issue-user.
  550. if err = issue.ReadBy(ctx.User.ID); err != nil {
  551. ctx.ServerError("ReadBy", err)
  552. return
  553. }
  554. }
  555. var (
  556. tag models.CommentTag
  557. ok bool
  558. marked = make(map[int64]models.CommentTag)
  559. comment *models.Comment
  560. participants = make([]*models.User, 1, 10)
  561. )
  562. if ctx.Repo.Repository.IsTimetrackerEnabled() {
  563. if ctx.IsSigned {
  564. // Deal with the stopwatch
  565. ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
  566. if !ctx.Data["IsStopwatchRunning"].(bool) {
  567. var exists bool
  568. var sw *models.Stopwatch
  569. if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
  570. ctx.ServerError("HasUserStopwatch", err)
  571. return
  572. }
  573. ctx.Data["HasUserStopwatch"] = exists
  574. if exists {
  575. // Add warning if the user has already a stopwatch
  576. var otherIssue *models.Issue
  577. if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
  578. ctx.ServerError("GetIssueByID", err)
  579. return
  580. }
  581. // Add link to the issue of the already running stopwatch
  582. ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
  583. }
  584. }
  585. ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
  586. } else {
  587. ctx.Data["CanUseTimetracker"] = false
  588. }
  589. if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
  590. ctx.ServerError("TotalTimes", err)
  591. return
  592. }
  593. }
  594. // Check if the user can use the dependencies
  595. ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User)
  596. // Render comments and and fetch participants.
  597. participants[0] = issue.Poster
  598. for _, comment = range issue.Comments {
  599. if comment.Type == models.CommentTypeComment {
  600. comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink,
  601. ctx.Repo.Repository.ComposeMetas()))
  602. // Check tag.
  603. tag, ok = marked[comment.PosterID]
  604. if ok {
  605. comment.ShowTag = tag
  606. continue
  607. }
  608. comment.ShowTag, err = commentTag(repo, comment.Poster, issue)
  609. if err != nil {
  610. ctx.ServerError("commentTag", err)
  611. return
  612. }
  613. marked[comment.PosterID] = comment.ShowTag
  614. isAdded := false
  615. for j := range participants {
  616. if comment.Poster == participants[j] {
  617. isAdded = true
  618. break
  619. }
  620. }
  621. if !isAdded && !issue.IsPoster(comment.Poster.ID) {
  622. participants = append(participants, comment.Poster)
  623. }
  624. } else if comment.Type == models.CommentTypeLabel {
  625. if err = comment.LoadLabel(); err != nil {
  626. ctx.ServerError("LoadLabel", err)
  627. return
  628. }
  629. } else if comment.Type == models.CommentTypeMilestone {
  630. if err = comment.LoadMilestone(); err != nil {
  631. ctx.ServerError("LoadMilestone", err)
  632. return
  633. }
  634. ghostMilestone := &models.Milestone{
  635. ID: -1,
  636. Name: ctx.Tr("repo.issues.deleted_milestone"),
  637. }
  638. if comment.OldMilestoneID > 0 && comment.OldMilestone == nil {
  639. comment.OldMilestone = ghostMilestone
  640. }
  641. if comment.MilestoneID > 0 && comment.Milestone == nil {
  642. comment.Milestone = ghostMilestone
  643. }
  644. } else if comment.Type == models.CommentTypeAssignees {
  645. if err = comment.LoadAssigneeUser(); err != nil {
  646. ctx.ServerError("LoadAssigneeUser", err)
  647. return
  648. }
  649. } else if comment.Type == models.CommentTypeRemoveDependency || comment.Type == models.CommentTypeAddDependency {
  650. if err = comment.LoadDepIssueDetails(); err != nil {
  651. ctx.ServerError("LoadDepIssueDetails", err)
  652. return
  653. }
  654. }
  655. }
  656. if issue.IsPull {
  657. pull := issue.PullRequest
  658. canDelete := false
  659. if ctx.IsSigned {
  660. if err := pull.GetHeadRepo(); err != nil {
  661. log.Error(4, "GetHeadRepo: %v", err)
  662. } else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch && ctx.User.IsWriterOfRepo(pull.HeadRepo) {
  663. // Check if branch is not protected
  664. if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch, ctx.User); err != nil {
  665. log.Error(4, "IsProtectedBranch: %v", err)
  666. } else if !protected {
  667. canDelete = true
  668. ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
  669. }
  670. }
  671. }
  672. prUnit, err := repo.GetUnit(models.UnitTypePullRequests)
  673. if err != nil {
  674. ctx.ServerError("GetUnit", err)
  675. return
  676. }
  677. prConfig := prUnit.PullRequestsConfig()
  678. ctx.Data["AllowMerge"] = ctx.Data["IsRepositoryWriter"]
  679. if err := pull.CheckUserAllowedToMerge(ctx.User); err != nil {
  680. if !models.IsErrNotAllowedToMerge(err) {
  681. ctx.ServerError("CheckUserAllowedToMerge", err)
  682. return
  683. }
  684. ctx.Data["AllowMerge"] = false
  685. }
  686. // Check correct values and select default
  687. if ms, ok := ctx.Data["MergeStyle"].(models.MergeStyle); !ok ||
  688. !prConfig.IsMergeStyleAllowed(ms) {
  689. if prConfig.AllowMerge {
  690. ctx.Data["MergeStyle"] = models.MergeStyleMerge
  691. } else if prConfig.AllowRebase {
  692. ctx.Data["MergeStyle"] = models.MergeStyleRebase
  693. } else if prConfig.AllowSquash {
  694. ctx.Data["MergeStyle"] = models.MergeStyleSquash
  695. } else {
  696. ctx.Data["MergeStyle"] = ""
  697. }
  698. }
  699. ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
  700. }
  701. // Get Dependencies
  702. ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
  703. ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
  704. ctx.Data["Participants"] = participants
  705. ctx.Data["NumParticipants"] = len(participants)
  706. ctx.Data["Issue"] = issue
  707. ctx.Data["ReadOnly"] = true
  708. ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
  709. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
  710. ctx.HTML(200, tplIssueView)
  711. }
  712. // GetActionIssue will return the issue which is used in the context.
  713. func GetActionIssue(ctx *context.Context) *models.Issue {
  714. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  715. if err != nil {
  716. ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
  717. return nil
  718. }
  719. checkIssueRights(ctx, issue)
  720. if ctx.Written() {
  721. return nil
  722. }
  723. if err = issue.LoadAttributes(); err != nil {
  724. ctx.ServerError("LoadAttributes", nil)
  725. return nil
  726. }
  727. return issue
  728. }
  729. func checkIssueRights(ctx *context.Context, issue *models.Issue) {
  730. if issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) ||
  731. !issue.IsPull && !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) {
  732. ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
  733. }
  734. }
  735. func getActionIssues(ctx *context.Context) []*models.Issue {
  736. commaSeparatedIssueIDs := ctx.Query("issue_ids")
  737. if len(commaSeparatedIssueIDs) == 0 {
  738. return nil
  739. }
  740. issueIDs := make([]int64, 0, 10)
  741. for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
  742. issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
  743. if err != nil {
  744. ctx.ServerError("ParseInt", err)
  745. return nil
  746. }
  747. issueIDs = append(issueIDs, issueID)
  748. }
  749. issues, err := models.GetIssuesByIDs(issueIDs)
  750. if err != nil {
  751. ctx.ServerError("GetIssuesByIDs", err)
  752. return nil
  753. }
  754. // Check access rights for all issues
  755. issueUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues)
  756. prUnitEnabled := ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)
  757. for _, issue := range issues {
  758. if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
  759. ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
  760. return nil
  761. }
  762. if err = issue.LoadAttributes(); err != nil {
  763. ctx.ServerError("LoadAttributes", err)
  764. return nil
  765. }
  766. }
  767. return issues
  768. }
  769. // UpdateIssueTitle change issue's title
  770. func UpdateIssueTitle(ctx *context.Context) {
  771. issue := GetActionIssue(ctx)
  772. if ctx.Written() {
  773. return
  774. }
  775. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) {
  776. ctx.Error(403)
  777. return
  778. }
  779. title := ctx.QueryTrim("title")
  780. if len(title) == 0 {
  781. ctx.Error(204)
  782. return
  783. }
  784. if err := issue.ChangeTitle(ctx.User, title); err != nil {
  785. ctx.ServerError("ChangeTitle", err)
  786. return
  787. }
  788. ctx.JSON(200, map[string]interface{}{
  789. "title": issue.Title,
  790. })
  791. }
  792. // UpdateIssueContent change issue's content
  793. func UpdateIssueContent(ctx *context.Context) {
  794. issue := GetActionIssue(ctx)
  795. if ctx.Written() {
  796. return
  797. }
  798. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) {
  799. ctx.Error(403)
  800. return
  801. }
  802. content := ctx.Query("content")
  803. if err := issue.ChangeContent(ctx.User, content); err != nil {
  804. ctx.ServerError("ChangeContent", err)
  805. return
  806. }
  807. ctx.JSON(200, map[string]interface{}{
  808. "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  809. })
  810. }
  811. // UpdateIssueMilestone change issue's milestone
  812. func UpdateIssueMilestone(ctx *context.Context) {
  813. issues := getActionIssues(ctx)
  814. if ctx.Written() {
  815. return
  816. }
  817. milestoneID := ctx.QueryInt64("id")
  818. for _, issue := range issues {
  819. oldMilestoneID := issue.MilestoneID
  820. if oldMilestoneID == milestoneID {
  821. continue
  822. }
  823. issue.MilestoneID = milestoneID
  824. if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
  825. ctx.ServerError("ChangeMilestoneAssign", err)
  826. return
  827. }
  828. }
  829. ctx.JSON(200, map[string]interface{}{
  830. "ok": true,
  831. })
  832. }
  833. // UpdateIssueAssignee change issue's assignee
  834. func UpdateIssueAssignee(ctx *context.Context) {
  835. issues := getActionIssues(ctx)
  836. if ctx.Written() {
  837. return
  838. }
  839. assigneeID := ctx.QueryInt64("id")
  840. action := ctx.Query("action")
  841. for _, issue := range issues {
  842. switch action {
  843. case "clear":
  844. if err := models.DeleteNotPassedAssignee(issue, ctx.User, []*models.User{}); err != nil {
  845. ctx.ServerError("ClearAssignees", err)
  846. return
  847. }
  848. default:
  849. if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil {
  850. ctx.ServerError("ChangeAssignee", err)
  851. return
  852. }
  853. }
  854. }
  855. ctx.JSON(200, map[string]interface{}{
  856. "ok": true,
  857. })
  858. }
  859. // UpdateIssueStatus change issue's status
  860. func UpdateIssueStatus(ctx *context.Context) {
  861. issues := getActionIssues(ctx)
  862. if ctx.Written() {
  863. return
  864. }
  865. var isClosed bool
  866. switch action := ctx.Query("action"); action {
  867. case "open":
  868. isClosed = false
  869. case "close":
  870. isClosed = true
  871. default:
  872. log.Warn("Unrecognized action: %s", action)
  873. }
  874. if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
  875. ctx.ServerError("LoadRepositories", err)
  876. return
  877. }
  878. for _, issue := range issues {
  879. if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
  880. if models.IsErrDependenciesLeft(err) {
  881. ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
  882. "error": "cannot close this issue because it still has open dependencies",
  883. })
  884. return
  885. }
  886. ctx.ServerError("ChangeStatus", err)
  887. return
  888. }
  889. }
  890. ctx.JSON(200, map[string]interface{}{
  891. "ok": true,
  892. })
  893. }
  894. // NewComment create a comment for issue
  895. func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
  896. issue := GetActionIssue(ctx)
  897. if ctx.Written() {
  898. return
  899. }
  900. var attachments []string
  901. if setting.AttachmentEnabled {
  902. attachments = form.Files
  903. }
  904. if ctx.HasError() {
  905. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  906. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
  907. return
  908. }
  909. var comment *models.Comment
  910. defer func() {
  911. // Check if issue admin/poster changes the status of issue.
  912. if (ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
  913. (form.Status == "reopen" || form.Status == "close") &&
  914. !(issue.IsPull && issue.PullRequest.HasMerged) {
  915. // Duplication and conflict check should apply to reopen pull request.
  916. var pr *models.PullRequest
  917. if form.Status == "reopen" && issue.IsPull {
  918. pull := issue.PullRequest
  919. pr, err := models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
  920. if err != nil {
  921. if !models.IsErrPullRequestNotExist(err) {
  922. ctx.ServerError("GetUnmergedPullRequest", err)
  923. return
  924. }
  925. }
  926. // Regenerate patch and test conflict.
  927. if pr == nil {
  928. if err = issue.PullRequest.UpdatePatch(); err != nil {
  929. ctx.ServerError("UpdatePatch", err)
  930. return
  931. }
  932. issue.PullRequest.AddToTaskQueue()
  933. }
  934. }
  935. if pr != nil {
  936. ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
  937. } else {
  938. if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
  939. log.Error(4, "ChangeStatus: %v", err)
  940. if models.IsErrDependenciesLeft(err) {
  941. if issue.IsPull {
  942. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
  943. ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
  944. } else {
  945. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.issue_close_blocked"))
  946. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
  947. }
  948. return
  949. }
  950. } else {
  951. log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
  952. notification.Service.NotifyIssue(issue, ctx.User.ID)
  953. }
  954. }
  955. }
  956. // Redirect to comment hashtag if there is any actual content.
  957. typeName := "issues"
  958. if issue.IsPull {
  959. typeName = "pulls"
  960. }
  961. if comment != nil {
  962. ctx.Redirect(fmt.Sprintf("%s/%s/%d#%s", ctx.Repo.RepoLink, typeName, issue.Index, comment.HashTag()))
  963. } else {
  964. ctx.Redirect(fmt.Sprintf("%s/%s/%d", ctx.Repo.RepoLink, typeName, issue.Index))
  965. }
  966. }()
  967. // Fix #321: Allow empty comments, as long as we have attachments.
  968. if len(form.Content) == 0 && len(attachments) == 0 {
  969. return
  970. }
  971. comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
  972. if err != nil {
  973. ctx.ServerError("CreateIssueComment", err)
  974. return
  975. }
  976. notification.Service.NotifyIssue(issue, ctx.User.ID)
  977. log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
  978. }
  979. // UpdateCommentContent change comment of issue's content
  980. func UpdateCommentContent(ctx *context.Context) {
  981. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  982. if err != nil {
  983. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  984. return
  985. }
  986. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  987. ctx.Error(403)
  988. return
  989. } else if comment.Type != models.CommentTypeComment {
  990. ctx.Error(204)
  991. return
  992. }
  993. oldContent := comment.Content
  994. comment.Content = ctx.Query("content")
  995. if len(comment.Content) == 0 {
  996. ctx.JSON(200, map[string]interface{}{
  997. "content": "",
  998. })
  999. return
  1000. }
  1001. if err = models.UpdateComment(ctx.User, comment, oldContent); err != nil {
  1002. ctx.ServerError("UpdateComment", err)
  1003. return
  1004. }
  1005. ctx.JSON(200, map[string]interface{}{
  1006. "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  1007. })
  1008. }
  1009. // DeleteComment delete comment of issue
  1010. func DeleteComment(ctx *context.Context) {
  1011. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1012. if err != nil {
  1013. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1014. return
  1015. }
  1016. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  1017. ctx.Error(403)
  1018. return
  1019. } else if comment.Type != models.CommentTypeComment {
  1020. ctx.Error(204)
  1021. return
  1022. }
  1023. if err = models.DeleteComment(ctx.User, comment); err != nil {
  1024. ctx.ServerError("DeleteCommentByID", err)
  1025. return
  1026. }
  1027. ctx.Status(200)
  1028. }
  1029. // Milestones render milestones page
  1030. func Milestones(ctx *context.Context) {
  1031. ctx.Data["Title"] = ctx.Tr("repo.milestones")
  1032. ctx.Data["PageIsIssueList"] = true
  1033. ctx.Data["PageIsMilestones"] = true
  1034. isShowClosed := ctx.Query("state") == "closed"
  1035. openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID)
  1036. if err != nil {
  1037. ctx.ServerError("MilestoneStats", err)
  1038. return
  1039. }
  1040. ctx.Data["OpenCount"] = openCount
  1041. ctx.Data["ClosedCount"] = closedCount
  1042. sortType := ctx.Query("sort")
  1043. page := ctx.QueryInt("page")
  1044. if page <= 1 {
  1045. page = 1
  1046. }
  1047. var total int
  1048. if !isShowClosed {
  1049. total = int(openCount)
  1050. } else {
  1051. total = int(closedCount)
  1052. }
  1053. ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  1054. miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
  1055. if err != nil {
  1056. ctx.ServerError("GetMilestones", err)
  1057. return
  1058. }
  1059. if ctx.Repo.Repository.IsTimetrackerEnabled() {
  1060. if miles.LoadTotalTrackedTimes(); err != nil {
  1061. ctx.ServerError("LoadTotalTrackedTimes", err)
  1062. return
  1063. }
  1064. }
  1065. for _, m := range miles {
  1066. m.RenderedContent = string(markdown.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
  1067. }
  1068. ctx.Data["Milestones"] = miles
  1069. if isShowClosed {
  1070. ctx.Data["State"] = "closed"
  1071. } else {
  1072. ctx.Data["State"] = "open"
  1073. }
  1074. ctx.Data["SortType"] = sortType
  1075. ctx.Data["IsShowClosed"] = isShowClosed
  1076. ctx.HTML(200, tplMilestone)
  1077. }
  1078. // NewMilestone render creating milestone page
  1079. func NewMilestone(ctx *context.Context) {
  1080. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  1081. ctx.Data["PageIsIssueList"] = true
  1082. ctx.Data["PageIsMilestones"] = true
  1083. ctx.Data["RequireDatetimepicker"] = true
  1084. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1085. ctx.HTML(200, tplMilestoneNew)
  1086. }
  1087. // NewMilestonePost response for creating milestone
  1088. func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  1089. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  1090. ctx.Data["PageIsIssueList"] = true
  1091. ctx.Data["PageIsMilestones"] = true
  1092. ctx.Data["RequireDatetimepicker"] = true
  1093. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1094. if ctx.HasError() {
  1095. ctx.HTML(200, tplMilestoneNew)
  1096. return
  1097. }
  1098. if len(form.Deadline) == 0 {
  1099. form.Deadline = "9999-12-31"
  1100. }
  1101. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  1102. if err != nil {
  1103. ctx.Data["Err_Deadline"] = true
  1104. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  1105. return
  1106. }
  1107. if err = models.NewMilestone(&models.Milestone{
  1108. RepoID: ctx.Repo.Repository.ID,
  1109. Name: form.Title,
  1110. Content: form.Content,
  1111. DeadlineUnix: util.TimeStamp(deadline.Unix()),
  1112. }); err != nil {
  1113. ctx.ServerError("NewMilestone", err)
  1114. return
  1115. }
  1116. ctx.Flash.Success(ctx.Tr("repo.milestones.create_success", form.Title))
  1117. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1118. }
  1119. // EditMilestone render edting milestone page
  1120. func EditMilestone(ctx *context.Context) {
  1121. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  1122. ctx.Data["PageIsMilestones"] = true
  1123. ctx.Data["PageIsEditMilestone"] = true
  1124. ctx.Data["RequireDatetimepicker"] = true
  1125. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1126. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1127. if err != nil {
  1128. if models.IsErrMilestoneNotExist(err) {
  1129. ctx.NotFound("", nil)
  1130. } else {
  1131. ctx.ServerError("GetMilestoneByRepoID", err)
  1132. }
  1133. return
  1134. }
  1135. ctx.Data["title"] = m.Name
  1136. ctx.Data["content"] = m.Content
  1137. if len(m.DeadlineString) > 0 {
  1138. ctx.Data["deadline"] = m.DeadlineString
  1139. }
  1140. ctx.HTML(200, tplMilestoneNew)
  1141. }
  1142. // EditMilestonePost response for edting milestone
  1143. func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  1144. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  1145. ctx.Data["PageIsMilestones"] = true
  1146. ctx.Data["PageIsEditMilestone"] = true
  1147. ctx.Data["RequireDatetimepicker"] = true
  1148. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1149. if ctx.HasError() {
  1150. ctx.HTML(200, tplMilestoneNew)
  1151. return
  1152. }
  1153. if len(form.Deadline) == 0 {
  1154. form.Deadline = "9999-12-31"
  1155. }
  1156. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  1157. if err != nil {
  1158. ctx.Data["Err_Deadline"] = true
  1159. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  1160. return
  1161. }
  1162. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1163. if err != nil {
  1164. if models.IsErrMilestoneNotExist(err) {
  1165. ctx.NotFound("", nil)
  1166. } else {
  1167. ctx.ServerError("GetMilestoneByRepoID", err)
  1168. }
  1169. return
  1170. }
  1171. m.Name = form.Title
  1172. m.Content = form.Content
  1173. m.DeadlineUnix = util.TimeStamp(deadline.Unix())
  1174. if err = models.UpdateMilestone(m); err != nil {
  1175. ctx.ServerError("UpdateMilestone", err)
  1176. return
  1177. }
  1178. ctx.Flash.Success(ctx.Tr("repo.milestones.edit_success", m.Name))
  1179. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1180. }
  1181. // ChangeMilestonStatus response for change a milestone's status
  1182. func ChangeMilestonStatus(ctx *context.Context) {
  1183. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1184. if err != nil {
  1185. if models.IsErrMilestoneNotExist(err) {
  1186. ctx.NotFound("", err)
  1187. } else {
  1188. ctx.ServerError("GetMilestoneByRepoID", err)
  1189. }
  1190. return
  1191. }
  1192. switch ctx.Params(":action") {
  1193. case "open":
  1194. if m.IsClosed {
  1195. if err = models.ChangeMilestoneStatus(m, false); err != nil {
  1196. ctx.ServerError("ChangeMilestoneStatus", err)
  1197. return
  1198. }
  1199. }
  1200. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open")
  1201. case "close":
  1202. if !m.IsClosed {
  1203. m.ClosedDateUnix = util.TimeStampNow()
  1204. if err = models.ChangeMilestoneStatus(m, true); err != nil {
  1205. ctx.ServerError("ChangeMilestoneStatus", err)
  1206. return
  1207. }
  1208. }
  1209. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=closed")
  1210. default:
  1211. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1212. }
  1213. }
  1214. // DeleteMilestone delete a milestone
  1215. func DeleteMilestone(ctx *context.Context) {
  1216. if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
  1217. ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
  1218. } else {
  1219. ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
  1220. }
  1221. ctx.JSON(200, map[string]interface{}{
  1222. "redirect": ctx.Repo.RepoLink + "/milestones",
  1223. })
  1224. }
  1225. // ChangeIssueReaction create a reaction for issue
  1226. func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {
  1227. issue := GetActionIssue(ctx)
  1228. if ctx.Written() {
  1229. return
  1230. }
  1231. if ctx.HasError() {
  1232. ctx.ServerError("ChangeIssueReaction", errors.New(ctx.GetErrMsg()))
  1233. return
  1234. }
  1235. switch ctx.Params(":action") {
  1236. case "react":
  1237. reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Content)
  1238. if err != nil {
  1239. log.Info("CreateIssueReaction: %s", err)
  1240. break
  1241. }
  1242. // Reload new reactions
  1243. issue.Reactions = nil
  1244. if err = issue.LoadAttributes(); err != nil {
  1245. log.Info("issue.LoadAttributes: %s", err)
  1246. break
  1247. }
  1248. log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
  1249. case "unreact":
  1250. if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil {
  1251. ctx.ServerError("DeleteIssueReaction", err)
  1252. return
  1253. }
  1254. // Reload new reactions
  1255. issue.Reactions = nil
  1256. if err := issue.LoadAttributes(); err != nil {
  1257. log.Info("issue.LoadAttributes: %s", err)
  1258. break
  1259. }
  1260. log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
  1261. default:
  1262. ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
  1263. return
  1264. }
  1265. if len(issue.Reactions) == 0 {
  1266. ctx.JSON(200, map[string]interface{}{
  1267. "empty": true,
  1268. "html": "",
  1269. })
  1270. return
  1271. }
  1272. html, err := ctx.HTMLString(string(tplReactions), map[string]interface{}{
  1273. "ctx": ctx.Data,
  1274. "ActionURL": fmt.Sprintf("%s/issues/%d/reactions", ctx.Repo.RepoLink, issue.Index),
  1275. "Reactions": issue.Reactions.GroupByType(),
  1276. })
  1277. if err != nil {
  1278. ctx.ServerError("ChangeIssueReaction.HTMLString", err)
  1279. return
  1280. }
  1281. ctx.JSON(200, map[string]interface{}{
  1282. "html": html,
  1283. })
  1284. }
  1285. // ChangeCommentReaction create a reaction for comment
  1286. func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {
  1287. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  1288. if err != nil {
  1289. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  1290. return
  1291. }
  1292. issue, err := models.GetIssueByID(comment.IssueID)
  1293. checkIssueRights(ctx, issue)
  1294. if ctx.Written() {
  1295. return
  1296. }
  1297. if ctx.HasError() {
  1298. ctx.ServerError("ChangeCommentReaction", errors.New(ctx.GetErrMsg()))
  1299. return
  1300. }
  1301. switch ctx.Params(":action") {
  1302. case "react":
  1303. reaction, err := models.CreateCommentReaction(ctx.User, issue, comment, form.Content)
  1304. if err != nil {
  1305. log.Info("CreateCommentReaction: %s", err)
  1306. break
  1307. }
  1308. // Reload new reactions
  1309. comment.Reactions = nil
  1310. if err = comment.LoadReactions(); err != nil {
  1311. log.Info("comment.LoadReactions: %s", err)
  1312. break
  1313. }
  1314. log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID, reaction.ID)
  1315. case "unreact":
  1316. if err := models.DeleteCommentReaction(ctx.User, issue, comment, form.Content); err != nil {
  1317. ctx.ServerError("DeleteCommentReaction", err)
  1318. return
  1319. }
  1320. // Reload new reactions
  1321. comment.Reactions = nil
  1322. if err = comment.LoadReactions(); err != nil {
  1323. log.Info("comment.LoadReactions: %s", err)
  1324. break
  1325. }
  1326. log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
  1327. default:
  1328. ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.Params(":action")), nil)
  1329. return
  1330. }
  1331. if len(comment.Reactions) == 0 {
  1332. ctx.JSON(200, map[string]interface{}{
  1333. "empty": true,
  1334. "html": "",
  1335. })
  1336. return
  1337. }
  1338. html, err := ctx.HTMLString(string(tplReactions), map[string]interface{}{
  1339. "ctx": ctx.Data,
  1340. "ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
  1341. "Reactions": comment.Reactions.GroupByType(),
  1342. })
  1343. if err != nil {
  1344. ctx.ServerError("ChangeCommentReaction.HTMLString", err)
  1345. return
  1346. }
  1347. ctx.JSON(200, map[string]interface{}{
  1348. "html": html,
  1349. })
  1350. }