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.

issue_lock.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 models
  5. // IssueLockOptions defines options for locking and/or unlocking an issue/PR
  6. type IssueLockOptions struct {
  7. Doer *User
  8. Issue *Issue
  9. Reason string
  10. }
  11. // LockIssue locks an issue. This would limit commenting abilities to
  12. // users with write access to the repo
  13. func LockIssue(opts *IssueLockOptions) error {
  14. return updateIssueLock(opts, true)
  15. }
  16. // UnlockIssue unlocks a previously locked issue.
  17. func UnlockIssue(opts *IssueLockOptions) error {
  18. return updateIssueLock(opts, false)
  19. }
  20. func updateIssueLock(opts *IssueLockOptions, lock bool) error {
  21. if opts.Issue.IsLocked == lock {
  22. return nil
  23. }
  24. opts.Issue.IsLocked = lock
  25. var commentType CommentType
  26. if opts.Issue.IsLocked {
  27. commentType = CommentTypeLock
  28. } else {
  29. commentType = CommentTypeUnlock
  30. }
  31. if err := UpdateIssueCols(opts.Issue, "is_locked"); err != nil {
  32. return err
  33. }
  34. _, err := CreateComment(&CreateCommentOptions{
  35. Doer: opts.Doer,
  36. Issue: opts.Issue,
  37. Repo: opts.Issue.Repo,
  38. Type: commentType,
  39. Content: opts.Reason,
  40. })
  41. return err
  42. }