2022-01-21 12:59:26 -05:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-01-21 12:59:26 -05:00
|
|
|
|
|
|
|
package forms
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
2022-06-13 04:37:59 -05:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2022-01-21 12:59:26 -05:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2024-02-27 02:12:22 -05:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-01-21 12:59:26 -05:00
|
|
|
)
|
|
|
|
|
2022-06-13 04:37:59 -05:00
|
|
|
type hiddenCommentTypeGroupsType map[string][]issues_model.CommentType
|
2022-01-21 12:59:26 -05:00
|
|
|
|
|
|
|
// hiddenCommentTypeGroups maps the group names to comment types, these group names comes from the Web UI (appearance.tmpl)
|
|
|
|
var hiddenCommentTypeGroups = hiddenCommentTypeGroupsType{
|
|
|
|
"reference": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*3*/ issues_model.CommentTypeIssueRef,
|
|
|
|
/*4*/ issues_model.CommentTypeCommitRef,
|
|
|
|
/*5*/ issues_model.CommentTypeCommentRef,
|
|
|
|
/*6*/ issues_model.CommentTypePullRef,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"label": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*7*/ issues_model.CommentTypeLabel,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"milestone": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*8*/ issues_model.CommentTypeMilestone,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"assignee": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*9*/ issues_model.CommentTypeAssignees,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"title": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*10*/ issues_model.CommentTypeChangeTitle,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"branch": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*11*/ issues_model.CommentTypeDeleteBranch,
|
|
|
|
/*25*/ issues_model.CommentTypeChangeTargetBranch,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"time_tracking": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*12*/ issues_model.CommentTypeStartTracking,
|
|
|
|
/*13*/ issues_model.CommentTypeStopTracking,
|
|
|
|
/*14*/ issues_model.CommentTypeAddTimeManual,
|
|
|
|
/*15*/ issues_model.CommentTypeCancelTracking,
|
|
|
|
/*26*/ issues_model.CommentTypeDeleteTimeManual,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"deadline": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*16*/ issues_model.CommentTypeAddedDeadline,
|
|
|
|
/*17*/ issues_model.CommentTypeModifiedDeadline,
|
|
|
|
/*18*/ issues_model.CommentTypeRemovedDeadline,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"dependency": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*19*/ issues_model.CommentTypeAddDependency,
|
|
|
|
/*20*/ issues_model.CommentTypeRemoveDependency,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"lock": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*23*/ issues_model.CommentTypeLock,
|
|
|
|
/*24*/ issues_model.CommentTypeUnlock,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"review_request": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*27*/ issues_model.CommentTypeReviewRequest,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"pull_request_push": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*29*/ issues_model.CommentTypePullRequestPush,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"project": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*30*/ issues_model.CommentTypeProject,
|
2024-05-27 03:59:54 -05:00
|
|
|
/*31*/ issues_model.CommentTypeProjectColumn,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
"issue_ref": {
|
2022-06-13 04:37:59 -05:00
|
|
|
/*33*/ issues_model.CommentTypeChangeIssueRef,
|
2022-01-21 12:59:26 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserHiddenCommentTypesFromRequest parse the form to hidden comment types bitset
|
|
|
|
func UserHiddenCommentTypesFromRequest(ctx *context.Context) *big.Int {
|
|
|
|
bitset := new(big.Int)
|
|
|
|
for group, commentTypes := range hiddenCommentTypeGroups {
|
|
|
|
if ctx.FormBool(group) {
|
|
|
|
for _, commentType := range commentTypes {
|
|
|
|
bitset = bitset.SetBit(bitset, int(commentType), 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bitset
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsUserHiddenCommentTypeGroupChecked check whether a hidden comment type group is "enabled" (checked on UI)
|
|
|
|
func IsUserHiddenCommentTypeGroupChecked(group string, hiddenCommentTypes *big.Int) (ret bool) {
|
|
|
|
commentTypes, ok := hiddenCommentTypeGroups[group]
|
|
|
|
if !ok {
|
|
|
|
log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group)
|
2023-07-07 00:31:56 -05:00
|
|
|
return false
|
2022-01-21 12:59:26 -05:00
|
|
|
}
|
|
|
|
if hiddenCommentTypes == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, commentType := range commentTypes {
|
|
|
|
if hiddenCommentTypes.Bit(int(commentType)) == 1 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|