gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package forms
  4. import (
  5. "math/big"
  6. issues_model "code.gitea.io/gitea/models/issues"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/services/context"
  9. )
  10. type hiddenCommentTypeGroupsType map[string][]issues_model.CommentType
  11. // hiddenCommentTypeGroups maps the group names to comment types, these group names comes from the Web UI (appearance.tmpl)
  12. var hiddenCommentTypeGroups = hiddenCommentTypeGroupsType{
  13. "reference": {
  14. /*3*/ issues_model.CommentTypeIssueRef,
  15. /*4*/ issues_model.CommentTypeCommitRef,
  16. /*5*/ issues_model.CommentTypeCommentRef,
  17. /*6*/ issues_model.CommentTypePullRef,
  18. },
  19. "label": {
  20. /*7*/ issues_model.CommentTypeLabel,
  21. },
  22. "milestone": {
  23. /*8*/ issues_model.CommentTypeMilestone,
  24. },
  25. "assignee": {
  26. /*9*/ issues_model.CommentTypeAssignees,
  27. },
  28. "title": {
  29. /*10*/ issues_model.CommentTypeChangeTitle,
  30. },
  31. "branch": {
  32. /*11*/ issues_model.CommentTypeDeleteBranch,
  33. /*25*/ issues_model.CommentTypeChangeTargetBranch,
  34. },
  35. "time_tracking": {
  36. /*12*/ issues_model.CommentTypeStartTracking,
  37. /*13*/ issues_model.CommentTypeStopTracking,
  38. /*14*/ issues_model.CommentTypeAddTimeManual,
  39. /*15*/ issues_model.CommentTypeCancelTracking,
  40. /*26*/ issues_model.CommentTypeDeleteTimeManual,
  41. /*38*/ issues_model.CommentTypeChangeTimeEstimate,
  42. },
  43. "deadline": {
  44. /*16*/ issues_model.CommentTypeAddedDeadline,
  45. /*17*/ issues_model.CommentTypeModifiedDeadline,
  46. /*18*/ issues_model.CommentTypeRemovedDeadline,
  47. },
  48. "dependency": {
  49. /*19*/ issues_model.CommentTypeAddDependency,
  50. /*20*/ issues_model.CommentTypeRemoveDependency,
  51. },
  52. "lock": {
  53. /*23*/ issues_model.CommentTypeLock,
  54. /*24*/ issues_model.CommentTypeUnlock,
  55. },
  56. "review_request": {
  57. /*27*/ issues_model.CommentTypeReviewRequest,
  58. },
  59. "pull_request_push": {
  60. /*29*/ issues_model.CommentTypePullRequestPush,
  61. },
  62. "project": {
  63. /*30*/ issues_model.CommentTypeProject,
  64. /*31*/ issues_model.CommentTypeProjectColumn,
  65. },
  66. "issue_ref": {
  67. /*33*/ issues_model.CommentTypeChangeIssueRef,
  68. },
  69. }
  70. // UserHiddenCommentTypesFromRequest parse the form to hidden comment types bitset
  71. func UserHiddenCommentTypesFromRequest(ctx *context.Context) *big.Int {
  72. bitset := new(big.Int)
  73. for group, commentTypes := range hiddenCommentTypeGroups {
  74. if ctx.FormBool(group) {
  75. for _, commentType := range commentTypes {
  76. bitset = bitset.SetBit(bitset, int(commentType), 1)
  77. }
  78. }
  79. }
  80. return bitset
  81. }
  82. // IsUserHiddenCommentTypeGroupChecked check whether a hidden comment type group is "enabled" (checked on UI)
  83. func IsUserHiddenCommentTypeGroupChecked(group string, hiddenCommentTypes *big.Int) (ret bool) {
  84. commentTypes, ok := hiddenCommentTypeGroups[group]
  85. if !ok {
  86. log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group)
  87. return false
  88. }
  89. if hiddenCommentTypes == nil {
  90. return false
  91. }
  92. for _, commentType := range commentTypes {
  93. if hiddenCommentTypes.Bit(int(commentType)) == 1 {
  94. return true
  95. }
  96. }
  97. return false
  98. }