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

792 lines
30 KiB

Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
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>
6 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>
6 years ago
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package routes
  5. import (
  6. "encoding/gob"
  7. "net/http"
  8. "os"
  9. "path"
  10. "time"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/auth"
  13. "code.gitea.io/gitea/modules/context"
  14. "code.gitea.io/gitea/modules/lfs"
  15. "code.gitea.io/gitea/modules/log"
  16. "code.gitea.io/gitea/modules/options"
  17. "code.gitea.io/gitea/modules/public"
  18. "code.gitea.io/gitea/modules/setting"
  19. "code.gitea.io/gitea/modules/templates"
  20. "code.gitea.io/gitea/modules/validation"
  21. "code.gitea.io/gitea/routers"
  22. "code.gitea.io/gitea/routers/admin"
  23. apiv1 "code.gitea.io/gitea/routers/api/v1"
  24. "code.gitea.io/gitea/routers/dev"
  25. "code.gitea.io/gitea/routers/org"
  26. "code.gitea.io/gitea/routers/private"
  27. "code.gitea.io/gitea/routers/repo"
  28. "code.gitea.io/gitea/routers/user"
  29. userSetting "code.gitea.io/gitea/routers/user/setting"
  30. "github.com/go-macaron/binding"
  31. "github.com/go-macaron/cache"
  32. "github.com/go-macaron/captcha"
  33. "github.com/go-macaron/csrf"
  34. "github.com/go-macaron/gzip"
  35. "github.com/go-macaron/i18n"
  36. "github.com/go-macaron/session"
  37. "github.com/go-macaron/toolbox"
  38. "github.com/tstranex/u2f"
  39. "gopkg.in/macaron.v1"
  40. )
  41. // NewMacaron initializes Macaron instance.
  42. func NewMacaron() *macaron.Macaron {
  43. gob.Register(&u2f.Challenge{})
  44. m := macaron.New()
  45. if !setting.DisableRouterLog {
  46. m.Use(macaron.Logger())
  47. }
  48. m.Use(macaron.Recovery())
  49. if setting.EnableGzip {
  50. m.Use(gzip.Gziper())
  51. }
  52. if setting.Protocol == setting.FCGI {
  53. m.SetURLPrefix(setting.AppSubURL)
  54. }
  55. m.Use(public.Custom(
  56. &public.Options{
  57. SkipLogging: setting.DisableRouterLog,
  58. ExpiresAfter: time.Hour * 6,
  59. },
  60. ))
  61. m.Use(public.Static(
  62. &public.Options{
  63. Directory: path.Join(setting.StaticRootPath, "public"),
  64. SkipLogging: setting.DisableRouterLog,
  65. ExpiresAfter: time.Hour * 6,
  66. },
  67. ))
  68. m.Use(public.StaticHandler(
  69. setting.AvatarUploadPath,
  70. &public.Options{
  71. Prefix: "avatars",
  72. SkipLogging: setting.DisableRouterLog,
  73. ExpiresAfter: time.Hour * 6,
  74. },
  75. ))
  76. m.Use(templates.HTMLRenderer())
  77. models.InitMailRender(templates.Mailer())
  78. localeNames, err := options.Dir("locale")
  79. if err != nil {
  80. log.Fatal(4, "Failed to list locale files: %v", err)
  81. }
  82. localFiles := make(map[string][]byte)
  83. for _, name := range localeNames {
  84. localFiles[name], err = options.Locale(name)
  85. if err != nil {
  86. log.Fatal(4, "Failed to load %s locale file. %v", name, err)
  87. }
  88. }
  89. m.Use(i18n.I18n(i18n.Options{
  90. SubURL: setting.AppSubURL,
  91. Files: localFiles,
  92. Langs: setting.Langs,
  93. Names: setting.Names,
  94. DefaultLang: "en-US",
  95. Redirect: true,
  96. }))
  97. m.Use(cache.Cacher(cache.Options{
  98. Adapter: setting.CacheService.Adapter,
  99. AdapterConfig: setting.CacheService.Conn,
  100. Interval: setting.CacheService.Interval,
  101. }))
  102. m.Use(captcha.Captchaer(captcha.Options{
  103. SubURL: setting.AppSubURL,
  104. }))
  105. m.Use(session.Sessioner(setting.SessionConfig))
  106. m.Use(csrf.Csrfer(csrf.Options{
  107. Secret: setting.SecretKey,
  108. Cookie: setting.CSRFCookieName,
  109. SetCookie: true,
  110. Secure: setting.SessionConfig.Secure,
  111. CookieHttpOnly: true,
  112. Header: "X-Csrf-Token",
  113. CookiePath: setting.AppSubURL,
  114. }))
  115. m.Use(toolbox.Toolboxer(m, toolbox.Options{
  116. HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
  117. {
  118. Desc: "Database connection",
  119. Func: models.Ping,
  120. },
  121. },
  122. DisableDebug: !setting.EnablePprof,
  123. }))
  124. m.Use(context.Contexter())
  125. return m
  126. }
  127. // RegisterRoutes routes routes to Macaron
  128. func RegisterRoutes(m *macaron.Macaron) {
  129. reqSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: true})
  130. ignSignIn := context.Toggle(&context.ToggleOptions{SignInRequired: setting.Service.RequireSignInView})
  131. ignSignInAndCsrf := context.Toggle(&context.ToggleOptions{DisableCSRF: true})
  132. reqSignOut := context.Toggle(&context.ToggleOptions{SignOutRequired: true})
  133. bindIgnErr := binding.BindIgnErr
  134. validation.AddBindingRules()
  135. openIDSignInEnabled := func(ctx *context.Context) {
  136. if !setting.Service.EnableOpenIDSignIn {
  137. ctx.Error(403)
  138. return
  139. }
  140. }
  141. openIDSignUpEnabled := func(ctx *context.Context) {
  142. if !setting.Service.EnableOpenIDSignUp {
  143. ctx.Error(403)
  144. return
  145. }
  146. }
  147. m.Use(user.GetNotificationCount)
  148. // FIXME: not all routes need go through same middlewares.
  149. // Especially some AJAX requests, we can reduce middleware number to improve performance.
  150. // Routers.
  151. // for health check
  152. m.Head("/", func() string {
  153. return ""
  154. })
  155. m.Get("/", routers.Home)
  156. m.Group("/explore", func() {
  157. m.Get("", func(ctx *context.Context) {
  158. ctx.Redirect(setting.AppSubURL + "/explore/repos")
  159. })
  160. m.Get("/repos", routers.ExploreRepos)
  161. m.Get("/users", routers.ExploreUsers)
  162. m.Get("/organizations", routers.ExploreOrganizations)
  163. m.Get("/code", routers.ExploreCode)
  164. }, ignSignIn)
  165. m.Combo("/install", routers.InstallInit).Get(routers.Install).
  166. Post(bindIgnErr(auth.InstallForm{}), routers.InstallPost)
  167. m.Get("/^:type(issues|pulls)$", reqSignIn, user.Issues)
  168. // ***** START: User *****
  169. m.Group("/user", func() {
  170. m.Get("/login", user.SignIn)
  171. m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)
  172. m.Group("", func() {
  173. m.Combo("/login/openid").
  174. Get(user.SignInOpenID).
  175. Post(bindIgnErr(auth.SignInOpenIDForm{}), user.SignInOpenIDPost)
  176. }, openIDSignInEnabled)
  177. m.Group("/openid", func() {
  178. m.Combo("/connect").
  179. Get(user.ConnectOpenID).
  180. Post(bindIgnErr(auth.ConnectOpenIDForm{}), user.ConnectOpenIDPost)
  181. m.Group("/register", func() {
  182. m.Combo("").
  183. Get(user.RegisterOpenID, openIDSignUpEnabled).
  184. Post(bindIgnErr(auth.SignUpOpenIDForm{}), user.RegisterOpenIDPost)
  185. }, openIDSignUpEnabled)
  186. }, openIDSignInEnabled)
  187. m.Get("/sign_up", user.SignUp)
  188. m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost)
  189. m.Get("/reset_password", user.ResetPasswd)
  190. m.Post("/reset_password", user.ResetPasswdPost)
  191. m.Group("/oauth2", func() {
  192. m.Get("/:provider", user.SignInOAuth)
  193. m.Get("/:provider/callback", user.SignInOAuthCallback)
  194. })
  195. m.Get("/link_account", user.LinkAccount)
  196. m.Post("/link_account_signin", bindIgnErr(auth.SignInForm{}), user.LinkAccountPostSignIn)
  197. m.Post("/link_account_signup", bindIgnErr(auth.RegisterForm{}), user.LinkAccountPostRegister)
  198. m.Group("/two_factor", func() {
  199. m.Get("", user.TwoFactor)
  200. m.Post("", bindIgnErr(auth.TwoFactorAuthForm{}), user.TwoFactorPost)
  201. m.Get("/scratch", user.TwoFactorScratch)
  202. m.Post("/scratch", bindIgnErr(auth.TwoFactorScratchAuthForm{}), user.TwoFactorScratchPost)
  203. })
  204. m.Group("/u2f", func() {
  205. m.Get("", user.U2F)
  206. m.Get("/challenge", user.U2FChallenge)
  207. m.Post("/sign", bindIgnErr(u2f.SignResponse{}), user.U2FSign)
  208. })
  209. }, reqSignOut)
  210. m.Group("/user/settings", func() {
  211. m.Get("", userSetting.Profile)
  212. m.Post("", bindIgnErr(auth.UpdateProfileForm{}), userSetting.ProfilePost)
  213. m.Get("/change_password", user.MustChangePassword)
  214. m.Post("/change_password", bindIgnErr(auth.MustChangePasswordForm{}), user.MustChangePasswordPost)
  215. m.Post("/avatar", binding.MultipartForm(auth.AvatarForm{}), userSetting.AvatarPost)
  216. m.Post("/avatar/delete", userSetting.DeleteAvatar)
  217. m.Group("/account", func() {
  218. m.Combo("").Get(userSetting.Account).Post(bindIgnErr(auth.ChangePasswordForm{}), userSetting.AccountPost)
  219. m.Post("/email", bindIgnErr(auth.AddEmailForm{}), userSetting.EmailPost)
  220. m.Post("/email/delete", userSetting.DeleteEmail)
  221. m.Post("/delete", userSetting.DeleteAccount)
  222. })
  223. m.Group("/security", func() {
  224. m.Get("", userSetting.Security)
  225. m.Group("/two_factor", func() {
  226. m.Post("/regenerate_scratch", userSetting.RegenerateScratchTwoFactor)
  227. m.Post("/disable", userSetting.DisableTwoFactor)
  228. m.Get("/enroll", userSetting.EnrollTwoFactor)
  229. m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), userSetting.EnrollTwoFactorPost)
  230. })
  231. m.Group("/u2f", func() {
  232. m.Post("/request_register", bindIgnErr(auth.U2FRegistrationForm{}), userSetting.U2FRegister)
  233. m.Post("/register", bindIgnErr(u2f.RegisterResponse{}), userSetting.U2FRegisterPost)
  234. m.Post("/delete", bindIgnErr(auth.U2FDeleteForm{}), userSetting.U2FDelete)
  235. })
  236. m.Group("/openid", func() {
  237. m.Post("", bindIgnErr(auth.AddOpenIDForm{}), userSetting.OpenIDPost)
  238. m.Post("/delete", userSetting.DeleteOpenID)
  239. m.Post("/toggle_visibility", userSetting.ToggleOpenIDVisibility)
  240. }, openIDSignInEnabled)
  241. m.Post("/account_link", userSetting.DeleteAccountLink)
  242. })
  243. m.Combo("/applications").Get(userSetting.Applications).
  244. Post(bindIgnErr(auth.NewAccessTokenForm{}), userSetting.ApplicationsPost)
  245. m.Post("/applications/delete", userSetting.DeleteApplication)
  246. m.Combo("/keys").Get(userSetting.Keys).
  247. Post(bindIgnErr(auth.AddKeyForm{}), userSetting.KeysPost)
  248. m.Post("/keys/delete", userSetting.DeleteKey)
  249. m.Get("/organization", userSetting.Organization)
  250. m.Get("/repos", userSetting.Repos)
  251. // redirects from old settings urls to new ones
  252. // TODO: can be removed on next major version
  253. m.Get("/avatar", func(ctx *context.Context) {
  254. ctx.Redirect(setting.AppSubURL+"/user/settings", http.StatusMovedPermanently)
  255. })
  256. m.Get("/email", func(ctx *context.Context) {
  257. ctx.Redirect(setting.AppSubURL+"/user/settings/account", http.StatusMovedPermanently)
  258. })
  259. m.Get("/delete", func(ctx *context.Context) {
  260. ctx.Redirect(setting.AppSubURL+"/user/settings/account", http.StatusMovedPermanently)
  261. })
  262. m.Get("/openid", func(ctx *context.Context) {
  263. ctx.Redirect(setting.AppSubURL+"/user/settings/security", http.StatusMovedPermanently)
  264. })
  265. m.Get("/account_link", func(ctx *context.Context) {
  266. ctx.Redirect(setting.AppSubURL+"/user/settings/security", http.StatusMovedPermanently)
  267. })
  268. }, reqSignIn, func(ctx *context.Context) {
  269. ctx.Data["PageIsUserSettings"] = true
  270. })
  271. m.Group("/user", func() {
  272. // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
  273. m.Any("/activate", user.Activate)
  274. m.Any("/activate_email", user.ActivateEmail)
  275. m.Get("/email2user", user.Email2User)
  276. m.Get("/forgot_password", user.ForgotPasswd)
  277. m.Post("/forgot_password", user.ForgotPasswdPost)
  278. m.Get("/logout", user.SignOut)
  279. })
  280. // ***** END: User *****
  281. adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})
  282. // ***** START: Admin *****
  283. m.Group("/admin", func() {
  284. m.Get("", adminReq, admin.Dashboard)
  285. m.Get("/config", admin.Config)
  286. m.Post("/config/test_mail", admin.SendTestMail)
  287. m.Get("/monitor", admin.Monitor)
  288. m.Group("/users", func() {
  289. m.Get("", admin.Users)
  290. m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(auth.AdminCreateUserForm{}), admin.NewUserPost)
  291. m.Combo("/:userid").Get(admin.EditUser).Post(bindIgnErr(auth.AdminEditUserForm{}), admin.EditUserPost)
  292. m.Post("/:userid/delete", admin.DeleteUser)
  293. })
  294. m.Group("/orgs", func() {
  295. m.Get("", admin.Organizations)
  296. })
  297. m.Group("/repos", func() {
  298. m.Get("", admin.Repos)
  299. m.Post("/delete", admin.DeleteRepo)
  300. })
  301. m.Group("/auths", func() {
  302. m.Get("", admin.Authentications)
  303. m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost)
  304. m.Combo("/:authid").Get(admin.EditAuthSource).
  305. Post(bindIgnErr(auth.AuthenticationForm{}), admin.EditAuthSourcePost)
  306. m.Post("/:authid/delete", admin.DeleteAuthSource)
  307. })
  308. m.Group("/notices", func() {
  309. m.Get("", admin.Notices)
  310. m.Post("/delete", admin.DeleteNotices)
  311. m.Get("/empty", admin.EmptyNotices)
  312. })
  313. }, adminReq)
  314. // ***** END: Admin *****
  315. m.Group("", func() {
  316. m.Group("/:username", func() {
  317. m.Get("", user.Profile)
  318. m.Get("/followers", user.Followers)
  319. m.Get("/following", user.Following)
  320. })
  321. m.Get("/attachments/:uuid", func(ctx *context.Context) {
  322. attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
  323. if err != nil {
  324. if models.IsErrAttachmentNotExist(err) {
  325. ctx.Error(404)
  326. } else {
  327. ctx.ServerError("GetAttachmentByUUID", err)
  328. }
  329. return
  330. }
  331. fr, err := os.Open(attach.LocalPath())
  332. if err != nil {
  333. ctx.ServerError("Open", err)
  334. return
  335. }
  336. defer fr.Close()
  337. if err := attach.IncreaseDownloadCount(); err != nil {
  338. ctx.ServerError("Update", err)
  339. return
  340. }
  341. if err = repo.ServeData(ctx, attach.Name, fr); err != nil {
  342. ctx.ServerError("ServeData", err)
  343. return
  344. }
  345. })
  346. m.Post("/attachments", repo.UploadAttachment)
  347. }, ignSignIn)
  348. m.Group("/:username", func() {
  349. m.Get("/action/:action", user.Action)
  350. }, reqSignIn)
  351. if macaron.Env == macaron.DEV {
  352. m.Get("/template/*", dev.TemplatePreview)
  353. }
  354. reqRepoAdmin := context.RequireRepoAdmin()
  355. reqRepoWriter := context.RequireRepoWriter()
  356. // ***** START: Organization *****
  357. m.Group("/org", func() {
  358. m.Group("", func() {
  359. m.Get("/create", org.Create)
  360. m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost)
  361. })
  362. m.Group("/:org", func() {
  363. m.Get("/dashboard", user.Dashboard)
  364. m.Get("/^:type(issues|pulls)$", user.Issues)
  365. m.Get("/members", org.Members)
  366. m.Get("/members/action/:action", org.MembersAction)
  367. m.Get("/teams", org.Teams)
  368. }, context.OrgAssignment(true))
  369. m.Group("/:org", func() {
  370. m.Get("/teams/:team", org.TeamMembers)
  371. m.Get("/teams/:team/repositories", org.TeamRepositories)
  372. m.Route("/teams/:team/action/:action", "GET,POST", org.TeamsAction)
  373. m.Route("/teams/:team/action/repo/:action", "GET,POST", org.TeamsRepoAction)
  374. }, context.OrgAssignment(true, false, true))
  375. m.Group("/:org", func() {
  376. m.Get("/teams/new", org.NewTeam)
  377. m.Post("/teams/new", bindIgnErr(auth.CreateTeamForm{}), org.NewTeamPost)
  378. m.Get("/teams/:team/edit", org.EditTeam)
  379. m.Post("/teams/:team/edit", bindIgnErr(auth.CreateTeamForm{}), org.EditTeamPost)
  380. m.Post("/teams/:team/delete", org.DeleteTeam)
  381. m.Group("/settings", func() {
  382. m.Combo("").Get(org.Settings).
  383. Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
  384. m.Post("/avatar", binding.MultipartForm(auth.AvatarForm{}), org.SettingsAvatar)
  385. m.Post("/avatar/delete", org.SettingsDeleteAvatar)
  386. m.Group("/hooks", func() {
  387. m.Get("", org.Webhooks)
  388. m.Post("/delete", org.DeleteWebhook)
  389. m.Get("/:type/new", repo.WebhooksNew)
  390. m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
  391. m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
  392. m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
  393. m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
  394. m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
  395. m.Get("/:id", repo.WebHooksEdit)
  396. m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
  397. m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
  398. m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
  399. m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
  400. m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
  401. })
  402. m.Route("/delete", "GET,POST", org.SettingsDelete)
  403. })
  404. }, context.OrgAssignment(true, true))
  405. }, reqSignIn)
  406. // ***** END: Organization *****
  407. // ***** START: Repository *****
  408. m.Group("/repo", func() {
  409. m.Get("/create", repo.Create)
  410. m.Post("/create", bindIgnErr(auth.CreateRepoForm{}), repo.CreatePost)
  411. m.Get("/migrate", repo.Migrate)
  412. m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), repo.MigratePost)
  413. m.Group("/fork", func() {
  414. m.Combo("/:repoid").Get(repo.Fork).
  415. Post(bindIgnErr(auth.CreateRepoForm{}), repo.ForkPost)
  416. }, context.RepoIDAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeCode))
  417. }, reqSignIn)
  418. m.Group("/:username/:reponame", func() {
  419. m.Group("/settings", func() {
  420. m.Combo("").Get(repo.Settings).
  421. Post(bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost)
  422. m.Group("/collaboration", func() {
  423. m.Combo("").Get(repo.Collaboration).Post(repo.CollaborationPost)
  424. m.Post("/access_mode", repo.ChangeCollaborationAccessMode)
  425. m.Post("/delete", repo.DeleteCollaboration)
  426. })
  427. m.Group("/branches", func() {
  428. m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
  429. m.Combo("/*").Get(repo.SettingsProtectedBranch).
  430. Post(bindIgnErr(auth.ProtectBranchForm{}), repo.SettingsProtectedBranchPost)
  431. }, repo.MustBeNotBare)
  432. m.Group("/hooks", func() {
  433. m.Get("", repo.Webhooks)
  434. m.Post("/delete", repo.DeleteWebhook)
  435. m.Get("/:type/new", repo.WebhooksNew)
  436. m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
  437. m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
  438. m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
  439. m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
  440. m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
  441. m.Get("/:id", repo.WebHooksEdit)
  442. m.Post("/:id/test", repo.TestWebhook)
  443. m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
  444. m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
  445. m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
  446. m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
  447. m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
  448. m.Group("/git", func() {
  449. m.Get("", repo.GitHooks)
  450. m.Combo("/:name").Get(repo.GitHooksEdit).
  451. Post(repo.GitHooksEditPost)
  452. }, context.GitHookService())
  453. })
  454. m.Group("/keys", func() {
  455. m.Combo("").Get(repo.DeployKeys).
  456. Post(bindIgnErr(auth.AddKeyForm{}), repo.DeployKeysPost)
  457. m.Post("/delete", repo.DeleteDeployKey)
  458. })
  459. }, func(ctx *context.Context) {
  460. ctx.Data["PageIsSettings"] = true
  461. })
  462. }, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.UnitTypes(), context.LoadRepoUnits(), context.RepoRef())
  463. m.Get("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), repo.Action)
  464. m.Group("/:username/:reponame", func() {
  465. m.Group("/issues", func() {
  466. m.Combo("/new").Get(context.RepoRef(), repo.NewIssue).
  467. Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
  468. }, context.CheckUnit(models.UnitTypeIssues))
  469. // FIXME: should use different URLs but mostly same logic for comments of issue and pull reuqest.
  470. // So they can apply their own enable/disable logic on routers.
  471. m.Group("/issues", func() {
  472. m.Group("/:index", func() {
  473. m.Post("/title", repo.UpdateIssueTitle)
  474. m.Post("/content", repo.UpdateIssueContent)
  475. m.Post("/watch", repo.IssueWatch)
  476. m.Group("/dependency", func() {
  477. m.Post("/add", repo.AddDependency)
  478. m.Post("/delete", repo.RemoveDependency)
  479. })
  480. m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
  481. m.Group("/times", func() {
  482. m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually)
  483. m.Group("/stopwatch", func() {
  484. m.Post("/toggle", repo.IssueStopwatch)
  485. m.Post("/cancel", repo.CancelStopwatch)
  486. })
  487. })
  488. m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction)
  489. })
  490. m.Post("/labels", reqRepoWriter, repo.UpdateIssueLabel)
  491. m.Post("/milestone", reqRepoWriter, repo.UpdateIssueMilestone)
  492. m.Post("/assignee", reqRepoWriter, repo.UpdateIssueAssignee)
  493. m.Post("/status", reqRepoWriter, repo.UpdateIssueStatus)
  494. })
  495. m.Group("/comments/:id", func() {
  496. m.Post("", repo.UpdateCommentContent)
  497. m.Post("/delete", repo.DeleteComment)
  498. m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeCommentReaction)
  499. }, context.CheckAnyUnit(models.UnitTypeIssues, models.UnitTypePullRequests))
  500. m.Group("/labels", func() {
  501. m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
  502. m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
  503. m.Post("/delete", repo.DeleteLabel)
  504. m.Post("/initialize", bindIgnErr(auth.InitializeLabelsForm{}), repo.InitializeLabels)
  505. }, reqRepoWriter, context.RepoRef(), context.CheckAnyUnit(models.UnitTypeIssues, models.UnitTypePullRequests))
  506. m.Group("/milestones", func() {
  507. m.Combo("/new").Get(repo.NewMilestone).
  508. Post(bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
  509. m.Get("/:id/edit", repo.EditMilestone)
  510. m.Post("/:id/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost)
  511. m.Get("/:id/:action", repo.ChangeMilestonStatus)
  512. m.Post("/delete", repo.DeleteMilestone)
  513. }, reqRepoWriter, context.RepoRef(), context.CheckAnyUnit(models.UnitTypeIssues, models.UnitTypePullRequests))
  514. m.Combo("/compare/*", repo.MustAllowPulls, repo.SetEditorconfigIfExists).
  515. Get(repo.SetDiffViewStyle, repo.CompareAndPullRequest).
  516. Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
  517. m.Group("", func() {
  518. m.Group("", func() {
  519. m.Combo("/_edit/*").Get(repo.EditFile).
  520. Post(bindIgnErr(auth.EditRepoFileForm{}), repo.EditFilePost)
  521. m.Combo("/_new/*").Get(repo.NewFile).
  522. Post(bindIgnErr(auth.EditRepoFileForm{}), repo.NewFilePost)
  523. m.Post("/_preview/*", bindIgnErr(auth.EditPreviewDiffForm{}), repo.DiffPreviewPost)
  524. m.Combo("/_delete/*").Get(repo.DeleteFile).
  525. Post(bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
  526. m.Combo("/_upload/*", repo.MustBeAbleToUpload).
  527. Get(repo.UploadFile).
  528. Post(bindIgnErr(auth.UploadRepoFileForm{}), repo.UploadFilePost)
  529. }, context.RepoRefByType(context.RepoRefBranch), repo.MustBeEditable)
  530. m.Group("", func() {
  531. m.Post("/upload-file", repo.UploadFileToServer)
  532. m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
  533. }, context.RepoRef(), repo.MustBeEditable, repo.MustBeAbleToUpload)
  534. }, repo.MustBeNotBare, reqRepoWriter)
  535. m.Group("/branches", func() {
  536. m.Group("/_new/", func() {
  537. m.Post("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.CreateBranch)
  538. m.Post("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.CreateBranch)
  539. m.Post("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.CreateBranch)
  540. }, bindIgnErr(auth.NewBranchForm{}))
  541. m.Post("/delete", repo.DeleteBranchPost)
  542. m.Post("/restore", repo.RestoreBranchPost)
  543. }, reqRepoWriter, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode))
  544. }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits())
  545. // Releases
  546. m.Group("/:username/:reponame", func() {
  547. m.Group("/releases", func() {
  548. m.Get("/", repo.MustBeNotBare, repo.Releases)
  549. }, repo.MustBeNotBare, context.RepoRef())
  550. m.Group("/releases", func() {
  551. m.Get("/new", repo.NewRelease)
  552. m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
  553. m.Post("/delete", repo.DeleteRelease)
  554. }, reqSignIn, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
  555. m.Group("/releases", func() {
  556. m.Get("/edit/*", repo.EditRelease)
  557. m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
  558. }, reqSignIn, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
  559. var err error
  560. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
  561. if err != nil {
  562. ctx.ServerError("GetBranchCommit", err)
  563. return
  564. }
  565. ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
  566. if err != nil {
  567. ctx.ServerError("GetCommitsCount", err)
  568. return
  569. }
  570. ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
  571. })
  572. }, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeReleases))
  573. m.Group("/:username/:reponame", func() {
  574. m.Post("/topics", repo.TopicsPost)
  575. }, context.RepoAssignment(), reqRepoAdmin)
  576. m.Group("/:username/:reponame", func() {
  577. m.Group("", func() {
  578. m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
  579. m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
  580. m.Get("/labels/", context.CheckAnyUnit(models.UnitTypeIssues, models.UnitTypePullRequests), repo.RetrieveLabels, repo.Labels)
  581. m.Get("/milestones", context.CheckAnyUnit(models.UnitTypeIssues, models.UnitTypePullRequests), repo.Milestones)
  582. }, context.RepoRef())
  583. m.Group("/wiki", func() {
  584. m.Get("/?:page", repo.Wiki)
  585. m.Get("/_pages", repo.WikiPages)
  586. m.Group("", func() {
  587. m.Combo("/_new").Get(repo.NewWiki).
  588. Post(bindIgnErr(auth.NewWikiForm{}), repo.NewWikiPost)
  589. m.Combo("/:page/_edit").Get(repo.EditWiki).
  590. Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost)
  591. m.Post("/:page/delete", repo.DeleteWikiPagePost)
  592. }, reqSignIn, reqRepoWriter)
  593. }, repo.MustEnableWiki, context.RepoRef())
  594. m.Group("/wiki", func() {
  595. m.Get("/raw/*", repo.WikiRaw)
  596. }, repo.MustEnableWiki)
  597. m.Group("/activity", func() {
  598. m.Get("", repo.Activity)
  599. m.Get("/:period", repo.Activity)
  600. }, context.RepoRef(), repo.MustBeNotBare, context.CheckAnyUnit(models.UnitTypePullRequests, models.UnitTypeIssues, models.UnitTypeReleases))
  601. m.Get("/archive/*", repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.Download)
  602. m.Group("/branches", func() {
  603. m.Get("", repo.Branches)
  604. }, repo.MustBeNotBare, context.RepoRef(), context.CheckUnit(models.UnitTypeCode))
  605. m.Group("/pulls/:index", func() {
  606. m.Get(".diff", repo.DownloadPullDiff)
  607. m.Get(".patch", repo.DownloadPullPatch)
  608. m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
  609. m.Post("/merge", reqRepoWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
  610. m.Post("/cleanup", context.RepoRef(), repo.CleanUpPullRequest)
  611. m.Group("/files", func() {
  612. m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.ViewPullFiles)
  613. m.Group("/reviews", func() {
  614. m.Post("/comments", bindIgnErr(auth.CodeCommentForm{}), repo.CreateCodeComment)
  615. m.Post("/submit", bindIgnErr(auth.SubmitReviewForm{}), repo.SubmitReview)
  616. })
  617. })
  618. }, repo.MustAllowPulls)
  619. m.Group("/raw", func() {
  620. m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownload)
  621. m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownload)
  622. m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownload)
  623. // "/*" route is deprecated, and kept for backward compatibility
  624. m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.SingleDownload)
  625. }, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode))
  626. m.Group("/commits", func() {
  627. m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RefCommits)
  628. m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RefCommits)
  629. m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RefCommits)
  630. // "/*" route is deprecated, and kept for backward compatibility
  631. m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.RefCommits)
  632. }, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode))
  633. m.Group("", func() {
  634. m.Get("/graph", repo.Graph)
  635. m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
  636. }, repo.MustBeNotBare, context.RepoRef(), context.CheckUnit(models.UnitTypeCode))
  637. m.Group("/src", func() {
  638. m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home)
  639. m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.Home)
  640. m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.Home)
  641. // "/*" route is deprecated, and kept for backward compatibility
  642. m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.Home)
  643. }, repo.SetEditorconfigIfExists)
  644. m.Group("", func() {
  645. m.Get("/forks", repo.Forks)
  646. }, context.RepoRef(), context.CheckUnit(models.UnitTypeCode))
  647. m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)",
  648. repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.RawDiff)
  649. m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists,
  650. repo.SetDiffViewStyle, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.CompareDiff)
  651. }, ignSignIn, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits())
  652. m.Group("/:username/:reponame", func() {
  653. m.Get("/stars", repo.Stars)
  654. m.Get("/watchers", repo.Watchers)
  655. m.Get("/search", context.CheckUnit(models.UnitTypeCode), repo.Search)
  656. }, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes(), context.LoadRepoUnits())
  657. m.Group("/:username", func() {
  658. m.Group("/:reponame", func() {
  659. m.Get("", repo.SetEditorconfigIfExists, repo.Home)
  660. m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
  661. }, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes(), context.LoadRepoUnits())
  662. m.Group("/:reponame", func() {
  663. m.Group("\\.git/info/lfs", func() {
  664. m.Post("/objects/batch", lfs.BatchHandler)
  665. m.Get("/objects/:oid/:filename", lfs.ObjectOidHandler)
  666. m.Any("/objects/:oid", lfs.ObjectOidHandler)
  667. m.Post("/objects", lfs.PostHandler)
  668. m.Post("/verify", lfs.VerifyHandler)
  669. m.Group("/locks", func() {
  670. m.Get("/", lfs.GetListLockHandler)
  671. m.Post("/", lfs.PostLockHandler)
  672. m.Post("/verify", lfs.VerifyLockHandler)
  673. m.Post("/:lid/unlock", lfs.UnLockHandler)
  674. }, context.RepoAssignment())
  675. m.Any("/*", func(ctx *context.Context) {
  676. ctx.NotFound("", nil)
  677. })
  678. }, ignSignInAndCsrf)
  679. m.Any("/*", ignSignInAndCsrf, repo.HTTP)
  680. m.Head("/tasks/trigger", repo.TriggerTask)
  681. })
  682. })
  683. // ***** END: Repository *****
  684. m.Group("/notifications", func() {
  685. m.Get("", user.Notifications)
  686. m.Post("/status", user.NotificationStatusPost)
  687. m.Post("/purge", user.NotificationPurgePost)
  688. }, reqSignIn)
  689. if setting.API.EnableSwagger {
  690. m.Get("/swagger.v1.json", templates.JSONRenderer(), routers.SwaggerV1Json)
  691. }
  692. m.Group("/api", func() {
  693. apiv1.RegisterRoutes(m)
  694. }, ignSignIn)
  695. m.Group("/api/internal", func() {
  696. // package name internal is ideal but Golang is not allowed, so we use private as package name.
  697. private.RegisterRoutes(m)
  698. })
  699. // robots.txt
  700. m.Get("/robots.txt", func(ctx *context.Context) {
  701. if setting.HasRobotsTxt {
  702. ctx.ServeFileContent(path.Join(setting.CustomPath, "robots.txt"))
  703. } else {
  704. ctx.NotFound("", nil)
  705. }
  706. })
  707. // Not found handler.
  708. m.NotFound(routers.NotFound)
  709. }