gitea源码

issue_lock.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. issues_model "code.gitea.io/gitea/models/issues"
  6. "code.gitea.io/gitea/modules/web"
  7. "code.gitea.io/gitea/services/context"
  8. "code.gitea.io/gitea/services/forms"
  9. )
  10. // LockIssue locks an issue. This would limit commenting abilities to
  11. // users with write access to the repo.
  12. func LockIssue(ctx *context.Context) {
  13. form := web.GetForm(ctx).(*forms.IssueLockForm)
  14. issue := GetActionIssue(ctx)
  15. if ctx.Written() {
  16. return
  17. }
  18. if issue.IsLocked {
  19. ctx.JSONError(ctx.Tr("repo.issues.lock_duplicate"))
  20. return
  21. }
  22. if err := issues_model.LockIssue(ctx, &issues_model.IssueLockOptions{
  23. Doer: ctx.Doer,
  24. Issue: issue,
  25. Reason: form.Reason,
  26. }); err != nil {
  27. ctx.ServerError("LockIssue", err)
  28. return
  29. }
  30. ctx.JSONRedirect(issue.Link())
  31. }
  32. // UnlockIssue unlocks a previously locked issue.
  33. func UnlockIssue(ctx *context.Context) {
  34. issue := GetActionIssue(ctx)
  35. if ctx.Written() {
  36. return
  37. }
  38. if !issue.IsLocked {
  39. ctx.JSONError(ctx.Tr("repo.issues.unlock_error"))
  40. return
  41. }
  42. if err := issues_model.UnlockIssue(ctx, &issues_model.IssueLockOptions{
  43. Doer: ctx.Doer,
  44. Issue: issue,
  45. }); err != nil {
  46. ctx.ServerError("UnlockIssue", err)
  47. return
  48. }
  49. ctx.JSONRedirect(issue.Link())
  50. }