snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
190
server/public/model/preference.go
Normal file
190
server/public/model/preference.go
Normal file
@@ -0,0 +1,190 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
// The primary key for the preference table is the combination of User.Id, Category, and Name.
|
||||
|
||||
// PreferenceCategoryDirectChannelShow and PreferenceCategoryGroupChannelShow
|
||||
// are used to store the user's preferences for which channels to show in the sidebar.
|
||||
// The Name field is the channel ID.
|
||||
PreferenceCategoryDirectChannelShow = "direct_channel_show"
|
||||
PreferenceCategoryGroupChannelShow = "group_channel_show"
|
||||
// PreferenceCategoryTutorialStep is used to store the user's progress in the tutorial.
|
||||
// The Name field is the user ID again (for whatever reason).
|
||||
PreferenceCategoryTutorialSteps = "tutorial_step"
|
||||
// PreferenceCategoryAdvancedSettings has settings for the user's advanced settings.
|
||||
// The Name field is the setting name. Possible values are:
|
||||
// - "formatting"
|
||||
// - "send_on_ctrl_enter"
|
||||
// - "join_leave"
|
||||
// - "unread_scroll_position"
|
||||
// - "sync_drafts"
|
||||
// - "attach_app_logs"
|
||||
// - "feature_enabled_markdown_preview" <- deprecated in favor of "formatting"
|
||||
PreferenceCategoryAdvancedSettings = "advanced_settings"
|
||||
// PreferenceCategoryFlaggedPost is used to store the user's saved posts.
|
||||
// The Name field is the post ID.
|
||||
PreferenceCategoryFlaggedPost = "flagged_post"
|
||||
// PreferenceCategoryFavoriteChannel is used to store the user's favorite channels to be
|
||||
// shown in the sidebar. The Name field is the channel ID.
|
||||
PreferenceCategoryFavoriteChannel = "favorite_channel"
|
||||
// PreferenceCategorySidebarSettings is used to store the user's sidebar settings.
|
||||
// The Name field is the setting name. (ie. PreferenceNameShowUnreadSection or PreferenceLimitVisibleDmsGms)
|
||||
PreferenceCategorySidebarSettings = "sidebar_settings"
|
||||
// PreferenceCategoryDisplaySettings is used to store the user's various display settings.
|
||||
// The possible Name fields are:
|
||||
// - PreferenceNameUseMilitaryTime
|
||||
// - PreferenceNameCollapseSetting
|
||||
// - PreferenceNameMessageDisplay
|
||||
// - PreferenceNameCollapseConsecutive
|
||||
// - PreferenceNameColorizeUsernames
|
||||
// - PreferenceNameChannelDisplayMode
|
||||
// - PreferenceNameNameFormat
|
||||
PreferenceCategoryDisplaySettings = "display_settings"
|
||||
// PreferenceCategorySystemNotice is used store system admin notices.
|
||||
// Possible Name values are not defined here. It can be anything with the notice name.
|
||||
PreferenceCategorySystemNotice = "system_notice"
|
||||
// Deprecated: PreferenceCategoryLast is not used anymore.
|
||||
PreferenceCategoryLast = "last"
|
||||
// PreferenceCategoryCustomStatus is used to store the user's custom status preferences.
|
||||
// Possible Name values are:
|
||||
// - PreferenceNameRecentCustomStatuses
|
||||
// - PreferenceNameCustomStatusTutorialState
|
||||
// - PreferenceCustomStatusModalViewed
|
||||
PreferenceCategoryCustomStatus = "custom_status"
|
||||
// PreferenceCategoryNotifications is used to store the user's notification settings.
|
||||
// Possible Name values are:
|
||||
// - PreferenceNameEmailInterval
|
||||
PreferenceCategoryNotifications = "notifications"
|
||||
|
||||
// Deprecated: PreferenceRecommendedNextSteps is not used anymore.
|
||||
// Use PreferenceCategoryRecommendedNextSteps instead.
|
||||
// PreferenceRecommendedNextSteps is actually a Category. The only possible
|
||||
// Name vaule is PreferenceRecommendedNextStepsHide for now.
|
||||
PreferenceRecommendedNextSteps = PreferenceCategoryRecommendedNextSteps
|
||||
PreferenceCategoryRecommendedNextSteps = "recommended_next_steps"
|
||||
|
||||
// PreferenceCategoryTheme has the name for the team id where theme is set.
|
||||
PreferenceCategoryTheme = "theme"
|
||||
|
||||
PreferenceNameAttachAppLogs = "attach_app_logs"
|
||||
PreferenceNameCollapsedThreadsEnabled = "collapsed_reply_threads"
|
||||
PreferenceNameChannelDisplayMode = "channel_display_mode"
|
||||
PreferenceNameCollapseSetting = "collapse_previews"
|
||||
PreferenceNameMessageDisplay = "message_display"
|
||||
PreferenceNameCollapseConsecutive = "collapse_consecutive_messages"
|
||||
PreferenceNameColorizeUsernames = "colorize_usernames"
|
||||
PreferenceNameNameFormat = "name_format"
|
||||
PreferenceNameUseMilitaryTime = "use_military_time"
|
||||
|
||||
PreferenceNameShowUnreadSection = "show_unread_section"
|
||||
PreferenceLimitVisibleDmsGms = "limit_visible_dms_gms"
|
||||
|
||||
PreferenceMaxLimitVisibleDmsGmsValue = 40
|
||||
MaxPreferenceValueLength = 20000
|
||||
|
||||
PreferenceCategoryAuthorizedOAuthApp = "oauth_app"
|
||||
// the name for oauth_app is the client_id and value is the current scope
|
||||
|
||||
// Deprecated: PreferenceCategoryLastChannel is not used anymore.
|
||||
PreferenceNameLastChannel = "channel"
|
||||
// Deprecated: PreferenceCategoryLastTeam is not used anymore.
|
||||
PreferenceNameLastTeam = "team"
|
||||
|
||||
PreferenceNameRecentCustomStatuses = "recent_custom_statuses"
|
||||
PreferenceNameCustomStatusTutorialState = "custom_status_tutorial_state"
|
||||
PreferenceCustomStatusModalViewed = "custom_status_modal_viewed"
|
||||
|
||||
PreferenceNameEmailInterval = "email_interval"
|
||||
|
||||
PreferenceEmailIntervalNoBatchingSeconds = "30" // the "immediate" setting is actually 30s
|
||||
PreferenceEmailIntervalBatchingSeconds = "900" // fifteen minutes is 900 seconds
|
||||
PreferenceEmailIntervalImmediately = "immediately"
|
||||
PreferenceEmailIntervalFifteen = "fifteen"
|
||||
PreferenceEmailIntervalFifteenAsSeconds = "900"
|
||||
PreferenceEmailIntervalHour = "hour"
|
||||
PreferenceEmailIntervalHourAsSeconds = "3600"
|
||||
PreferenceCloudUserEphemeralInfo = "cloud_user_ephemeral_info"
|
||||
|
||||
PreferenceNameRecommendedNextStepsHide = "hide"
|
||||
)
|
||||
|
||||
type Preference struct {
|
||||
UserId string `json:"user_id"`
|
||||
Category string `json:"category"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type Preferences []Preference
|
||||
|
||||
func (o *Preference) IsValid() *AppError {
|
||||
if !IsValidId(o.UserId) {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.id.app_error", nil, "user_id="+o.UserId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.Category == "" || len(o.Category) > 32 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.category.app_error", nil, "category="+o.Category, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if len(o.Name) > 32 {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.name.app_error", nil, "name="+o.Name, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Value) > MaxPreferenceValueLength {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.value.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
var unused map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&unused); err != nil {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
if o.Category == PreferenceCategorySidebarSettings && o.Name == PreferenceLimitVisibleDmsGms {
|
||||
visibleDmsGmsValue, convErr := strconv.Atoi(o.Value)
|
||||
if convErr != nil || visibleDmsGmsValue < 1 || visibleDmsGmsValue > PreferenceMaxLimitVisibleDmsGmsValue {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.limit_visible_dms_gms.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var preUpdateColorPattern = regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
|
||||
func (o *Preference) PreUpdate() {
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
// decode the value of theme (a map of strings to string) and eliminate any invalid values
|
||||
var props map[string]string
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
json.NewDecoder(strings.NewReader(o.Value)).Decode(&props)
|
||||
|
||||
// blank out any invalid theme values
|
||||
for name, value := range props {
|
||||
if name == "image" || name == "type" || name == "codeTheme" {
|
||||
continue
|
||||
}
|
||||
|
||||
if !preUpdateColorPattern.MatchString(value) {
|
||||
props[name] = "#ffffff"
|
||||
}
|
||||
}
|
||||
|
||||
if b, err := json.Marshal(props); err == nil {
|
||||
o.Value = string(b)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user