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

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