Channel banner sql migrations (#30274)
* Adde MySQL and Postgres migrations * Replaced select * with column names * removed all * from channel SQL store * cleanup * Fixed a duplicate column * cleanup * Added migrations and store support * WIP * used channelname slice in a missed place * Handled patch * Added app level tests * Added API layer tests * Added API layer tests * WIP * converted to query builder * cleanupo * added not null and default constraints * Fixed test * fixed file name * review fixes * review fixes * updated migration file * fixed text * Review fixes
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6df8726321
Коммит
6e738f489f
@@ -5,8 +5,10 @@ package model
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"database/sql/driver"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -32,33 +34,66 @@ const (
|
||||
ChannelHeaderMaxRunes = 1024
|
||||
ChannelPurposeMaxRunes = 250
|
||||
ChannelCacheSize = 25000
|
||||
ChannelBannerInfoMaxLength = 1024
|
||||
|
||||
ChannelSortByUsername = "username"
|
||||
ChannelSortByStatus = "status"
|
||||
)
|
||||
|
||||
type ChannelBannerInfo struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
Text *string `json:"text"`
|
||||
BackgroundColor *string `json:"background_color"`
|
||||
}
|
||||
|
||||
func (c *ChannelBannerInfo) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
b, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected []byte, got %T", value)
|
||||
}
|
||||
|
||||
return json.Unmarshal(b, c)
|
||||
}
|
||||
|
||||
func (c ChannelBannerInfo) Value() (driver.Value, error) {
|
||||
if c == (ChannelBannerInfo{}) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
j, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(j), nil
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
TeamId string `json:"team_id"`
|
||||
Type ChannelType `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Name string `json:"name"`
|
||||
Header string `json:"header"`
|
||||
Purpose string `json:"purpose"`
|
||||
LastPostAt int64 `json:"last_post_at"`
|
||||
TotalMsgCount int64 `json:"total_msg_count"`
|
||||
ExtraUpdateAt int64 `json:"extra_update_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
SchemeId *string `json:"scheme_id"`
|
||||
Props map[string]any `json:"props"`
|
||||
GroupConstrained *bool `json:"group_constrained"`
|
||||
Shared *bool `json:"shared"`
|
||||
TotalMsgCountRoot int64 `json:"total_msg_count_root"`
|
||||
PolicyID *string `json:"policy_id"`
|
||||
LastRootPostAt int64 `json:"last_root_post_at"`
|
||||
Id string `json:"id"`
|
||||
CreateAt int64 `json:"create_at"`
|
||||
UpdateAt int64 `json:"update_at"`
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
TeamId string `json:"team_id"`
|
||||
Type ChannelType `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Name string `json:"name"`
|
||||
Header string `json:"header"`
|
||||
Purpose string `json:"purpose"`
|
||||
LastPostAt int64 `json:"last_post_at"`
|
||||
TotalMsgCount int64 `json:"total_msg_count"`
|
||||
ExtraUpdateAt int64 `json:"extra_update_at"`
|
||||
CreatorId string `json:"creator_id"`
|
||||
SchemeId *string `json:"scheme_id"`
|
||||
Props map[string]any `json:"props"`
|
||||
GroupConstrained *bool `json:"group_constrained"`
|
||||
Shared *bool `json:"shared"`
|
||||
TotalMsgCountRoot int64 `json:"total_msg_count_root"`
|
||||
PolicyID *string `json:"policy_id"`
|
||||
LastRootPostAt int64 `json:"last_root_post_at"`
|
||||
BannerInfo *ChannelBannerInfo `json:"banner_info"`
|
||||
}
|
||||
|
||||
func (o *Channel) Auditable() map[string]interface{} {
|
||||
@@ -99,11 +134,12 @@ type ChannelsWithCount struct {
|
||||
}
|
||||
|
||||
type ChannelPatch struct {
|
||||
DisplayName *string `json:"display_name"`
|
||||
Name *string `json:"name"`
|
||||
Header *string `json:"header"`
|
||||
Purpose *string `json:"purpose"`
|
||||
GroupConstrained *bool `json:"group_constrained"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Name *string `json:"name"`
|
||||
Header *string `json:"header"`
|
||||
Purpose *string `json:"purpose"`
|
||||
GroupConstrained *bool `json:"group_constrained"`
|
||||
BannerInfo *ChannelBannerInfo `json:"banner_info"`
|
||||
}
|
||||
|
||||
func (c *ChannelPatch) Auditable() map[string]interface{} {
|
||||
@@ -261,6 +297,22 @@ func (o *Channel) IsValid() *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if o.BannerInfo != nil && o.BannerInfo.Enabled != nil && *o.BannerInfo.Enabled {
|
||||
if o.Type != ChannelTypeOpen && o.Type != ChannelTypePrivate {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.banner_info.channel_type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.BannerInfo.Text == nil || len(*o.BannerInfo.Text) == 0 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.banner_info.text.empty.app_error", nil, "", http.StatusBadRequest)
|
||||
} else if len(*o.BannerInfo.Text) > ChannelBannerInfoMaxLength {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.banner_info.text.invalid_length.app_error", map[string]any{"maxLength": ChannelBannerInfoMaxLength}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if o.BannerInfo.BackgroundColor == nil || len(*o.BannerInfo.BackgroundColor) == 0 {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.banner_info.background_color.empty.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -312,6 +364,25 @@ func (o *Channel) Patch(patch *ChannelPatch) {
|
||||
if patch.GroupConstrained != nil {
|
||||
o.GroupConstrained = patch.GroupConstrained
|
||||
}
|
||||
|
||||
// patching channel banner info
|
||||
if patch.BannerInfo != nil {
|
||||
if o.BannerInfo == nil {
|
||||
o.BannerInfo = &ChannelBannerInfo{}
|
||||
}
|
||||
|
||||
if patch.BannerInfo.Enabled != nil {
|
||||
o.BannerInfo.Enabled = patch.BannerInfo.Enabled
|
||||
}
|
||||
|
||||
if patch.BannerInfo.Text != nil {
|
||||
o.BannerInfo.Text = patch.BannerInfo.Text
|
||||
}
|
||||
|
||||
if patch.BannerInfo.BackgroundColor != nil {
|
||||
o.BannerInfo.BackgroundColor = patch.BannerInfo.BackgroundColor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Channel) MakeNonNil() {
|
||||
|
||||
Ссылка в новой задаче
Block a user