mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-27 12:13:29 -04: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
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package model
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
type ReviewSettingsRequest struct {
|
|
ReviewerSettings
|
|
ReviewerIDsSettings
|
|
}
|
|
|
|
func (rs *ReviewSettingsRequest) SetDefaults() {
|
|
rs.ReviewerSettings.SetDefaults()
|
|
rs.ReviewerIDsSettings.SetDefaults()
|
|
}
|
|
|
|
func (rs *ReviewSettingsRequest) IsValid() *AppError {
|
|
additionalReviewersEnabled := *rs.SystemAdminsAsReviewers || *rs.TeamAdminsAsReviewers
|
|
|
|
// If common reviewers are enabled, there must be at least one specified reviewer, or additional viewers be specified
|
|
if *rs.CommonReviewers && len(rs.CommonReviewerIds) == 0 && !additionalReviewersEnabled {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.content_flagging.common_reviewers_not_set.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
// if Additional Reviewers are specified, no extra validation is needed in team specific settings as
|
|
// settings team reviewers keeping team feature disabled is valid, as well as
|
|
// enabling team feature and not specified reviews is fine as well (since Additional Reviewers are set)
|
|
if !additionalReviewersEnabled {
|
|
for _, setting := range rs.TeamReviewersSetting {
|
|
if *setting.Enabled && len(setting.ReviewerIds) == 0 {
|
|
return NewAppError("Config.IsValid", "model.config.is_valid.content_flagging.team_reviewers_not_set.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type ContentFlaggingSettingsRequest struct {
|
|
ContentFlaggingSettingsBase
|
|
ReviewerSettings *ReviewSettingsRequest
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettingsRequest) SetDefaults() {
|
|
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.ReviewerSettings == nil {
|
|
cfs.ReviewerSettings = &ReviewSettingsRequest{}
|
|
}
|
|
|
|
if cfs.AdditionalSettings == nil {
|
|
cfs.AdditionalSettings = &AdditionalContentFlaggingSettings{}
|
|
}
|
|
|
|
cfs.NotificationSettings.SetDefaults()
|
|
cfs.ReviewerSettings.SetDefaults()
|
|
cfs.AdditionalSettings.SetDefaults()
|
|
}
|
|
|
|
func (cfs *ContentFlaggingSettingsRequest) IsValid() *AppError {
|
|
if appErr := cfs.ContentFlaggingSettingsBase.IsValid(); appErr != nil {
|
|
return appErr
|
|
}
|
|
|
|
if appErr := cfs.ReviewerSettings.IsValid(); appErr != nil {
|
|
return appErr
|
|
}
|
|
|
|
return nil
|
|
}
|