feat: enforce friend add and curfew policies
This commit is contained in:
@@ -64,9 +64,18 @@ var (
|
||||
moderationProviderCache = newConfigCache[*types.ModerationProviderConfig]()
|
||||
moderationPolicyCache = newConfigCache[*types.ModerationPolicy]()
|
||||
moderationWordsCache = newConfigCache[*types.SensitiveWordSet]()
|
||||
securityPolicyCache = newConfigCache[*types.SecurityPolicy]()
|
||||
thirdPartyConfigAllKeys = "*"
|
||||
)
|
||||
|
||||
func InvalidateSecurityPolicyCache(tenantCode string) {
|
||||
if strings.TrimSpace(tenantCode) == "" {
|
||||
securityPolicyCache.clear()
|
||||
return
|
||||
}
|
||||
securityPolicyCache.delete(strings.TrimSpace(tenantCode))
|
||||
}
|
||||
|
||||
func InvalidateModerationConfigCache(tenantCode string, provider, policy, words bool) {
|
||||
if provider {
|
||||
moderationProviderCache.clear()
|
||||
|
||||
@@ -173,6 +173,7 @@ type AdminInternalConfigProvider interface {
|
||||
ModerationProvider() (*types.ModerationProviderConfig, error)
|
||||
ModerationPolicy(tenantCode string) (*types.ModerationPolicy, error)
|
||||
SensitiveWords(tenantCode string) (*types.SensitiveWordSet, error)
|
||||
SecurityPolicy(tenantCode string) (*types.SecurityPolicy, error)
|
||||
}
|
||||
|
||||
var adminInternalConfigProvider AdminInternalConfigProvider
|
||||
@@ -185,6 +186,7 @@ type ModerationConfigPersistenceInterface interface {
|
||||
Provider() (*types.ModerationProviderConfig, error)
|
||||
Policy(tenantCode string) (*types.ModerationPolicy, error)
|
||||
Words(tenantCode string) (*types.SensitiveWordSet, error)
|
||||
SecurityPolicy(tenantCode string) (*types.SecurityPolicy, error)
|
||||
}
|
||||
|
||||
type moderationConfigMapper struct{}
|
||||
@@ -235,6 +237,21 @@ func (moderationConfigMapper) Words(tenantCode string) (*types.SensitiveWordSet,
|
||||
return value, err
|
||||
}
|
||||
|
||||
func (moderationConfigMapper) SecurityPolicy(tenantCode string) (*types.SecurityPolicy, error) {
|
||||
tenantCode = strings.TrimSpace(tenantCode)
|
||||
if value, ok := securityPolicyCache.get(tenantCode); ok {
|
||||
return value, nil
|
||||
}
|
||||
if adminInternalConfigProvider == nil {
|
||||
return nil, types.ErrUnsupported
|
||||
}
|
||||
value, err := adminInternalConfigProvider.SecurityPolicy(tenantCode)
|
||||
if err == nil && value != nil {
|
||||
securityPolicyCache.set(tenantCode, value)
|
||||
}
|
||||
return value, err
|
||||
}
|
||||
|
||||
// RegistrationConfigPersistenceInterface exposes global registration policy.
|
||||
type RegistrationConfigPersistenceInterface interface {
|
||||
SMSEnabled() (bool, error)
|
||||
|
||||
@@ -3,18 +3,21 @@ package types
|
||||
import "time"
|
||||
|
||||
type UserProfile struct {
|
||||
UserID Uid
|
||||
AvatarFileID string
|
||||
Nickname string
|
||||
BirthDate string
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string
|
||||
Version int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
UserID Uid
|
||||
AvatarFileID string
|
||||
Nickname string
|
||||
BirthDate string
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string
|
||||
FriendAddEnabled bool
|
||||
FriendAddDisabledReason string
|
||||
FriendAddPolicyVersion int
|
||||
Version int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type UserProfilePatch struct {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package types
|
||||
|
||||
type SecurityPolicy struct {
|
||||
TenantID TenantID `json:"tenant_id"`
|
||||
TenantCode string `json:"tenant_code"`
|
||||
PolicyVersion uint `json:"policy_version"`
|
||||
GlobalFriendEnabled bool `json:"global_friend_enabled"`
|
||||
FriendDisabledPolicy map[string]any `json:"friend_disabled_policy"`
|
||||
MessageCurfewEnabled bool `json:"message_curfew_enabled"`
|
||||
CurfewRules []*MessageCurfewRule `json:"curfew_rules"`
|
||||
}
|
||||
|
||||
type MessageCurfewRule struct {
|
||||
RuleCode string `json:"rule_code"`
|
||||
RuleName string `json:"rule_name"`
|
||||
DateType string `json:"date_type"`
|
||||
CustomDates []string `json:"custom_dates"`
|
||||
Weekdays []int `json:"weekdays"`
|
||||
Timezone string `json:"timezone"`
|
||||
StartTime string `json:"start_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
Scope string `json:"scope"`
|
||||
WhitelistUserIds []string `json:"whitelist_user_ids"`
|
||||
WhitelistGroupIds []string `json:"whitelist_group_ids"`
|
||||
Message string `json:"message"`
|
||||
Status int `json:"status"`
|
||||
Sort int `json:"sort"`
|
||||
}
|
||||
Reference in New Issue
Block a user