mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* MM-68149: upgrade to Go 1.26.2 Update go directive in go.mod and .go-version. * MM-68149: replace pointer helpers with Go 1.26 new() Go 1.26 extends the built-in new() to accept an initial value expression, making typed-pointer helpers like model.NewPointer(x), bToP(x), and boolPtr(x) redundant. Replace every call site with new(x) and remove the now-unused helper functions and their //go:fix inline directives. * MM-68149: apply go fix for reflect API and format-string changes - reflect.Ptr → reflect.Pointer (renamed in Go 1.18, deprecated alias removed in 1.26) - reflect range-over-struct: for i := 0; i < t.NumField(); i++ → for field := range t.Fields() and the equivalent for Methods() and interface types - Fix format-string concatenation and variadic-arg mismatches flagged by go vet * MM-68149: update JPEG fixtures and test infrastructure for Go 1.26 encoder Go 1.26 ships a new image/jpeg encoder that produces slightly different output. Regenerate all JPEG fixture files and switch the comparison helpers from byte-equality to pixel-level comparison with a small per-channel tolerance, so minor encoder drift across patch versions is handled automatically. Add -update-fixtures flag to make it easy to regenerate fixtures after future major Go upgrades. Document the update procedure in tests/README.md. * MM-68149: CI check that go fix ./... produces no changes * Fix real bugs flagged by CodeRabbit review - group.go: set newGroup.MemberCount not group.MemberCount (member count was populated on the wrong variable and lost before publish/return) - file_test.go: guard compareImage(GetFilePreview) on the preview slice length, not the thumbnail slice length (copy-paste error) - config_test.go: remove duplicate MinimumLength assignment * fixup! Fix real bugs flagged by CodeRabbit review
236 lines
6.9 KiB
Go
236 lines
6.9 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"slices"
|
|
)
|
|
|
|
type ContentFlaggingEvent string
|
|
|
|
const (
|
|
EventFlagged ContentFlaggingEvent = "flagged"
|
|
EventAssigned ContentFlaggingEvent = "assigned"
|
|
EventContentRemoved ContentFlaggingEvent = "removed"
|
|
EventContentDismissed ContentFlaggingEvent = "dismissed"
|
|
)
|
|
|
|
type NotificationTarget string
|
|
|
|
const (
|
|
TargetReviewers NotificationTarget = "reviewers"
|
|
TargetAuthor NotificationTarget = "author"
|
|
TargetReporter NotificationTarget = "reporter"
|
|
)
|
|
|
|
var ContentFlaggingDefaultReasons = []string{
|
|
"Classification mismatch",
|
|
"Need-to-know violation",
|
|
"Personally identifiable information (PII) exposure",
|
|
"Operational security (OPSEC) concern",
|
|
"Controlled Unclassified Information (CUI) violation",
|
|
"Unauthorized disclosure",
|
|
"Other",
|
|
}
|
|
|
|
type ContentFlaggingNotificationSettings struct {
|
|
EventTargetMapping map[ContentFlaggingEvent][]NotificationTarget
|
|
}
|
|
|
|
func (cfs *ContentFlaggingNotificationSettings) SetDefaults() {
|
|
if cfs.EventTargetMapping == nil {
|
|
cfs.EventTargetMapping = make(map[ContentFlaggingEvent][]NotificationTarget)
|
|
}
|
|
|
|
if _, exists := cfs.EventTargetMapping[EventFlagged]; !exists {
|
|
cfs.EventTargetMapping[EventFlagged] = []NotificationTarget{TargetReviewers}
|
|
} else {
|
|
// Ensure TargetReviewers is always included for EventFlagged
|
|
if !slices.Contains(cfs.EventTargetMapping[EventFlagged], TargetReviewers) {
|
|
cfs.EventTargetMapping[EventFlagged] = append(cfs.EventTargetMapping[EventFlagged], TargetReviewers)
|
|
}
|
|
}
|
|
|
|
if _, exists := cfs.EventTargetMapping[EventAssigned]; !exists {
|
|
cfs.EventTargetMapping[EventAssigned] = []NotificationTarget{TargetReviewers}
|
|
}
|
|
|
|
if _, exists := cfs.EventTargetMapping[EventContentRemoved]; !exists {
|
|
cfs.EventTargetMapping[EventContentRemoved] = []NotificationTarget{TargetReviewers, TargetAuthor, TargetReporter}
|
|
}
|
|
|
|
if _, exists := cfs.EventTargetMapping[EventContentDismissed]; !exists {
|
|
cfs.EventTargetMapping[EventContentDismissed] = []NotificationTarget{TargetReviewers, TargetReporter}
|
|
}
|
|
}
|
|
|
|
func (cfs *ContentFlaggingNotificationSettings) IsValid() *AppError {
|
|
// Reviewers must be notified when content is flagged
|
|
// Disabling this option is not allowed in the UI, so this check is for safety and consistency.
|
|
|
|
// Only valid events and targets are allowed
|
|
for event, targets := range cfs.EventTargetMapping {
|
|
if event != EventFlagged && event != EventAssigned && event != EventContentRemoved && event != EventContentDismissed {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.notification_settings.invalid_event", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
for _, target := range targets {
|
|
if target != TargetReviewers && target != TargetAuthor && target != TargetReporter {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.notification_settings.invalid_target", nil, fmt.Sprintf("target: %s", target), http.StatusBadRequest)
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(cfs.EventTargetMapping[EventFlagged]) == 0 {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.notification_settings.reviewer_flagged_notification_disabled", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
// Search for the TargetReviewers in the EventFlagged event
|
|
reviewerFound := slices.Contains(cfs.EventTargetMapping[EventFlagged], TargetReviewers)
|
|
if !reviewerFound {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.notification_settings.reviewer_flagged_notification_disabled", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type TeamReviewerSetting struct {
|
|
Enabled *bool
|
|
ReviewerIds []string
|
|
}
|
|
|
|
type ReviewerSettings struct {
|
|
CommonReviewers *bool
|
|
SystemAdminsAsReviewers *bool
|
|
TeamAdminsAsReviewers *bool
|
|
}
|
|
|
|
func (rs *ReviewerSettings) SetDefaults() {
|
|
if rs.CommonReviewers == nil {
|
|
rs.CommonReviewers = new(true)
|
|
}
|
|
|
|
if rs.SystemAdminsAsReviewers == nil {
|
|
rs.SystemAdminsAsReviewers = new(false)
|
|
}
|
|
|
|
if rs.TeamAdminsAsReviewers == nil {
|
|
rs.TeamAdminsAsReviewers = new(true)
|
|
}
|
|
}
|
|
|
|
type AdditionalContentFlaggingSettings struct {
|
|
Reasons *[]string
|
|
ReporterCommentRequired *bool
|
|
ReviewerCommentRequired *bool
|
|
HideFlaggedContent *bool
|
|
}
|
|
|
|
func (acfs *AdditionalContentFlaggingSettings) SetDefaults() {
|
|
if acfs.Reasons == nil {
|
|
acfs.Reasons = &ContentFlaggingDefaultReasons
|
|
}
|
|
|
|
if acfs.ReporterCommentRequired == nil {
|
|
acfs.ReporterCommentRequired = new(true)
|
|
}
|
|
|
|
if acfs.ReviewerCommentRequired == nil {
|
|
acfs.ReviewerCommentRequired = new(true)
|
|
}
|
|
|
|
if acfs.HideFlaggedContent == nil {
|
|
acfs.HideFlaggedContent = new(true)
|
|
}
|
|
}
|
|
|
|
func (acfs *AdditionalContentFlaggingSettings) IsValid() *AppError {
|
|
if acfs.Reasons == nil || len(*acfs.Reasons) == 0 {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.content_flagging.reasons_not_set.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type ContentFlaggingSettingsBase struct {
|
|
EnableContentFlagging *bool
|
|
NotificationSettings *ContentFlaggingNotificationSettings
|
|
AdditionalSettings *AdditionalContentFlaggingSettings
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettingsBase) SetDefaults() {
|
|
if cfs.EnableContentFlagging == nil {
|
|
cfs.EnableContentFlagging = new(false)
|
|
}
|
|
|
|
if cfs.NotificationSettings == nil {
|
|
cfs.NotificationSettings = &ContentFlaggingNotificationSettings{
|
|
EventTargetMapping: make(map[ContentFlaggingEvent][]NotificationTarget),
|
|
}
|
|
}
|
|
|
|
if cfs.AdditionalSettings == nil {
|
|
cfs.AdditionalSettings = &AdditionalContentFlaggingSettings{}
|
|
}
|
|
|
|
cfs.NotificationSettings.SetDefaults()
|
|
cfs.AdditionalSettings.SetDefaults()
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettingsBase) IsValid() *AppError {
|
|
if err := cfs.NotificationSettings.IsValid(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := cfs.AdditionalSettings.IsValid(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type ContentFlaggingSettings struct {
|
|
ContentFlaggingSettingsBase
|
|
ReviewerSettings *ReviewerSettings
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettings) SetDefaults() {
|
|
cfs.ContentFlaggingSettingsBase.SetDefaults()
|
|
|
|
if cfs.ReviewerSettings == nil {
|
|
cfs.ReviewerSettings = &ReviewerSettings{}
|
|
}
|
|
|
|
cfs.ReviewerSettings.SetDefaults()
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettings) IsValid() *AppError {
|
|
return cfs.ContentFlaggingSettingsBase.IsValid()
|
|
}
|
|
|
|
type ContentFlaggingReportingConfig struct {
|
|
Reasons *[]string `json:"reasons"`
|
|
ReporterCommentRequired *bool `json:"reporter_comment_required"`
|
|
ReviewerCommentRequired *bool `json:"reviewer_comment_required"`
|
|
NotifyReporterOnDismissal *bool `json:"notify_reporter_on_dismissal,omitempty"`
|
|
NotifyReporterOnRemoval *bool `json:"notify_reporter_on_removal,omitempty"`
|
|
}
|
|
|
|
type ReviewerIDsSettings struct {
|
|
CommonReviewerIds []string
|
|
TeamReviewersSetting map[string]*TeamReviewerSetting
|
|
}
|
|
|
|
func (rs *ReviewerIDsSettings) SetDefaults() {
|
|
if rs.CommonReviewerIds == nil {
|
|
rs.CommonReviewerIds = []string{}
|
|
}
|
|
|
|
if rs.TeamReviewersSetting == nil {
|
|
rs.TeamReviewersSetting = map[string]*TeamReviewerSetting{}
|
|
}
|
|
}
|