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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/context"
  7. "code.gitea.io/gitea/modules/web"
  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 !form.HasValidReason() {
  23. ctx.JSONError(ctx.Tr("repo.issues.lock.unknown_reason"))
  24. return
  25. }
  26. if err := issues_model.LockIssue(&issues_model.IssueLockOptions{
  27. Doer: ctx.Doer,
  28. Issue: issue,
  29. Reason: form.Reason,
  30. }); err != nil {
  31. ctx.ServerError("LockIssue", err)
  32. return
  33. }
  34. ctx.JSONRedirect(issue.Link())
  35. }
  36. // UnlockIssue unlocks a previously locked issue.
  37. func UnlockIssue(ctx *context.Context) {
  38. issue := GetActionIssue(ctx)
  39. if ctx.Written() {
  40. return
  41. }
  42. if !issue.IsLocked {
  43. ctx.JSONError(ctx.Tr("repo.issues.unlock_error"))
  44. return
  45. }
  46. if err := issues_model.UnlockIssue(&issues_model.IssueLockOptions{
  47. Doer: ctx.Doer,
  48. Issue: issue,
  49. }); err != nil {
  50. ctx.ServerError("UnlockIssue", err)
  51. return
  52. }
  53. ctx.JSONRedirect(issue.Link())
  54. }