Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

issue_lock.go 1.6KB

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