[MM-22051] Remove To/From JSON (#18070)
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6861efb47e
Коммит
92837fa1ee
@@ -66,7 +66,7 @@ func (t *TraceOnAdapter) Printf(format string, v ...interface{}) {
|
||||
}
|
||||
|
||||
type JSONSerializable interface {
|
||||
ToJson() string
|
||||
ToJSON() string
|
||||
}
|
||||
|
||||
type mattermConverter struct{}
|
||||
@@ -74,19 +74,21 @@ type mattermConverter struct{}
|
||||
func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
|
||||
switch t := val.(type) {
|
||||
case model.StringMap:
|
||||
return model.MapToJson(t), nil
|
||||
return model.MapToJSON(t), nil
|
||||
case map[string]string:
|
||||
return model.MapToJson(model.StringMap(t)), nil
|
||||
return model.MapToJSON(model.StringMap(t)), nil
|
||||
case model.StringArray:
|
||||
return model.ArrayToJson(t), nil
|
||||
return model.ArrayToJSON(t), nil
|
||||
case model.StringInterface:
|
||||
return model.StringInterfaceToJson(t), nil
|
||||
return model.StringInterfaceToJSON(t), nil
|
||||
case map[string]interface{}:
|
||||
return model.StringInterfaceToJson(model.StringInterface(t)), nil
|
||||
return model.StringInterfaceToJSON(model.StringInterface(t)), nil
|
||||
case JSONSerializable:
|
||||
return t.ToJson(), nil
|
||||
return t.ToJSON(), nil
|
||||
case *opengraph.OpenGraph:
|
||||
return json.Marshal(t)
|
||||
case *model.PostImage:
|
||||
return json.Marshal(t)
|
||||
}
|
||||
|
||||
return val, nil
|
||||
|
||||
@@ -108,7 +108,7 @@ func channelMemberToSlice(member *model.ChannelMember) []interface{} {
|
||||
resultSlice = append(resultSlice, member.MsgCountRoot)
|
||||
resultSlice = append(resultSlice, member.MentionCount)
|
||||
resultSlice = append(resultSlice, member.MentionCountRoot)
|
||||
resultSlice = append(resultSlice, model.MapToJson(member.NotifyProps))
|
||||
resultSlice = append(resultSlice, model.MapToJSON(member.NotifyProps))
|
||||
resultSlice = append(resultSlice, member.LastUpdateAt)
|
||||
resultSlice = append(resultSlice, member.SchemeUser)
|
||||
resultSlice = append(resultSlice, member.SchemeAdmin)
|
||||
@@ -1642,7 +1642,7 @@ func (s SqlChannelStore) UpdateMemberNotifyProps(channelID, userID string, props
|
||||
if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
_, err = tx.Exec(`UPDATE channelmembers
|
||||
SET notifyprops = notifyprops || $1::jsonb
|
||||
WHERE userid=$2 AND channelid=$3`, model.MapToJson(props), userID, channelID)
|
||||
WHERE userid=$2 AND channelid=$3`, model.MapToJSON(props), userID, channelID)
|
||||
} else {
|
||||
// It's difficult to construct a SQL query for MySQL
|
||||
// to handle a case of empty map. So we just ignore it.
|
||||
|
||||
@@ -5,6 +5,7 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -46,11 +47,15 @@ func (jss SqlJobStore) Save(job *model.Job) (*model.Job, error) {
|
||||
}
|
||||
|
||||
func (jss SqlJobStore) UpdateOptimistically(job *model.Job, currentStatus string) (bool, error) {
|
||||
dataJSON, jsonErr := json.Marshal(job.Data)
|
||||
if jsonErr != nil {
|
||||
return false, errors.Wrap(jsonErr, "failed to encode job's data to JSON")
|
||||
}
|
||||
query, args, err := jss.getQueryBuilder().
|
||||
Update("Jobs").
|
||||
Set("LastActivityAt", model.GetMillis()).
|
||||
Set("Status", job.Status).
|
||||
Set("Data", job.DataToJson()).
|
||||
Set("Data", string(dataJSON)).
|
||||
Set("Progress", job.Progress).
|
||||
Where(sq.Eq{"Id": job.Id, "Status": currentStatus}).ToSql()
|
||||
if err != nil {
|
||||
|
||||
@@ -85,10 +85,10 @@ func postToSlice(post *model.Post) []interface{} {
|
||||
post.OriginalId,
|
||||
post.Message,
|
||||
post.Type,
|
||||
model.StringInterfaceToJson(post.Props),
|
||||
model.StringInterfaceToJSON(post.Props),
|
||||
post.Hashtags,
|
||||
model.ArrayToJson(post.Filenames),
|
||||
model.ArrayToJson(post.FileIds),
|
||||
model.ArrayToJSON(post.Filenames),
|
||||
model.ArrayToJSON(post.FileIds),
|
||||
post.HasReactions,
|
||||
post.RemoteId,
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func (me SqlSessionStore) UpdateProps(session *model.Session) error {
|
||||
_, err := me.GetMaster().Exec(`UPDATE Sessions
|
||||
SET Props=:Props
|
||||
WHERE Id=:Id`, map[string]interface{}{
|
||||
"Props": model.MapToJson(session.Props),
|
||||
"Props": model.MapToJSON(session.Props),
|
||||
"Id": session.Id,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -53,7 +53,7 @@ func threadToSlice(thread *model.Thread) []interface{} {
|
||||
thread.ChannelId,
|
||||
thread.LastReplyAt,
|
||||
thread.ReplyCount,
|
||||
model.ArrayToJson(thread.Participants),
|
||||
model.ArrayToJSON(thread.Participants),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ func (us SqlUserStore) UpdateNotifyProps(userID string, props map[string]string)
|
||||
if _, err := us.GetMaster().Exec(`UPDATE Users
|
||||
SET NotifyProps = :NotifyProps
|
||||
WHERE Id = :UserId`, map[string]interface{}{
|
||||
"NotifyProps": model.MapToJson(props),
|
||||
"NotifyProps": model.MapToJSON(props),
|
||||
"UserId": userID}); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userID)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package storetest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,6 +37,20 @@ func cleanupChannels(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
func channelToJSON(t *testing.T, channel *model.Channel) string {
|
||||
t.Helper()
|
||||
js, err := json.Marshal(channel)
|
||||
require.NoError(t, err)
|
||||
return string(js)
|
||||
}
|
||||
|
||||
func channelMemberToJSON(t *testing.T, cm *model.ChannelMember) string {
|
||||
t.Helper()
|
||||
js, err := json.Marshal(cm)
|
||||
require.NoError(t, err)
|
||||
return string(js)
|
||||
}
|
||||
|
||||
func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
createDefaultRoles(ss)
|
||||
|
||||
@@ -379,7 +394,7 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlStore) {
|
||||
|
||||
c1, err := ss.Channel().Get(o1.Id, false)
|
||||
require.NoError(t, err, err)
|
||||
require.Equal(t, o1.ToJson(), c1.ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, c1), "invalid returned channel")
|
||||
|
||||
_, err = ss.Channel().Get("", false)
|
||||
require.Error(t, err, "missing id should have failed")
|
||||
@@ -421,11 +436,11 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlStore) {
|
||||
|
||||
c2, err := ss.Channel().Get(o2.Id, false)
|
||||
require.NoError(t, err, err)
|
||||
require.Equal(t, o2.ToJson(), c2.ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o2), channelToJSON(t, c2), "invalid returned channel")
|
||||
|
||||
c4, err := ss.Channel().Get(o2.Id, true)
|
||||
require.NoError(t, err, err)
|
||||
require.Equal(t, o2.ToJson(), c4.ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o2), channelToJSON(t, c4), "invalid returned channel")
|
||||
|
||||
channels, chanErr := ss.Channel().GetAll(o1.TeamId)
|
||||
require.NoError(t, chanErr, chanErr)
|
||||
@@ -499,8 +514,8 @@ func testChannelStoreGetChannelsByIds(t *testing.T, ss store.Store) {
|
||||
r1, err := ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}, false)
|
||||
require.NoError(t, err, err)
|
||||
require.Len(t, r1, 2, "invalid returned channels, exepected 2 and got "+strconv.Itoa(len(r1)))
|
||||
require.Equal(t, o1.ToJson(), r1[0].ToJson())
|
||||
require.Equal(t, o2.ToJson(), r1[1].ToJson())
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, r1[0]))
|
||||
require.Equal(t, channelToJSON(t, &o2), channelToJSON(t, r1[1]))
|
||||
})
|
||||
|
||||
t.Run("Get 1 existing and 1 not existing channel", func(t *testing.T) {
|
||||
@@ -508,16 +523,16 @@ func testChannelStoreGetChannelsByIds(t *testing.T, ss store.Store) {
|
||||
r2, err := ss.Channel().GetChannelsByIds([]string{o1.Id, nonexistentId}, false)
|
||||
require.NoError(t, err, err)
|
||||
require.Len(t, r2, 1, "invalid returned channels, expected 1 and got "+strconv.Itoa(len(r2)))
|
||||
require.Equal(t, o1.ToJson(), r2[0].ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, r2[0]), "invalid returned channel")
|
||||
})
|
||||
|
||||
t.Run("Get 2 existing and 1 deleted channel", func(t *testing.T) {
|
||||
r1, err := ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id, o3.Id}, true)
|
||||
require.NoError(t, err, err)
|
||||
require.Len(t, r1, 3, "invalid returned channels, exepected 3 and got "+strconv.Itoa(len(r1)))
|
||||
require.Equal(t, o1.ToJson(), r1[0].ToJson())
|
||||
require.Equal(t, o2.ToJson(), r1[1].ToJson())
|
||||
require.Equal(t, o3.ToJson(), r1[2].ToJson())
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, r1[0]))
|
||||
require.Equal(t, channelToJSON(t, &o2), channelToJSON(t, r1[1]))
|
||||
require.Equal(t, channelToJSON(t, &o3), channelToJSON(t, r1[2]))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -656,7 +671,7 @@ func testChannelStoreGetByName(t *testing.T, ss store.Store) {
|
||||
|
||||
result, err := ss.Channel().GetByName(o1.TeamId, o1.Name, true)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, o1.ToJson(), result.ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, result), "invalid returned channel")
|
||||
|
||||
channelID := result.Id
|
||||
|
||||
@@ -665,7 +680,7 @@ func testChannelStoreGetByName(t *testing.T, ss store.Store) {
|
||||
|
||||
result, err = ss.Channel().GetByName(o1.TeamId, o1.Name, false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, o1.ToJson(), result.ToJson(), "invalid returned channel")
|
||||
require.Equal(t, channelToJSON(t, &o1), channelToJSON(t, result), "invalid returned channel")
|
||||
|
||||
_, err = ss.Channel().GetByName(o1.TeamId, "", false)
|
||||
require.Error(t, err, "Missing id should have failed")
|
||||
@@ -4405,7 +4420,7 @@ func testChannelStoreGetMemberForPost(t *testing.T, ss store.Store) {
|
||||
|
||||
r1, err := ss.Channel().GetMemberForPost(p1.Id, m1.UserId)
|
||||
require.NoError(t, err, err)
|
||||
require.Equal(t, m1.ToJson(), r1.ToJson(), "invalid returned channel member")
|
||||
require.Equal(t, channelMemberToJSON(t, m1), channelMemberToJSON(t, r1), "invalid returned channel member")
|
||||
|
||||
_, err = ss.Channel().GetMemberForPost(p1.Id, model.NewId())
|
||||
require.Error(t, err, "shouldn't have returned a member")
|
||||
|
||||
@@ -40,7 +40,6 @@ func testLinkMetadataStoreSave(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
linkMetadata, err := ss.LinkMetadata().Save(metadata)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *metadata, *linkMetadata)
|
||||
})
|
||||
|
||||
@@ -11,8 +11,8 @@ type JSONSerializable struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// ToJson provides a mock function with given fields:
|
||||
func (_m *JSONSerializable) ToJson() string {
|
||||
// ToJSON provides a mock function with given fields:
|
||||
func (_m *JSONSerializable) ToJSON() string {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 string
|
||||
|
||||
@@ -47,7 +47,7 @@ func testPreferenceSave(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, preference := range preferences {
|
||||
data, _ := ss.Preference().Get(preference.UserId, preference.Category, preference.Name)
|
||||
require.Equal(t, data.ToJson(), preference.ToJson(), "got incorrect preference after first Save")
|
||||
require.Equal(t, data, &preference, "got incorrect preference after first Save")
|
||||
}
|
||||
|
||||
preferences[0].Value = "value2a"
|
||||
@@ -57,7 +57,7 @@ func testPreferenceSave(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, preference := range preferences {
|
||||
data, _ := ss.Preference().Get(preference.UserId, preference.Category, preference.Name)
|
||||
require.Equal(t, data.ToJson(), preference.ToJson(), "got incorrect preference after second Save")
|
||||
require.Equal(t, data, &preference, "got incorrect preference after second Save")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func testPreferenceGet(t *testing.T, ss store.Store) {
|
||||
|
||||
data, err := ss.Preference().Get(userId, category, name)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, preferences[0].ToJson(), data.ToJson(), "got incorrect preference")
|
||||
require.Equal(t, &preferences[0], data, "got incorrect preference")
|
||||
|
||||
// make sure getting a missing preference fails
|
||||
_, err = ss.Preference().Get(model.NewId(), model.NewId(), model.NewId())
|
||||
|
||||
@@ -126,7 +126,7 @@ func testTeamStoreGet(t *testing.T, ss store.Store) {
|
||||
|
||||
r1, err := ss.Team().Get(o1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, r1.ToJson(), o1.ToJson())
|
||||
require.Equal(t, r1, &o1)
|
||||
|
||||
_, err = ss.Team().Get("")
|
||||
require.Error(t, err, "Missing id should have failed")
|
||||
|
||||
Ссылка в новой задаче
Block a user