本站源代码
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.

72 lines
1.5KB

  1. // Copyright 2019 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 repo
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/auth"
  9. "code.gitea.io/gitea/modules/context"
  10. )
  11. // LockIssue locks an issue. This would limit commenting abilities to
  12. // users with write access to the repo.
  13. func LockIssue(ctx *context.Context, form auth.IssueLockForm) {
  14. issue := GetActionIssue(ctx)
  15. if ctx.Written() {
  16. return
  17. }
  18. if issue.IsLocked {
  19. ctx.Flash.Error(ctx.Tr("repo.issues.lock_duplicate"))
  20. ctx.Redirect(issue.HTMLURL())
  21. return
  22. }
  23. if !form.HasValidReason() {
  24. ctx.Flash.Error(ctx.Tr("repo.issues.lock.unknown_reason"))
  25. ctx.Redirect(issue.HTMLURL())
  26. return
  27. }
  28. if err := models.LockIssue(&models.IssueLockOptions{
  29. Doer: ctx.User,
  30. Issue: issue,
  31. Reason: form.Reason,
  32. }); err != nil {
  33. ctx.ServerError("LockIssue", err)
  34. return
  35. }
  36. ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  37. }
  38. // UnlockIssue unlocks a previously locked issue.
  39. func UnlockIssue(ctx *context.Context) {
  40. issue := GetActionIssue(ctx)
  41. if ctx.Written() {
  42. return
  43. }
  44. if !issue.IsLocked {
  45. ctx.Flash.Error(ctx.Tr("repo.issues.unlock_error"))
  46. ctx.Redirect(issue.HTMLURL())
  47. return
  48. }
  49. if err := models.UnlockIssue(&models.IssueLockOptions{
  50. Doer: ctx.User,
  51. Issue: issue,
  52. }); err != nil {
  53. ctx.ServerError("UnlockIssue", err)
  54. return
  55. }
  56. ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  57. }
上海开阖软件有限公司 沪ICP备12045867号-1