linstrom/storage/rolesUtil_generated.go

336 lines
17 KiB
Go
Raw Normal View History

2024-09-18 11:49:10 +00:00
// Code generated by cmd/RolesGenerator DO NOT EDIT.
2024-09-18 08:52:51 +00:00
// If you need to refresh the content, run go generate again
package storage
import (
"slices"
2024-12-18 14:24:56 +00:00
"git.mstar.dev/mstar/goutils/sliceutils"
)
2024-09-18 08:52:51 +00:00
func CollapseRolesIntoOne(roles ...Role) Role {
startingRole := RoleDeepCopy(DefaultUserRole)
slices.SortFunc(roles, func(a, b Role) int { return int(int64(a.Priority)-int64(b.Priority)) })
2024-09-18 08:52:51 +00:00
for _, role := range roles {
if role.CanSendReplies != nil {
*startingRole.CanSendReplies = *role.CanSendReplies
2024-09-18 08:52:51 +00:00
}
if role.CanBoost != nil {
*startingRole.CanBoost = *role.CanBoost
2024-09-18 08:52:51 +00:00
}
2024-11-20 12:39:17 +00:00
if role.AutoNsfwMedia != nil {
*startingRole.AutoNsfwMedia = *role.AutoNsfwMedia
2024-09-18 08:52:51 +00:00
}
if role.WithholdNotesForManualApproval != nil {
*startingRole.WithholdNotesForManualApproval = *role.WithholdNotesForManualApproval
}
if role.WithholdNotesBasedOnRegex != nil {
*startingRole.WithholdNotesBasedOnRegex = *role.WithholdNotesBasedOnRegex
2024-11-20 12:39:17 +00:00
}
if role.CanSendCustomReactions != nil {
*startingRole.CanSendCustomReactions = *role.CanSendCustomReactions
}
if role.CanSendLocalNotes != nil {
*startingRole.CanSendLocalNotes = *role.CanSendLocalNotes
}
if role.DisallowInteractionsWith != nil {
startingRole.DisallowInteractionsWith = append(startingRole.DisallowInteractionsWith, role.DisallowInteractionsWith...)
2024-11-20 12:39:17 +00:00
}
if role.CanDeleteNotes != nil {
*startingRole.CanDeleteNotes = *role.CanDeleteNotes
}
if role.CanSupressInteractionsBetweenUsers != nil {
*startingRole.CanSupressInteractionsBetweenUsers = *role.CanSupressInteractionsBetweenUsers
}
if role.CanSendPublicNotes != nil {
*startingRole.CanSendPublicNotes = *role.CanSendPublicNotes
}
2024-11-20 12:39:17 +00:00
if role.ScanCreatedPrivateNotes != nil {
*startingRole.ScanCreatedPrivateNotes = *role.ScanCreatedPrivateNotes
}
if role.ScanCreatedPublicNotes != nil {
*startingRole.ScanCreatedPublicNotes = *role.ScanCreatedPublicNotes
}
if role.CanConfirmWithheldNotes != nil {
*startingRole.CanConfirmWithheldNotes = *role.CanConfirmWithheldNotes
}
if role.CanManageAds != nil {
*startingRole.CanManageAds = *role.CanManageAds
2024-09-18 08:52:51 +00:00
}
2024-11-20 12:39:17 +00:00
if role.CanIncludeSurvey != nil {
*startingRole.CanIncludeSurvey = *role.CanIncludeSurvey
2024-09-18 08:52:51 +00:00
}
if role.CanLogin != nil {
*startingRole.CanLogin = *role.CanLogin
2024-09-18 11:49:10 +00:00
}
if role.CanChangeDisplayName != nil {
*startingRole.CanChangeDisplayName = *role.CanChangeDisplayName
}
if role.FullAdmin != nil {
*startingRole.FullAdmin = *role.FullAdmin
2024-09-18 11:49:10 +00:00
}
2024-11-20 12:39:17 +00:00
if role.CanOverwriteDisplayNames != nil {
*startingRole.CanOverwriteDisplayNames = *role.CanOverwriteDisplayNames
2024-09-18 11:49:10 +00:00
}
if role.CanSendCustomEmotes != nil {
*startingRole.CanSendCustomEmotes = *role.CanSendCustomEmotes
2024-09-18 08:52:51 +00:00
}
if role.CanQuote != nil {
*startingRole.CanQuote = *role.CanQuote
2024-09-18 08:52:51 +00:00
}
if role.CanSubmitReports != nil {
*startingRole.CanSubmitReports = *role.CanSubmitReports
}
if role.WithholdNotesRegexes != nil {
startingRole.WithholdNotesRegexes = append(startingRole.WithholdNotesRegexes, role.WithholdNotesRegexes...)
}
if role.CanAffectOtherAdmins != nil {
*startingRole.CanAffectOtherAdmins = *role.CanAffectOtherAdmins
}
if role.CanViewDeletedNotes != nil {
*startingRole.CanViewDeletedNotes = *role.CanViewDeletedNotes
}
if role.CanManageAvatarDecorations != nil {
*startingRole.CanManageAvatarDecorations = *role.CanManageAvatarDecorations
2024-09-18 11:49:10 +00:00
}
if role.CanSendFollowerOnlyNotes != nil {
*startingRole.CanSendFollowerOnlyNotes = *role.CanSendFollowerOnlyNotes
}
if role.BlockedUsers != nil {
startingRole.BlockedUsers = append(startingRole.BlockedUsers, role.BlockedUsers...)
}
if role.CanAssignRoles != nil {
*startingRole.CanAssignRoles = *role.CanAssignRoles
}
if role.CanManageCustomEmotes != nil {
*startingRole.CanManageCustomEmotes = *role.CanManageCustomEmotes
}
2024-11-20 12:39:17 +00:00
if role.CanSendPrivateNotes != nil {
*startingRole.CanSendPrivateNotes = *role.CanSendPrivateNotes
}
if role.CanFederateBsky != nil {
*startingRole.CanFederateBsky = *role.CanFederateBsky
}
2024-11-20 12:39:17 +00:00
if role.CanMentionOthers != nil {
*startingRole.CanMentionOthers = *role.CanMentionOthers
2024-09-18 11:49:10 +00:00
}
if role.AutoCwPostsText != nil {
*startingRole.AutoCwPostsText = *role.AutoCwPostsText
2024-09-18 11:49:10 +00:00
}
2024-11-20 12:39:17 +00:00
if role.CanSendMedia != nil {
*startingRole.CanSendMedia = *role.CanSendMedia
2024-09-18 08:52:51 +00:00
}
if role.CanIncludeLinks != nil {
*startingRole.CanIncludeLinks = *role.CanIncludeLinks
2024-09-18 08:52:51 +00:00
}
if role.MentionLimit != nil {
*startingRole.MentionLimit = *role.MentionLimit
2024-09-18 11:49:10 +00:00
}
if role.AutoCwPosts != nil {
*startingRole.AutoCwPosts = *role.AutoCwPosts
2024-11-20 12:39:17 +00:00
}
if role.ScanCreatedLocalNotes != nil {
*startingRole.ScanCreatedLocalNotes = *role.ScanCreatedLocalNotes
2024-11-20 12:39:17 +00:00
}
if role.ScanCreatedFollowerOnlyNotes != nil {
*startingRole.ScanCreatedFollowerOnlyNotes = *role.ScanCreatedFollowerOnlyNotes
}
if role.CanRecoverDeletedNotes != nil {
*startingRole.CanRecoverDeletedNotes = *role.CanRecoverDeletedNotes
2024-09-18 08:52:51 +00:00
}
if role.CanSendAnnouncements != nil {
*startingRole.CanSendAnnouncements = *role.CanSendAnnouncements
2024-09-18 11:49:10 +00:00
}
2024-11-20 12:39:17 +00:00
if role.CanFederateFedi != nil {
*startingRole.CanFederateFedi = *role.CanFederateFedi
2024-09-18 11:49:10 +00:00
}
if role.HasMentionCountLimit != nil {
*startingRole.HasMentionCountLimit = *role.HasMentionCountLimit
2024-11-20 12:39:17 +00:00
}
2024-09-18 08:52:51 +00:00
}
return startingRole
}
func RoleDeepCopy(o Role) Role {
2024-09-18 08:52:51 +00:00
n := Role{}
n.Model = o.Model
n.Name = o.Name
n.Priority = o.Priority
n.IsUserRole = o.IsUserRole
n.IsBuiltIn = o.IsBuiltIn
if o.CanSubmitReports == nil { n.CanSubmitReports = nil } else {
t := *o.CanSubmitReports
n.CanSubmitReports = &t
2024-09-18 08:52:51 +00:00
}
n.WithholdNotesRegexes = slices.Clone(o.WithholdNotesRegexes)
if o.CanAffectOtherAdmins == nil { n.CanAffectOtherAdmins = nil } else {
t := *o.CanAffectOtherAdmins
n.CanAffectOtherAdmins = &t
2024-09-18 08:52:51 +00:00
}
if o.CanViewDeletedNotes == nil { n.CanViewDeletedNotes = nil } else {
t := *o.CanViewDeletedNotes
n.CanViewDeletedNotes = &t
2024-09-18 08:52:51 +00:00
}
2024-11-20 12:39:17 +00:00
if o.CanManageAvatarDecorations == nil { n.CanManageAvatarDecorations = nil } else {
t := *o.CanManageAvatarDecorations
n.CanManageAvatarDecorations = &t
2024-09-18 08:52:51 +00:00
}
if o.CanSendFollowerOnlyNotes == nil { n.CanSendFollowerOnlyNotes = nil } else {
t := *o.CanSendFollowerOnlyNotes
n.CanSendFollowerOnlyNotes = &t
2024-09-18 11:49:10 +00:00
}
2024-11-20 12:39:17 +00:00
n.BlockedUsers = slices.Clone(o.BlockedUsers)
if o.CanAssignRoles == nil { n.CanAssignRoles = nil } else {
t := *o.CanAssignRoles
n.CanAssignRoles = &t
}
if o.CanManageCustomEmotes == nil { n.CanManageCustomEmotes = nil } else {
t := *o.CanManageCustomEmotes
n.CanManageCustomEmotes = &t
}
if o.CanSendPrivateNotes == nil { n.CanSendPrivateNotes = nil } else {
t := *o.CanSendPrivateNotes
n.CanSendPrivateNotes = &t
2024-09-18 08:52:51 +00:00
}
if o.CanFederateBsky == nil { n.CanFederateBsky = nil } else {
t := *o.CanFederateBsky
n.CanFederateBsky = &t
2024-09-18 08:52:51 +00:00
}
if o.CanMentionOthers == nil { n.CanMentionOthers = nil } else {
t := *o.CanMentionOthers
n.CanMentionOthers = &t
2024-09-18 08:52:51 +00:00
}
if o.AutoCwPostsText == nil { n.AutoCwPostsText = nil } else {
t := *o.AutoCwPostsText
n.AutoCwPostsText = &t
2024-09-18 08:52:51 +00:00
}
if o.CanSendMedia == nil { n.CanSendMedia = nil } else {
t := *o.CanSendMedia
n.CanSendMedia = &t
2024-09-18 08:52:51 +00:00
}
if o.CanIncludeLinks == nil { n.CanIncludeLinks = nil } else {
t := *o.CanIncludeLinks
n.CanIncludeLinks = &t
2024-11-20 12:39:17 +00:00
}
if o.MentionLimit == nil { n.MentionLimit = nil } else {
t := *o.MentionLimit
n.MentionLimit = &t
2024-11-20 12:39:17 +00:00
}
if o.AutoCwPosts == nil { n.AutoCwPosts = nil } else {
t := *o.AutoCwPosts
n.AutoCwPosts = &t
2024-09-18 08:52:51 +00:00
}
2024-11-20 12:39:17 +00:00
if o.ScanCreatedLocalNotes == nil { n.ScanCreatedLocalNotes = nil } else {
t := *o.ScanCreatedLocalNotes
n.ScanCreatedLocalNotes = &t
}
if o.ScanCreatedFollowerOnlyNotes == nil { n.ScanCreatedFollowerOnlyNotes = nil } else {
t := *o.ScanCreatedFollowerOnlyNotes
n.ScanCreatedFollowerOnlyNotes = &t
}
2024-11-20 12:39:17 +00:00
if o.CanRecoverDeletedNotes == nil { n.CanRecoverDeletedNotes = nil } else {
t := *o.CanRecoverDeletedNotes
n.CanRecoverDeletedNotes = &t
2024-09-18 11:49:10 +00:00
}
if o.CanSendAnnouncements == nil { n.CanSendAnnouncements = nil } else {
t := *o.CanSendAnnouncements
n.CanSendAnnouncements = &t
2024-09-18 11:49:10 +00:00
}
if o.CanFederateFedi == nil { n.CanFederateFedi = nil } else {
t := *o.CanFederateFedi
n.CanFederateFedi = &t
}
if o.HasMentionCountLimit == nil { n.HasMentionCountLimit = nil } else {
t := *o.HasMentionCountLimit
n.HasMentionCountLimit = &t
2024-09-18 08:52:51 +00:00
}
if o.CanSendReplies == nil { n.CanSendReplies = nil } else {
t := *o.CanSendReplies
n.CanSendReplies = &t
2024-09-18 08:52:51 +00:00
}
if o.CanBoost == nil { n.CanBoost = nil } else {
t := *o.CanBoost
n.CanBoost = &t
}
if o.AutoNsfwMedia == nil { n.AutoNsfwMedia = nil } else {
t := *o.AutoNsfwMedia
n.AutoNsfwMedia = &t
}
if o.WithholdNotesForManualApproval == nil { n.WithholdNotesForManualApproval = nil } else {
t := *o.WithholdNotesForManualApproval
n.WithholdNotesForManualApproval = &t
}
2024-11-20 12:39:17 +00:00
if o.WithholdNotesBasedOnRegex == nil { n.WithholdNotesBasedOnRegex = nil } else {
t := *o.WithholdNotesBasedOnRegex
n.WithholdNotesBasedOnRegex = &t
}
2024-11-20 12:39:17 +00:00
if o.CanSendCustomReactions == nil { n.CanSendCustomReactions = nil } else {
t := *o.CanSendCustomReactions
n.CanSendCustomReactions = &t
2024-09-18 11:49:10 +00:00
}
if o.CanSendLocalNotes == nil { n.CanSendLocalNotes = nil } else {
t := *o.CanSendLocalNotes
n.CanSendLocalNotes = &t
2024-09-18 11:49:10 +00:00
}
n.DisallowInteractionsWith = slices.Clone(o.DisallowInteractionsWith)
if o.CanDeleteNotes == nil { n.CanDeleteNotes = nil } else {
t := *o.CanDeleteNotes
n.CanDeleteNotes = &t
}
if o.CanSupressInteractionsBetweenUsers == nil { n.CanSupressInteractionsBetweenUsers = nil } else {
t := *o.CanSupressInteractionsBetweenUsers
n.CanSupressInteractionsBetweenUsers = &t
}
if o.CanSendPublicNotes == nil { n.CanSendPublicNotes = nil } else {
t := *o.CanSendPublicNotes
n.CanSendPublicNotes = &t
}
if o.ScanCreatedPrivateNotes == nil { n.ScanCreatedPrivateNotes = nil } else {
t := *o.ScanCreatedPrivateNotes
n.ScanCreatedPrivateNotes = &t
}
if o.ScanCreatedPublicNotes == nil { n.ScanCreatedPublicNotes = nil } else {
t := *o.ScanCreatedPublicNotes
n.ScanCreatedPublicNotes = &t
}
if o.CanConfirmWithheldNotes == nil { n.CanConfirmWithheldNotes = nil } else {
t := *o.CanConfirmWithheldNotes
n.CanConfirmWithheldNotes = &t
}
if o.CanManageAds == nil { n.CanManageAds = nil } else {
t := *o.CanManageAds
n.CanManageAds = &t
}
if o.CanIncludeSurvey == nil { n.CanIncludeSurvey = nil } else {
t := *o.CanIncludeSurvey
n.CanIncludeSurvey = &t
}
2024-11-20 12:39:17 +00:00
if o.CanLogin == nil { n.CanLogin = nil } else {
t := *o.CanLogin
n.CanLogin = &t
2024-09-18 08:52:51 +00:00
}
if o.CanChangeDisplayName == nil { n.CanChangeDisplayName = nil } else {
t := *o.CanChangeDisplayName
n.CanChangeDisplayName = &t
}
if o.FullAdmin == nil { n.FullAdmin = nil } else {
t := *o.FullAdmin
n.FullAdmin = &t
}
if o.CanOverwriteDisplayNames == nil { n.CanOverwriteDisplayNames = nil } else {
t := *o.CanOverwriteDisplayNames
n.CanOverwriteDisplayNames = &t
}
if o.CanSendCustomEmotes == nil { n.CanSendCustomEmotes = nil } else {
t := *o.CanSendCustomEmotes
n.CanSendCustomEmotes = &t
}
if o.CanQuote == nil { n.CanQuote = nil } else {
t := *o.CanQuote
n.CanQuote = &t
}
2024-09-18 08:52:51 +00:00
return n
}
func CompareRoles(a, b *Role) bool {
return (a.CanSendLocalNotes == nil || b.CanSendLocalNotes == nil || a.CanSendLocalNotes == b.CanSendLocalNotes) && (a.CanSendReplies == nil || b.CanSendReplies == nil || a.CanSendReplies == b.CanSendReplies) && (a.CanBoost == nil || b.CanBoost == nil || a.CanBoost == b.CanBoost) && (a.AutoNsfwMedia == nil || b.AutoNsfwMedia == nil || a.AutoNsfwMedia == b.AutoNsfwMedia) && (a.WithholdNotesForManualApproval == nil || b.WithholdNotesForManualApproval == nil || a.WithholdNotesForManualApproval == b.WithholdNotesForManualApproval) && (a.WithholdNotesBasedOnRegex == nil || b.WithholdNotesBasedOnRegex == nil || a.WithholdNotesBasedOnRegex == b.WithholdNotesBasedOnRegex) && (a.CanSendCustomReactions == nil || b.CanSendCustomReactions == nil || a.CanSendCustomReactions == b.CanSendCustomReactions) && (a.ScanCreatedPrivateNotes == nil || b.ScanCreatedPrivateNotes == nil || a.ScanCreatedPrivateNotes == b.ScanCreatedPrivateNotes) && (a.DisallowInteractionsWith == nil || b.DisallowInteractionsWith == nil || sliceutils.CompareUnordered(a.DisallowInteractionsWith,b.DisallowInteractionsWith)) && (a.CanDeleteNotes == nil || b.CanDeleteNotes == nil || a.CanDeleteNotes == b.CanDeleteNotes) && (a.CanSupressInteractionsBetweenUsers == nil || b.CanSupressInteractionsBetweenUsers == nil || a.CanSupressInteractionsBetweenUsers == b.CanSupressInteractionsBetweenUsers) && (a.CanSendPublicNotes == nil || b.CanSendPublicNotes == nil || a.CanSendPublicNotes == b.CanSendPublicNotes) && (a.CanLogin == nil || b.CanLogin == nil || a.CanLogin == b.CanLogin) && (a.ScanCreatedPublicNotes == nil || b.ScanCreatedPublicNotes == nil || a.ScanCreatedPublicNotes == b.ScanCreatedPublicNotes) && (a.CanConfirmWithheldNotes == nil || b.CanConfirmWithheldNotes == nil || a.CanConfirmWithheldNotes == b.CanConfirmWithheldNotes) && (a.CanManageAds == nil || b.CanManageAds == nil || a.CanManageAds == b.CanManageAds) && (a.CanIncludeSurvey == nil || b.CanIncludeSurvey == nil || a.CanIncludeSurvey == b.CanIncludeSurvey) && (a.CanQuote == nil || b.CanQuote == nil || a.CanQuote == b.CanQuote) && (a.CanChangeDisplayName == nil || b.CanChangeDisplayName == nil || a.CanChangeDisplayName == b.CanChangeDisplayName) && (a.FullAdmin == nil || b.FullAdmin == nil || a.FullAdmin == b.FullAdmin) && (a.CanOverwriteDisplayNames == nil || b.CanOverwriteDisplayNames == nil || a.CanOverwriteDisplayNames == b.CanOverwriteDisplayNames) && (a.CanSendCustomEmotes == nil || b.CanSendCustomEmotes == nil || a.CanSendCustomEmotes == b.CanSendCustomEmotes) && (a.BlockedUsers == nil || b.BlockedUsers == nil || sliceutils.CompareUnordered(a.BlockedUsers,b.BlockedUsers)) && (a.CanSubmitReports == nil || b.CanSubmitReports == nil || a.CanSubmitReports == b.CanSubmitReports) && (a.WithholdNotesRegexes == nil || b.WithholdNotesRegexes == nil || sliceutils.CompareUnordered(a.WithholdNotesRegexes,b.WithholdNotesRegexes)) && (a.CanAffectOtherAdmins == nil || b.CanAffectOtherAdmins == nil || a.CanAffectOtherAdmins == b.CanAffectOtherAdmins) && (a.CanViewDeletedNotes == nil || b.CanViewDeletedNotes == nil || a.CanViewDeletedNotes == b.CanViewDeletedNotes) && (a.CanManageAvatarDecorations == nil || b.CanManageAvatarDecorations == nil || a.CanManageAvatarDecorations == b.CanManageAvatarDecorations) && (a.CanSendFollowerOnlyNotes == nil || b.CanSendFollowerOnlyNotes == nil || a.CanSendFollowerOnlyNotes == b.CanSendFollowerOnlyNotes) && (a.CanFederateBsky == nil || b.CanFederateBsky == nil || a.CanFederateBsky == b.CanFederateBsky) && (a.CanAssignRoles == nil || b.CanAssignRoles == nil || a.CanAssignRoles == b.CanAssignRoles) && (a.CanManageCustomEmotes == nil || b.CanManageCustomEmotes == nil || a.CanManageCustomEmotes == b.CanManageCustomEmotes) && (a.CanSendPrivateNotes == nil || b.CanSendPrivateNotes == nil || a.CanSendPrivateNotes == b.CanSendPrivateNotes) && (a.CanIncludeLinks == nil || b.CanIncludeLinks == nil || a.CanIncludeLinks == b.CanIncludeLinks) && (a.CanMentionOthers == nil || b.CanMentionOthers == nil || a.CanMentionOthers == b.CanMentionOthers) && (a.AutoCwPostsText == nil || b.AutoCwPostsText =
}