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

issue.go 41 kB

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