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 33 kB

11 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
8 years ago
9 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
8 years ago
10 years ago
10 years ago
9 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>
7 years ago
8 years ago
8 years ago
8 years ago
8 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>
7 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>
7 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>
7 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
8 years ago
9 years ago
9 years ago
8 years ago
8 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/Unknwon/com"
  15. "github.com/Unknwon/paginater"
  16. "code.gitea.io/git"
  17. "code.gitea.io/gitea/models"
  18. "code.gitea.io/gitea/modules/auth"
  19. "code.gitea.io/gitea/modules/base"
  20. "code.gitea.io/gitea/modules/context"
  21. "code.gitea.io/gitea/modules/indexer"
  22. "code.gitea.io/gitea/modules/log"
  23. "code.gitea.io/gitea/modules/markdown"
  24. "code.gitea.io/gitea/modules/notification"
  25. "code.gitea.io/gitea/modules/setting"
  26. "code.gitea.io/gitea/modules/util"
  27. )
  28. const (
  29. tplIssues base.TplName = "repo/issue/list"
  30. tplIssueNew base.TplName = "repo/issue/new"
  31. tplIssueView base.TplName = "repo/issue/view"
  32. tplMilestone base.TplName = "repo/issue/milestones"
  33. tplMilestoneNew base.TplName = "repo/issue/milestone_new"
  34. tplMilestoneEdit base.TplName = "repo/issue/milestone_edit"
  35. issueTemplateKey = "IssueTemplate"
  36. )
  37. var (
  38. // ErrFileTypeForbidden not allowed file type error
  39. ErrFileTypeForbidden = errors.New("File type is not allowed")
  40. // ErrTooManyFiles upload too many files
  41. ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
  42. // IssueTemplateCandidates issue templates
  43. IssueTemplateCandidates = []string{
  44. "ISSUE_TEMPLATE.md",
  45. "issue_template.md",
  46. ".gitea/ISSUE_TEMPLATE.md",
  47. ".gitea/issue_template.md",
  48. ".github/ISSUE_TEMPLATE.md",
  49. ".github/issue_template.md",
  50. }
  51. )
  52. // MustEnableIssues check if repository enable internal issues
  53. func MustEnableIssues(ctx *context.Context) {
  54. if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
  55. !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
  56. ctx.Handle(404, "MustEnableIssues", nil)
  57. return
  58. }
  59. unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
  60. if err == nil {
  61. ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL)
  62. return
  63. }
  64. }
  65. // MustAllowPulls check if repository enable pull requests
  66. func MustAllowPulls(ctx *context.Context) {
  67. if !ctx.Repo.Repository.AllowsPulls() {
  68. ctx.Handle(404, "MustAllowPulls", nil)
  69. return
  70. }
  71. // User can send pull request if owns a forked repository.
  72. if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
  73. ctx.Repo.PullRequest.Allowed = true
  74. ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
  75. }
  76. }
  77. // Issues render issues page
  78. func Issues(ctx *context.Context) {
  79. isPullList := ctx.Params(":type") == "pulls"
  80. if isPullList {
  81. MustAllowPulls(ctx)
  82. if ctx.Written() {
  83. return
  84. }
  85. ctx.Data["Title"] = ctx.Tr("repo.pulls")
  86. ctx.Data["PageIsPullList"] = true
  87. } else {
  88. MustEnableIssues(ctx)
  89. if ctx.Written() {
  90. return
  91. }
  92. ctx.Data["Title"] = ctx.Tr("repo.issues")
  93. ctx.Data["PageIsIssueList"] = true
  94. }
  95. viewType := ctx.Query("type")
  96. sortType := ctx.Query("sort")
  97. types := []string{"all", "assigned", "created_by", "mentioned"}
  98. if !com.IsSliceContainsStr(types, viewType) {
  99. viewType = "all"
  100. }
  101. var (
  102. assigneeID = ctx.QueryInt64("assignee")
  103. posterID int64
  104. mentionedID int64
  105. forceEmpty bool
  106. )
  107. if ctx.IsSigned {
  108. switch viewType {
  109. case "created_by":
  110. posterID = ctx.User.ID
  111. case "mentioned":
  112. mentionedID = ctx.User.ID
  113. }
  114. }
  115. repo := ctx.Repo.Repository
  116. selectLabels := ctx.Query("labels")
  117. milestoneID := ctx.QueryInt64("milestone")
  118. isShowClosed := ctx.Query("state") == "closed"
  119. keyword := strings.Trim(ctx.Query("q"), " ")
  120. if bytes.Contains([]byte(keyword), []byte{0x00}) {
  121. keyword = ""
  122. }
  123. var issueIDs []int64
  124. var err error
  125. if len(keyword) > 0 {
  126. issueIDs, err = indexer.SearchIssuesByKeyword(repo.ID, keyword)
  127. if len(issueIDs) == 0 {
  128. forceEmpty = true
  129. }
  130. }
  131. var issueStats *models.IssueStats
  132. if forceEmpty {
  133. issueStats = &models.IssueStats{}
  134. } else {
  135. var err error
  136. issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
  137. RepoID: repo.ID,
  138. Labels: selectLabels,
  139. MilestoneID: milestoneID,
  140. AssigneeID: assigneeID,
  141. MentionedID: mentionedID,
  142. PosterID: posterID,
  143. IsPull: isPullList,
  144. IssueIDs: issueIDs,
  145. })
  146. if err != nil {
  147. ctx.Handle(500, "GetIssueStats", err)
  148. return
  149. }
  150. }
  151. page := ctx.QueryInt("page")
  152. if page <= 1 {
  153. page = 1
  154. }
  155. var total int
  156. if !isShowClosed {
  157. total = int(issueStats.OpenCount)
  158. } else {
  159. total = int(issueStats.ClosedCount)
  160. }
  161. pager := paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  162. ctx.Data["Page"] = pager
  163. var issues []*models.Issue
  164. if forceEmpty {
  165. issues = []*models.Issue{}
  166. } else {
  167. issues, err = models.Issues(&models.IssuesOptions{
  168. AssigneeID: assigneeID,
  169. RepoID: repo.ID,
  170. PosterID: posterID,
  171. MentionedID: mentionedID,
  172. MilestoneID: milestoneID,
  173. Page: pager.Current(),
  174. PageSize: setting.UI.IssuePagingNum,
  175. IsClosed: util.OptionalBoolOf(isShowClosed),
  176. IsPull: util.OptionalBoolOf(isPullList),
  177. Labels: selectLabels,
  178. SortType: sortType,
  179. IssueIDs: issueIDs,
  180. })
  181. if err != nil {
  182. ctx.Handle(500, "Issues", err)
  183. return
  184. }
  185. }
  186. // Get posters.
  187. for i := range issues {
  188. // Check read status
  189. if !ctx.IsSigned {
  190. issues[i].IsRead = true
  191. } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
  192. ctx.Handle(500, "GetIsRead", err)
  193. return
  194. }
  195. }
  196. ctx.Data["Issues"] = issues
  197. // Get milestones.
  198. ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)
  199. if err != nil {
  200. ctx.Handle(500, "GetAllRepoMilestones", err)
  201. return
  202. }
  203. // Get assignees.
  204. ctx.Data["Assignees"], err = repo.GetAssignees()
  205. if err != nil {
  206. ctx.Handle(500, "GetAssignees", err)
  207. return
  208. }
  209. if ctx.QueryInt64("assignee") == 0 {
  210. assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
  211. }
  212. ctx.Data["IssueStats"] = issueStats
  213. ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64()
  214. ctx.Data["ViewType"] = viewType
  215. ctx.Data["SortType"] = sortType
  216. ctx.Data["MilestoneID"] = milestoneID
  217. ctx.Data["AssigneeID"] = assigneeID
  218. ctx.Data["IsShowClosed"] = isShowClosed
  219. ctx.Data["Keyword"] = keyword
  220. if isShowClosed {
  221. ctx.Data["State"] = "closed"
  222. } else {
  223. ctx.Data["State"] = "open"
  224. }
  225. ctx.HTML(200, tplIssues)
  226. }
  227. // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
  228. func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
  229. var err error
  230. ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
  231. if err != nil {
  232. ctx.Handle(500, "GetMilestones", err)
  233. return
  234. }
  235. ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
  236. if err != nil {
  237. ctx.Handle(500, "GetMilestones", err)
  238. return
  239. }
  240. ctx.Data["Assignees"], err = repo.GetAssignees()
  241. if err != nil {
  242. ctx.Handle(500, "GetAssignees", err)
  243. return
  244. }
  245. }
  246. // RetrieveRepoMetas find all the meta information of a repository
  247. func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
  248. if !ctx.Repo.IsWriter() {
  249. return nil
  250. }
  251. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  252. if err != nil {
  253. ctx.Handle(500, "GetLabelsByRepoID", err)
  254. return nil
  255. }
  256. ctx.Data["Labels"] = labels
  257. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  258. if ctx.Written() {
  259. return nil
  260. }
  261. brs, err := ctx.Repo.GitRepo.GetBranches()
  262. if err != nil {
  263. ctx.Handle(500, "GetBranches", err)
  264. return nil
  265. }
  266. ctx.Data["Branches"] = brs
  267. return labels
  268. }
  269. func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (string, bool) {
  270. var r io.Reader
  271. var bytes []byte
  272. if ctx.Repo.Commit == nil {
  273. var err error
  274. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
  275. if err != nil {
  276. return "", false
  277. }
  278. }
  279. entry, err := ctx.Repo.Commit.GetTreeEntryByPath(filename)
  280. if err != nil {
  281. return "", false
  282. }
  283. r, err = entry.Blob().Data()
  284. if err != nil {
  285. return "", false
  286. }
  287. bytes, err = ioutil.ReadAll(r)
  288. if err != nil {
  289. return "", false
  290. }
  291. return string(bytes), true
  292. }
  293. func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles []string) {
  294. for _, filename := range possibleFiles {
  295. content, found := getFileContentFromDefaultBranch(ctx, filename)
  296. if found {
  297. ctx.Data[ctxDataKey] = content
  298. return
  299. }
  300. }
  301. }
  302. // NewIssue render createing issue page
  303. func NewIssue(ctx *context.Context) {
  304. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  305. ctx.Data["PageIsIssueList"] = true
  306. ctx.Data["RequireHighlightJS"] = true
  307. ctx.Data["RequireSimpleMDE"] = true
  308. setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
  309. renderAttachmentSettings(ctx)
  310. RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  311. if ctx.Written() {
  312. return
  313. }
  314. ctx.HTML(200, tplIssueNew)
  315. }
  316. // ValidateRepoMetas check and returns repository's meta informations
  317. func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64, int64, int64) {
  318. var (
  319. repo = ctx.Repo.Repository
  320. err error
  321. )
  322. labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  323. if ctx.Written() {
  324. return nil, 0, 0
  325. }
  326. if !ctx.Repo.IsWriter() {
  327. return nil, 0, 0
  328. }
  329. var labelIDs []int64
  330. hasSelected := false
  331. // Check labels.
  332. if len(form.LabelIDs) > 0 {
  333. labelIDs, err = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
  334. if err != nil {
  335. return nil, 0, 0
  336. }
  337. labelIDMark := base.Int64sToMap(labelIDs)
  338. for i := range labels {
  339. if labelIDMark[labels[i].ID] {
  340. labels[i].IsChecked = true
  341. hasSelected = true
  342. }
  343. }
  344. }
  345. ctx.Data["Labels"] = labels
  346. ctx.Data["HasSelectedLabel"] = hasSelected
  347. ctx.Data["label_ids"] = form.LabelIDs
  348. // Check milestone.
  349. milestoneID := form.MilestoneID
  350. if milestoneID > 0 {
  351. ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
  352. if err != nil {
  353. ctx.Handle(500, "GetMilestoneByID", err)
  354. return nil, 0, 0
  355. }
  356. ctx.Data["milestone_id"] = milestoneID
  357. }
  358. // Check assignee.
  359. assigneeID := form.AssigneeID
  360. if assigneeID > 0 {
  361. ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID)
  362. if err != nil {
  363. ctx.Handle(500, "GetAssigneeByID", err)
  364. return nil, 0, 0
  365. }
  366. ctx.Data["assignee_id"] = assigneeID
  367. }
  368. return labelIDs, milestoneID, assigneeID
  369. }
  370. // NewIssuePost response for creating new issue
  371. func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
  372. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  373. ctx.Data["PageIsIssueList"] = true
  374. ctx.Data["RequireHighlightJS"] = true
  375. ctx.Data["RequireSimpleMDE"] = true
  376. ctx.Data["ReadOnly"] = false
  377. renderAttachmentSettings(ctx)
  378. var (
  379. repo = ctx.Repo.Repository
  380. attachments []string
  381. )
  382. labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, form)
  383. if ctx.Written() {
  384. return
  385. }
  386. if setting.AttachmentEnabled {
  387. attachments = form.Files
  388. }
  389. if ctx.HasError() {
  390. ctx.HTML(200, tplIssueNew)
  391. return
  392. }
  393. issue := &models.Issue{
  394. RepoID: repo.ID,
  395. Title: form.Title,
  396. PosterID: ctx.User.ID,
  397. Poster: ctx.User,
  398. MilestoneID: milestoneID,
  399. AssigneeID: assigneeID,
  400. Content: form.Content,
  401. Ref: form.Ref,
  402. }
  403. if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil {
  404. ctx.Handle(500, "NewIssue", err)
  405. return
  406. }
  407. notification.Service.NotifyIssue(issue, ctx.User.ID)
  408. log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
  409. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  410. }
  411. // ViewIssue render issue view page
  412. func ViewIssue(ctx *context.Context) {
  413. ctx.Data["RequireHighlightJS"] = true
  414. ctx.Data["RequireDropzone"] = true
  415. renderAttachmentSettings(ctx)
  416. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  417. if err != nil {
  418. if models.IsErrIssueNotExist(err) {
  419. ctx.Handle(404, "GetIssueByIndex", err)
  420. } else {
  421. ctx.Handle(500, "GetIssueByIndex", err)
  422. }
  423. return
  424. }
  425. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  426. var iw *models.IssueWatch
  427. var exists bool
  428. if ctx.User != nil {
  429. iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
  430. if err != nil {
  431. ctx.Handle(500, "GetIssueWatch", err)
  432. return
  433. }
  434. if !exists {
  435. iw = &models.IssueWatch{
  436. UserID: ctx.User.ID,
  437. IssueID: issue.ID,
  438. IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
  439. }
  440. }
  441. }
  442. ctx.Data["IssueWatch"] = iw
  443. // Make sure type and URL matches.
  444. if ctx.Params(":type") == "issues" && issue.IsPull {
  445. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  446. return
  447. } else if ctx.Params(":type") == "pulls" && !issue.IsPull {
  448. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  449. return
  450. }
  451. if issue.IsPull {
  452. MustAllowPulls(ctx)
  453. if ctx.Written() {
  454. return
  455. }
  456. ctx.Data["PageIsPullList"] = true
  457. ctx.Data["PageIsPullConversation"] = true
  458. } else {
  459. MustEnableIssues(ctx)
  460. if ctx.Written() {
  461. return
  462. }
  463. ctx.Data["PageIsIssueList"] = true
  464. }
  465. issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
  466. ctx.Repo.Repository.ComposeMetas()))
  467. repo := ctx.Repo.Repository
  468. // Get more information if it's a pull request.
  469. if issue.IsPull {
  470. if issue.PullRequest.HasMerged {
  471. ctx.Data["DisableStatusChange"] = issue.PullRequest.HasMerged
  472. PrepareMergedViewPullInfo(ctx, issue)
  473. } else {
  474. PrepareViewPullInfo(ctx, issue)
  475. }
  476. if ctx.Written() {
  477. return
  478. }
  479. }
  480. // Metas.
  481. // Check labels.
  482. labelIDMark := make(map[int64]bool)
  483. for i := range issue.Labels {
  484. labelIDMark[issue.Labels[i].ID] = true
  485. }
  486. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  487. if err != nil {
  488. ctx.Handle(500, "GetLabelsByRepoID", err)
  489. return
  490. }
  491. hasSelected := false
  492. for i := range labels {
  493. if labelIDMark[labels[i].ID] {
  494. labels[i].IsChecked = true
  495. hasSelected = true
  496. }
  497. }
  498. ctx.Data["HasSelectedLabel"] = hasSelected
  499. ctx.Data["Labels"] = labels
  500. // Check milestone and assignee.
  501. if ctx.Repo.IsWriter() {
  502. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  503. if ctx.Written() {
  504. return
  505. }
  506. }
  507. if ctx.IsSigned {
  508. // Update issue-user.
  509. if err = issue.ReadBy(ctx.User.ID); err != nil {
  510. ctx.Handle(500, "ReadBy", err)
  511. return
  512. }
  513. }
  514. var (
  515. tag models.CommentTag
  516. ok bool
  517. marked = make(map[int64]models.CommentTag)
  518. comment *models.Comment
  519. participants = make([]*models.User, 1, 10)
  520. )
  521. if ctx.Repo.Repository.IsTimetrackerEnabled() {
  522. if ctx.IsSigned {
  523. // Deal with the stopwatch
  524. ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
  525. if !ctx.Data["IsStopwatchRunning"].(bool) {
  526. var exists bool
  527. var sw *models.Stopwatch
  528. if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
  529. ctx.Handle(500, "HasUserStopwatch", err)
  530. return
  531. }
  532. ctx.Data["HasUserStopwatch"] = exists
  533. if exists {
  534. // Add warning if the user has already a stopwatch
  535. var otherIssue *models.Issue
  536. if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
  537. ctx.Handle(500, "GetIssueByID", err)
  538. return
  539. }
  540. // Add link to the issue of the already running stopwatch
  541. ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
  542. }
  543. }
  544. ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
  545. } else {
  546. ctx.Data["CanUseTimetracker"] = false
  547. }
  548. if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
  549. ctx.Handle(500, "TotalTimes", err)
  550. return
  551. }
  552. }
  553. // Render comments and and fetch participants.
  554. participants[0] = issue.Poster
  555. for _, comment = range issue.Comments {
  556. if comment.Type == models.CommentTypeComment {
  557. comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink,
  558. ctx.Repo.Repository.ComposeMetas()))
  559. // Check tag.
  560. tag, ok = marked[comment.PosterID]
  561. if ok {
  562. comment.ShowTag = tag
  563. continue
  564. }
  565. if repo.IsOwnedBy(comment.PosterID) ||
  566. (repo.Owner.IsOrganization() && repo.Owner.IsOwnedBy(comment.PosterID)) {
  567. comment.ShowTag = models.CommentTagOwner
  568. } else if comment.Poster.IsWriterOfRepo(repo) {
  569. comment.ShowTag = models.CommentTagWriter
  570. } else if comment.PosterID == issue.PosterID {
  571. comment.ShowTag = models.CommentTagPoster
  572. }
  573. marked[comment.PosterID] = comment.ShowTag
  574. isAdded := false
  575. for j := range participants {
  576. if comment.Poster == participants[j] {
  577. isAdded = true
  578. break
  579. }
  580. }
  581. if !isAdded && !issue.IsPoster(comment.Poster.ID) {
  582. participants = append(participants, comment.Poster)
  583. }
  584. } else if comment.Type == models.CommentTypeLabel {
  585. if err = comment.LoadLabel(); err != nil {
  586. ctx.Handle(500, "LoadLabel", err)
  587. return
  588. }
  589. } else if comment.Type == models.CommentTypeMilestone {
  590. if err = comment.LoadMilestone(); err != nil {
  591. ctx.Handle(500, "LoadMilestone", err)
  592. return
  593. }
  594. ghostMilestone := &models.Milestone{
  595. ID: -1,
  596. Name: ctx.Tr("repo.issues.deleted_milestone"),
  597. }
  598. if comment.OldMilestoneID > 0 && comment.OldMilestone == nil {
  599. comment.OldMilestone = ghostMilestone
  600. }
  601. if comment.MilestoneID > 0 && comment.Milestone == nil {
  602. comment.Milestone = ghostMilestone
  603. }
  604. } else if comment.Type == models.CommentTypeAssignees {
  605. if err = comment.LoadAssignees(); err != nil {
  606. ctx.Handle(500, "LoadAssignees", err)
  607. return
  608. }
  609. }
  610. }
  611. if issue.IsPull {
  612. pull := issue.PullRequest
  613. canDelete := false
  614. if ctx.IsSigned {
  615. if err := pull.GetHeadRepo(); err != nil {
  616. log.Error(4, "GetHeadRepo: %v", err)
  617. } else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch && ctx.User.IsWriterOfRepo(pull.HeadRepo) {
  618. // Check if branch is not protected
  619. if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch, ctx.User); err != nil {
  620. log.Error(4, "IsProtectedBranch: %v", err)
  621. } else if !protected {
  622. canDelete = true
  623. ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
  624. }
  625. }
  626. }
  627. ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
  628. }
  629. ctx.Data["Participants"] = participants
  630. ctx.Data["NumParticipants"] = len(participants)
  631. ctx.Data["Issue"] = issue
  632. ctx.Data["ReadOnly"] = true
  633. ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
  634. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
  635. ctx.HTML(200, tplIssueView)
  636. }
  637. // GetActionIssue will return the issue which is used in the context.
  638. func GetActionIssue(ctx *context.Context) *models.Issue {
  639. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  640. if err != nil {
  641. if models.IsErrIssueNotExist(err) {
  642. ctx.Error(404, "GetIssueByIndex")
  643. } else {
  644. ctx.Handle(500, "GetIssueByIndex", err)
  645. }
  646. return nil
  647. }
  648. return issue
  649. }
  650. func getActionIssues(ctx *context.Context) []*models.Issue {
  651. commaSeparatedIssueIDs := ctx.Query("issue_ids")
  652. if len(commaSeparatedIssueIDs) == 0 {
  653. return nil
  654. }
  655. issueIDs := make([]int64, 0, 10)
  656. for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
  657. issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
  658. if err != nil {
  659. ctx.Handle(500, "ParseInt", err)
  660. return nil
  661. }
  662. issueIDs = append(issueIDs, issueID)
  663. }
  664. issues, err := models.GetIssuesByIDs(issueIDs)
  665. if err != nil {
  666. ctx.Handle(500, "GetIssuesByIDs", err)
  667. return nil
  668. }
  669. return issues
  670. }
  671. // UpdateIssueTitle change issue's title
  672. func UpdateIssueTitle(ctx *context.Context) {
  673. issue := GetActionIssue(ctx)
  674. if ctx.Written() {
  675. return
  676. }
  677. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) {
  678. ctx.Error(403)
  679. return
  680. }
  681. title := ctx.QueryTrim("title")
  682. if len(title) == 0 {
  683. ctx.Error(204)
  684. return
  685. }
  686. if err := issue.ChangeTitle(ctx.User, title); err != nil {
  687. ctx.Handle(500, "ChangeTitle", err)
  688. return
  689. }
  690. ctx.JSON(200, map[string]interface{}{
  691. "title": issue.Title,
  692. })
  693. }
  694. // UpdateIssueContent change issue's content
  695. func UpdateIssueContent(ctx *context.Context) {
  696. issue := GetActionIssue(ctx)
  697. if ctx.Written() {
  698. return
  699. }
  700. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) {
  701. ctx.Error(403)
  702. return
  703. }
  704. content := ctx.Query("content")
  705. if err := issue.ChangeContent(ctx.User, content); err != nil {
  706. ctx.Handle(500, "ChangeContent", err)
  707. return
  708. }
  709. ctx.JSON(200, map[string]interface{}{
  710. "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  711. })
  712. }
  713. // UpdateIssueMilestone change issue's milestone
  714. func UpdateIssueMilestone(ctx *context.Context) {
  715. issues := getActionIssues(ctx)
  716. if ctx.Written() {
  717. return
  718. }
  719. milestoneID := ctx.QueryInt64("id")
  720. for _, issue := range issues {
  721. oldMilestoneID := issue.MilestoneID
  722. if oldMilestoneID == milestoneID {
  723. continue
  724. }
  725. issue.MilestoneID = milestoneID
  726. if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
  727. ctx.Handle(500, "ChangeMilestoneAssign", err)
  728. return
  729. }
  730. }
  731. ctx.JSON(200, map[string]interface{}{
  732. "ok": true,
  733. })
  734. }
  735. // UpdateIssueAssignee change issue's assignee
  736. func UpdateIssueAssignee(ctx *context.Context) {
  737. issues := getActionIssues(ctx)
  738. if ctx.Written() {
  739. return
  740. }
  741. assigneeID := ctx.QueryInt64("id")
  742. for _, issue := range issues {
  743. if issue.AssigneeID == assigneeID {
  744. continue
  745. }
  746. if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil {
  747. ctx.Handle(500, "ChangeAssignee", err)
  748. return
  749. }
  750. }
  751. ctx.JSON(200, map[string]interface{}{
  752. "ok": true,
  753. })
  754. }
  755. // UpdateIssueStatus change issue's status
  756. func UpdateIssueStatus(ctx *context.Context) {
  757. issues := getActionIssues(ctx)
  758. if ctx.Written() {
  759. return
  760. }
  761. var isClosed bool
  762. switch action := ctx.Query("action"); action {
  763. case "open":
  764. isClosed = false
  765. case "close":
  766. isClosed = true
  767. default:
  768. log.Warn("Unrecognized action: %s", action)
  769. }
  770. if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
  771. ctx.Handle(500, "LoadRepositories", err)
  772. return
  773. }
  774. for _, issue := range issues {
  775. if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
  776. ctx.Handle(500, "ChangeStatus", err)
  777. return
  778. }
  779. }
  780. ctx.JSON(200, map[string]interface{}{
  781. "ok": true,
  782. })
  783. }
  784. // NewComment create a comment for issue
  785. func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
  786. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  787. if err != nil {
  788. ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
  789. return
  790. }
  791. var attachments []string
  792. if setting.AttachmentEnabled {
  793. attachments = form.Files
  794. }
  795. if ctx.HasError() {
  796. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  797. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
  798. return
  799. }
  800. var comment *models.Comment
  801. defer func() {
  802. // Check if issue admin/poster changes the status of issue.
  803. if (ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
  804. (form.Status == "reopen" || form.Status == "close") &&
  805. !(issue.IsPull && issue.PullRequest.HasMerged) {
  806. // Duplication and conflict check should apply to reopen pull request.
  807. var pr *models.PullRequest
  808. if form.Status == "reopen" && issue.IsPull {
  809. pull := issue.PullRequest
  810. pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
  811. if err != nil {
  812. if !models.IsErrPullRequestNotExist(err) {
  813. ctx.Handle(500, "GetUnmergedPullRequest", err)
  814. return
  815. }
  816. }
  817. // Regenerate patch and test conflict.
  818. if pr == nil {
  819. if err = issue.PullRequest.UpdatePatch(); err != nil {
  820. ctx.Handle(500, "UpdatePatch", err)
  821. return
  822. }
  823. issue.PullRequest.AddToTaskQueue()
  824. }
  825. }
  826. if pr != nil {
  827. ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
  828. } else {
  829. if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
  830. log.Error(4, "ChangeStatus: %v", err)
  831. } else {
  832. log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
  833. notification.Service.NotifyIssue(issue, ctx.User.ID)
  834. }
  835. }
  836. }
  837. // Redirect to comment hashtag if there is any actual content.
  838. typeName := "issues"
  839. if issue.IsPull {
  840. typeName = "pulls"
  841. }
  842. if comment != nil {
  843. ctx.Redirect(fmt.Sprintf("%s/%s/%d#%s", ctx.Repo.RepoLink, typeName, issue.Index, comment.HashTag()))
  844. } else {
  845. ctx.Redirect(fmt.Sprintf("%s/%s/%d", ctx.Repo.RepoLink, typeName, issue.Index))
  846. }
  847. }()
  848. // Fix #321: Allow empty comments, as long as we have attachments.
  849. if len(form.Content) == 0 && len(attachments) == 0 {
  850. return
  851. }
  852. comment, err = models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
  853. if err != nil {
  854. ctx.Handle(500, "CreateIssueComment", err)
  855. return
  856. }
  857. notification.Service.NotifyIssue(issue, ctx.User.ID)
  858. log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
  859. }
  860. // UpdateCommentContent change comment of issue's content
  861. func UpdateCommentContent(ctx *context.Context) {
  862. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  863. if err != nil {
  864. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  865. return
  866. }
  867. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  868. ctx.Error(403)
  869. return
  870. } else if comment.Type != models.CommentTypeComment {
  871. ctx.Error(204)
  872. return
  873. }
  874. comment.Content = ctx.Query("content")
  875. if len(comment.Content) == 0 {
  876. ctx.JSON(200, map[string]interface{}{
  877. "content": "",
  878. })
  879. return
  880. }
  881. if err = models.UpdateComment(comment); err != nil {
  882. ctx.Handle(500, "UpdateComment", err)
  883. return
  884. }
  885. ctx.JSON(200, map[string]interface{}{
  886. "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  887. })
  888. }
  889. // DeleteComment delete comment of issue
  890. func DeleteComment(ctx *context.Context) {
  891. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  892. if err != nil {
  893. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  894. return
  895. }
  896. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  897. ctx.Error(403)
  898. return
  899. } else if comment.Type != models.CommentTypeComment {
  900. ctx.Error(204)
  901. return
  902. }
  903. if err = models.DeleteComment(comment); err != nil {
  904. ctx.Handle(500, "DeleteCommentByID", err)
  905. return
  906. }
  907. ctx.Status(200)
  908. }
  909. // Milestones render milestones page
  910. func Milestones(ctx *context.Context) {
  911. MustEnableIssues(ctx)
  912. if ctx.Written() {
  913. return
  914. }
  915. ctx.Data["Title"] = ctx.Tr("repo.milestones")
  916. ctx.Data["PageIsIssueList"] = true
  917. ctx.Data["PageIsMilestones"] = true
  918. isShowClosed := ctx.Query("state") == "closed"
  919. openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.ID)
  920. ctx.Data["OpenCount"] = openCount
  921. ctx.Data["ClosedCount"] = closedCount
  922. sortType := ctx.Query("sort")
  923. page := ctx.QueryInt("page")
  924. if page <= 1 {
  925. page = 1
  926. }
  927. var total int
  928. if !isShowClosed {
  929. total = int(openCount)
  930. } else {
  931. total = int(closedCount)
  932. }
  933. ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  934. miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
  935. if err != nil {
  936. ctx.Handle(500, "GetMilestones", err)
  937. return
  938. }
  939. for _, m := range miles {
  940. m.RenderedContent = string(markdown.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
  941. }
  942. ctx.Data["Milestones"] = miles
  943. if isShowClosed {
  944. ctx.Data["State"] = "closed"
  945. } else {
  946. ctx.Data["State"] = "open"
  947. }
  948. ctx.Data["SortType"] = sortType
  949. ctx.Data["IsShowClosed"] = isShowClosed
  950. ctx.HTML(200, tplMilestone)
  951. }
  952. // NewMilestone render creating milestone page
  953. func NewMilestone(ctx *context.Context) {
  954. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  955. ctx.Data["PageIsIssueList"] = true
  956. ctx.Data["PageIsMilestones"] = true
  957. ctx.Data["RequireDatetimepicker"] = true
  958. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  959. ctx.HTML(200, tplMilestoneNew)
  960. }
  961. // NewMilestonePost response for creating milestone
  962. func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  963. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  964. ctx.Data["PageIsIssueList"] = true
  965. ctx.Data["PageIsMilestones"] = true
  966. ctx.Data["RequireDatetimepicker"] = true
  967. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  968. if ctx.HasError() {
  969. ctx.HTML(200, tplMilestoneNew)
  970. return
  971. }
  972. if len(form.Deadline) == 0 {
  973. form.Deadline = "9999-12-31"
  974. }
  975. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  976. if err != nil {
  977. ctx.Data["Err_Deadline"] = true
  978. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  979. return
  980. }
  981. if err = models.NewMilestone(&models.Milestone{
  982. RepoID: ctx.Repo.Repository.ID,
  983. Name: form.Title,
  984. Content: form.Content,
  985. Deadline: deadline,
  986. }); err != nil {
  987. ctx.Handle(500, "NewMilestone", err)
  988. return
  989. }
  990. ctx.Flash.Success(ctx.Tr("repo.milestones.create_success", form.Title))
  991. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  992. }
  993. // EditMilestone render edting milestone page
  994. func EditMilestone(ctx *context.Context) {
  995. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  996. ctx.Data["PageIsMilestones"] = true
  997. ctx.Data["PageIsEditMilestone"] = true
  998. ctx.Data["RequireDatetimepicker"] = true
  999. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1000. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1001. if err != nil {
  1002. if models.IsErrMilestoneNotExist(err) {
  1003. ctx.Handle(404, "", nil)
  1004. } else {
  1005. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1006. }
  1007. return
  1008. }
  1009. ctx.Data["title"] = m.Name
  1010. ctx.Data["content"] = m.Content
  1011. if len(m.DeadlineString) > 0 {
  1012. ctx.Data["deadline"] = m.DeadlineString
  1013. }
  1014. ctx.HTML(200, tplMilestoneNew)
  1015. }
  1016. // EditMilestonePost response for edting milestone
  1017. func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  1018. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  1019. ctx.Data["PageIsMilestones"] = true
  1020. ctx.Data["PageIsEditMilestone"] = true
  1021. ctx.Data["RequireDatetimepicker"] = true
  1022. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1023. if ctx.HasError() {
  1024. ctx.HTML(200, tplMilestoneNew)
  1025. return
  1026. }
  1027. if len(form.Deadline) == 0 {
  1028. form.Deadline = "9999-12-31"
  1029. }
  1030. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  1031. if err != nil {
  1032. ctx.Data["Err_Deadline"] = true
  1033. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  1034. return
  1035. }
  1036. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1037. if err != nil {
  1038. if models.IsErrMilestoneNotExist(err) {
  1039. ctx.Handle(404, "", nil)
  1040. } else {
  1041. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1042. }
  1043. return
  1044. }
  1045. m.Name = form.Title
  1046. m.Content = form.Content
  1047. m.Deadline = deadline
  1048. if err = models.UpdateMilestone(m); err != nil {
  1049. ctx.Handle(500, "UpdateMilestone", err)
  1050. return
  1051. }
  1052. ctx.Flash.Success(ctx.Tr("repo.milestones.edit_success", m.Name))
  1053. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1054. }
  1055. // ChangeMilestonStatus response for change a milestone's status
  1056. func ChangeMilestonStatus(ctx *context.Context) {
  1057. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1058. if err != nil {
  1059. if models.IsErrMilestoneNotExist(err) {
  1060. ctx.Handle(404, "", err)
  1061. } else {
  1062. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1063. }
  1064. return
  1065. }
  1066. switch ctx.Params(":action") {
  1067. case "open":
  1068. if m.IsClosed {
  1069. if err = models.ChangeMilestoneStatus(m, false); err != nil {
  1070. ctx.Handle(500, "ChangeMilestoneStatus", err)
  1071. return
  1072. }
  1073. }
  1074. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open")
  1075. case "close":
  1076. if !m.IsClosed {
  1077. m.ClosedDate = time.Now()
  1078. if err = models.ChangeMilestoneStatus(m, true); err != nil {
  1079. ctx.Handle(500, "ChangeMilestoneStatus", err)
  1080. return
  1081. }
  1082. }
  1083. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=closed")
  1084. default:
  1085. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1086. }
  1087. }
  1088. // DeleteMilestone delete a milestone
  1089. func DeleteMilestone(ctx *context.Context) {
  1090. if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
  1091. ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
  1092. } else {
  1093. ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
  1094. }
  1095. ctx.JSON(200, map[string]interface{}{
  1096. "redirect": ctx.Repo.RepoLink + "/milestones",
  1097. })
  1098. }