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