mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-01 15:00:08 +08:00
[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>
This commit is contained in:
+1
-1
@@ -911,7 +911,7 @@ func CheckEtag(t *testing.T, data interface{}, resp *model.Response) {
|
||||
t.Helper()
|
||||
|
||||
require.Empty(t, data)
|
||||
require.Equal(t, resp.StatusCode, http.StatusNotModified, "wrong status code for etag")
|
||||
require.Equal(t, http.StatusNotModified, resp.StatusCode, "wrong status code for etag")
|
||||
}
|
||||
|
||||
func checkHTTPStatus(t *testing.T, resp *model.Response, expectedStatus int) {
|
||||
|
||||
+4
-3
@@ -279,8 +279,9 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userPatch := model.UserPatchFromJson(r.Body)
|
||||
if userPatch == nil || userPatch.Password == nil || *userPatch.Password == "" {
|
||||
var userPatch model.UserPatch
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&userPatch)
|
||||
if jsonErr != nil || userPatch.Password == nil || *userPatch.Password == "" {
|
||||
c.SetInvalidParam("userPatch")
|
||||
return
|
||||
}
|
||||
@@ -298,7 +299,7 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.ConvertBotToUser(bot, userPatch, systemAdmin)
|
||||
user, err := c.App.ConvertBotToUser(bot, &userPatch, systemAdmin)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+19
-18
@@ -233,7 +233,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
privacy, ok := props["privacy"].(string)
|
||||
if !ok || (model.ChannelType(privacy) != model.ChannelTypeOpen && model.ChannelType(privacy) != model.ChannelTypePrivate) {
|
||||
c.SetInvalidParam("privacy")
|
||||
@@ -395,7 +395,7 @@ func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
allowed := false
|
||||
|
||||
if len(userIds) != 2 {
|
||||
@@ -479,7 +479,7 @@ func searchGroupChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
@@ -816,7 +816,7 @@ func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
channelIds := model.ArrayFromJson(r.Body)
|
||||
channelIds := model.ArrayFromJSON(r.Body)
|
||||
if len(channelIds) == 0 {
|
||||
c.SetInvalidParam("channel_ids")
|
||||
return
|
||||
@@ -1244,7 +1244,7 @@ func getChannelMembersTimezones(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ArrayToJson(membersTimezones)))
|
||||
w.Write([]byte(model.ArrayToJSON(membersTimezones)))
|
||||
}
|
||||
|
||||
func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1253,7 +1253,7 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
return
|
||||
@@ -1335,8 +1335,8 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
view := model.ChannelViewFromJson(r.Body)
|
||||
if view == nil {
|
||||
var view model.ChannelView
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&view); jsonErr != nil {
|
||||
c.SetInvalidParam("channel_view")
|
||||
return
|
||||
}
|
||||
@@ -1352,7 +1352,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
times, err := c.App.ViewChannel(view, c.Params.UserId, c.AppContext.Session().Id, view.CollapsedThreadsSupported)
|
||||
times, err := c.App.ViewChannel(&view, c.Params.UserId, c.AppContext.Session().Id, view.CollapsedThreadsSupported)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1378,7 +1378,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
newRoles := props["roles"]
|
||||
if !(model.IsValidUserRoles(newRoles)) {
|
||||
@@ -1412,8 +1412,8 @@ func updateChannelMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
schemeRoles := model.SchemeRolesFromJson(r.Body)
|
||||
if schemeRoles == nil {
|
||||
var schemeRoles model.SchemeRoles
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&schemeRoles); jsonErr != nil {
|
||||
c.SetInvalidParam("scheme_roles")
|
||||
return
|
||||
}
|
||||
@@ -1444,7 +1444,7 @@ func updateChannelMemberNotifyProps(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
if props == nil {
|
||||
c.SetInvalidParam("notify_props")
|
||||
return
|
||||
@@ -1477,7 +1477,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
userId, ok := props["user_id"].(string)
|
||||
if !ok || !model.IsValidId(userId) {
|
||||
c.SetInvalidParam("user_id")
|
||||
@@ -1663,15 +1663,16 @@ func updateChannelScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
schemeID := model.SchemeIDFromJson(r.Body)
|
||||
if schemeID == nil || !model.IsValidId(*schemeID) {
|
||||
var p model.SchemeIDPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&p); jsonErr != nil || p.SchemeID == nil || !model.IsValidId(*p.SchemeID) {
|
||||
c.SetInvalidParam("scheme_id")
|
||||
return
|
||||
}
|
||||
schemeID := p.SchemeID
|
||||
|
||||
auditRec := c.MakeAuditRecord("updateChannelScheme", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("new_scheme_id", schemeID)
|
||||
auditRec.AddMeta("new_scheme_id", *schemeID)
|
||||
|
||||
if c.App.Srv().License() == nil {
|
||||
c.Err = model.NewAppError("Api4.UpdateChannelScheme", "api.channel.update_channel_scheme.license.error", nil, "", http.StatusNotImplemented)
|
||||
@@ -1898,7 +1899,7 @@ func moveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
teamId, ok := props["team_id"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("team_id")
|
||||
|
||||
@@ -29,7 +29,13 @@ func getCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(categories.ToJson())
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getCategoriesForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(categoriesJSON)
|
||||
}
|
||||
|
||||
func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -64,8 +70,15 @@ func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
categoryJSON, jsonErr := json.Marshal(category)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
w.Write(category.ToJson())
|
||||
|
||||
w.Write(categoryJSON)
|
||||
}
|
||||
|
||||
func getCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -85,7 +98,7 @@ func getCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ArrayToJson(order)))
|
||||
w.Write([]byte(model.ArrayToJSON(order)))
|
||||
}
|
||||
|
||||
func updateCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -102,7 +115,7 @@ func updateCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *htt
|
||||
auditRec := c.MakeAuditRecord("updateCategoryOrderForTeamForUser", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
categoryOrder := model.ArrayFromJson(r.Body)
|
||||
categoryOrder := model.ArrayFromJSON(r.Body)
|
||||
|
||||
for _, categoryId := range categoryOrder {
|
||||
if !c.App.SessionHasPermissionToCategory(*c.AppContext.Session(), c.Params.UserId, c.Params.TeamId, categoryId) {
|
||||
@@ -118,7 +131,7 @@ func updateCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
w.Write([]byte(model.ArrayToJson(categoryOrder)))
|
||||
w.Write([]byte(model.ArrayToJSON(categoryOrder)))
|
||||
}
|
||||
|
||||
func getCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -138,7 +151,13 @@ func getCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(categories.ToJson())
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(categoriesJSON)
|
||||
}
|
||||
|
||||
func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -180,8 +199,14 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateCategoriesForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
w.Write(model.SidebarCategoriesWithChannelsToJson(categories))
|
||||
w.Write(categoriesJSON)
|
||||
}
|
||||
|
||||
func validateSidebarCategory(c *Context, teamId, userId string, category *model.SidebarCategoryWithChannels) *model.AppError {
|
||||
@@ -264,8 +289,14 @@ func updateCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
categoryJSON, jsonErr := json.Marshal(categories[0])
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
w.Write(categories[0].ToJson())
|
||||
w.Write(categoryJSON)
|
||||
}
|
||||
|
||||
func deleteCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -71,7 +71,7 @@ func localUpdateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
privacy, ok := props["privacy"].(string)
|
||||
if !ok || (model.ChannelType(privacy) != model.ChannelTypeOpen && model.ChannelType(privacy) != model.ChannelTypePrivate) {
|
||||
c.SetInvalidParam("privacy")
|
||||
@@ -145,7 +145,7 @@ func localAddChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
userId, ok := props["user_id"].(string)
|
||||
if !ok || !model.IsValidId(userId) {
|
||||
c.SetInvalidParam("user_id")
|
||||
@@ -326,7 +326,7 @@ func localMoveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
teamId, ok := props["team_id"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("team_id")
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -3071,7 +3072,8 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
post := model.PostFromJson(strings.NewReader(postData.(string)))
|
||||
var post model.Post
|
||||
json.Unmarshal([]byte(postData.(string)), &post)
|
||||
if post.ChannelId == expectedPost.ChannelId && post.Message == expectedPost.Message {
|
||||
return
|
||||
}
|
||||
|
||||
+7
-1
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
@@ -25,5 +26,10 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
infos := c.App.GetClusterStatus()
|
||||
w.Write([]byte(model.ClusterInfosToJson(infos)))
|
||||
js, jsonErr := json.Marshal(infos)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getClusterStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
+18
-13
@@ -30,8 +30,8 @@ func (api *API) InitCommand() {
|
||||
}
|
||||
|
||||
func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cmd := model.CommandFromJson(r.Body)
|
||||
if cmd == nil {
|
||||
var cmd model.Command
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil {
|
||||
c.SetInvalidParam("command")
|
||||
return
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
cmd.CreatorId = c.AppContext.Session().UserId
|
||||
|
||||
rcmd, err := c.App.CreateCommand(cmd)
|
||||
rcmd, err := c.App.CreateCommand(&cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -69,8 +69,8 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cmd := model.CommandFromJson(r.Body)
|
||||
if cmd == nil || cmd.Id != c.Params.CommandId {
|
||||
var cmd model.Command
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil || cmd.Id != c.Params.CommandId {
|
||||
c.SetInvalidParam("command")
|
||||
return
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rcmd, err := c.App.UpdateCommand(oldCmd, cmd)
|
||||
rcmd, err := c.App.UpdateCommand(oldCmd, &cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -126,8 +126,8 @@ func moveCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cmr, err := model.CommandMoveRequestFromJson(r.Body)
|
||||
if err != nil {
|
||||
var cmr model.CommandMoveRequest
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&cmr); jsonErr != nil {
|
||||
c.SetInvalidParam("team_id")
|
||||
return
|
||||
}
|
||||
@@ -298,8 +298,8 @@ func getCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
commandArgs := model.CommandArgsFromJson(r.Body)
|
||||
if commandArgs == nil {
|
||||
var commandArgs model.CommandArgs
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&commandArgs); jsonErr != nil {
|
||||
c.SetInvalidParam("command_args")
|
||||
return
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.AddMeta("commandargs", commandArgs) // overwrite in case teamid changed
|
||||
|
||||
response, err := c.App.ExecuteCommand(c.AppContext, commandArgs)
|
||||
response, err := c.App.ExecuteCommand(c.AppContext, &commandArgs)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -423,7 +423,12 @@ func listCommandAutocompleteSuggestions(c *Context, w http.ResponseWriter, r *ht
|
||||
|
||||
suggestions := c.App.GetSuggestions(c.AppContext, commandArgs, commands, roleId)
|
||||
|
||||
w.Write(model.AutocompleteSuggestionsToJSON(suggestions))
|
||||
js, jsonErr := json.Marshal(suggestions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("listCommandAutocompleteSuggestions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -470,5 +475,5 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
resp := make(map[string]string)
|
||||
resp["token"] = rcmd.Token
|
||||
|
||||
w.Write([]byte(model.MapToJson(resp)))
|
||||
w.Write([]byte(model.MapToJSON(resp)))
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func (api *API) InitCommandLocal() {
|
||||
}
|
||||
|
||||
func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cmd := model.CommandFromJson(r.Body)
|
||||
if cmd == nil {
|
||||
var cmd model.Command
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil {
|
||||
c.SetInvalidParam("command")
|
||||
return
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
rcmd, err := c.App.CreateCommand(cmd)
|
||||
rcmd, err := c.App.CreateCommand(&cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ func (api *API) InitCompliance() {
|
||||
}
|
||||
|
||||
func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
job := model.ComplianceFromJson(r.Body)
|
||||
if job == nil {
|
||||
var job model.Compliance
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&job); jsonErr != nil {
|
||||
c.SetInvalidParam("compliance")
|
||||
return
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
job.UserId = c.AppContext.Session().UserId
|
||||
|
||||
rjob, err := c.App.SaveComplianceReport(job)
|
||||
rjob, err := c.App.SaveComplianceReport(&job)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+25
-10
@@ -69,7 +69,12 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
return
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
@@ -103,7 +108,7 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
return
|
||||
@@ -170,7 +175,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
},
|
||||
})
|
||||
if mergeErr != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.config.update_config.restricted_merge.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.restricted_merge.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
@@ -178,7 +183,12 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -207,7 +217,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
config = c.App.ClientConfigWithComputed()
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJson(config)))
|
||||
w.Write([]byte(model.MapToJSON(config)))
|
||||
}
|
||||
|
||||
func getEnvironmentConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -218,11 +228,11 @@ func getEnvironmentConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(model.StringInterfaceToJson(envConfig)))
|
||||
w.Write([]byte(model.StringInterfaceToJSON(envConfig)))
|
||||
}
|
||||
|
||||
func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
return
|
||||
@@ -294,12 +304,17 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
},
|
||||
})
|
||||
if mergeErr != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.config.patch_config.restricted_merge.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.restricted_merge.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -372,7 +387,7 @@ func makeFilterConfigByPermission(accessType filterType) func(c *Context, struct
|
||||
}
|
||||
|
||||
func migrateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
from, ok := props["from"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("from")
|
||||
|
||||
@@ -35,7 +35,7 @@ func localGetConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
return
|
||||
@@ -87,7 +87,7 @@ func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localPatchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
return
|
||||
|
||||
+67
-20
@@ -40,7 +40,12 @@ func getGlobalPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(policy.ToJson())
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getGlobalPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getPolicies(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -58,7 +63,12 @@ func getPolicies(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(policies.ToJson())
|
||||
js, jsonErr := json.Marshal(policies)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getPolicies", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getPoliciesCount(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -89,12 +99,18 @@ func getPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
w.Write(policy.ToJson())
|
||||
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func createPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
policy, jsonErr := model.RetentionPolicyWithTeamAndChannelIdsFromJson(r.Body)
|
||||
if jsonErr != nil {
|
||||
var policy model.RetentionPolicyWithTeamAndChannelIDs
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&policy); jsonErr != nil {
|
||||
c.SetInvalidParam("policy")
|
||||
return
|
||||
}
|
||||
@@ -107,22 +123,28 @@ func createPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
newPolicy, err := c.App.CreateRetentionPolicy(policy)
|
||||
newPolicy, err := c.App.CreateRetentionPolicy(&policy)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddMeta("policy", newPolicy) // overwrite meta
|
||||
js, jsonErr := json.Marshal(newPolicy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
w.Write(newPolicy.ToJson())
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func patchPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
patch, jsonErr := model.RetentionPolicyWithTeamAndChannelIdsFromJson(r.Body)
|
||||
if jsonErr != nil {
|
||||
var patch model.RetentionPolicyWithTeamAndChannelIDs
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
|
||||
c.SetInvalidParam("policy")
|
||||
return
|
||||
}
|
||||
c.RequirePolicyId()
|
||||
patch.ID = c.Params.PolicyId
|
||||
@@ -136,13 +158,18 @@ func patchPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
policy, err := c.App.PatchRetentionPolicy(patch)
|
||||
policy, err := c.App.PatchRetentionPolicy(&patch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("patchPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
w.Write(policy.ToJson())
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func deletePolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -199,23 +226,28 @@ func searchTeamsInPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.TeamSearchFromJson(r.Body)
|
||||
if props == nil {
|
||||
var props model.TeamSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParam("team_search")
|
||||
return
|
||||
}
|
||||
|
||||
props.PolicyID = model.NewString(c.Params.PolicyId)
|
||||
props.IncludePolicyID = model.NewBool(true)
|
||||
|
||||
teams, _, err := c.App.SearchAllTeams(props)
|
||||
teams, _, err := c.App.SearchAllTeams(&props)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
|
||||
payload := []byte(model.TeamListToJson(teams))
|
||||
w.Write(payload)
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchTeamsInPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func addTeamsToPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -330,8 +362,13 @@ func searchChannelsInPolicy(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
payload := []byte(channels.ToJson())
|
||||
w.Write(payload)
|
||||
channelsJSON, jsonErr := json.Marshal(channels)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchChannelsInPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(channelsJSON)
|
||||
}
|
||||
|
||||
func addChannelsToPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -412,7 +449,12 @@ func getTeamPoliciesForUser(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(policies.ToJson())
|
||||
js, jsonErr := json.Marshal(policies)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamPoliciesForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getChannelPoliciesForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -435,5 +477,10 @@ func getChannelPoliciesForUser(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(policies.ToJson())
|
||||
js, jsonErr := json.Marshal(policies)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getChannelPoliciesForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (api *API) InitElasticsearch() {
|
||||
}
|
||||
|
||||
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
+5
-6
@@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
"github.com/mattermost/mattermost-server/v6/audit"
|
||||
@@ -83,15 +82,15 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
emoji := model.EmojiFromJson(strings.NewReader(props["emoji"][0]))
|
||||
if emoji == nil {
|
||||
var emoji model.Emoji
|
||||
if jsonErr := json.Unmarshal([]byte(props["emoji"][0]), &emoji); jsonErr != nil {
|
||||
c.SetInvalidParam("emoji")
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddMeta("emoji", emoji)
|
||||
|
||||
newEmoji, err := c.App.CreateEmoji(c.AppContext.Session().UserId, emoji, m)
|
||||
newEmoji, err := c.App.CreateEmoji(c.AppContext.Session().UserId, &emoji, m)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -255,8 +254,8 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func searchEmojis(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
emojiSearch := model.EmojiSearchFromJson(r.Body)
|
||||
if emojiSearch == nil {
|
||||
var emojiSearch model.EmojiSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&emojiSearch); jsonErr != nil {
|
||||
c.SetInvalidParam("term")
|
||||
return
|
||||
}
|
||||
|
||||
+3
-2
@@ -575,7 +575,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("link", link)
|
||||
|
||||
w.Write([]byte(model.MapToJson(resp)))
|
||||
w.Write([]byte(model.MapToJSON(resp)))
|
||||
}
|
||||
|
||||
func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -745,7 +745,8 @@ func searchFiles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
params, jsonErr := model.SearchParameterFromJson(r.Body)
|
||||
var params model.SearchParameter
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(¶ms)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchFiles", "api.post.search_files.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
+7
-2
@@ -6,6 +6,7 @@ package api4
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -77,10 +78,14 @@ func testDoUploadFileRequest(t testing.TB, c *model.Client4, url string, blob []
|
||||
defer closeBody(resp)
|
||||
|
||||
if resp.StatusCode >= 300 {
|
||||
return nil, model.BuildResponse(resp), model.AppErrorFromJson(resp.Body)
|
||||
return nil, model.BuildResponse(resp), model.AppErrorFromJSON(resp.Body)
|
||||
}
|
||||
|
||||
return model.FileUploadResponseFromJson(resp.Body), model.BuildResponse(resp), nil
|
||||
var res model.FileUploadResponse
|
||||
if jsonErr := json.NewDecoder(resp.Body).Decode(&res); jsonErr != nil {
|
||||
return nil, nil, model.NewAppError("doUploadFile", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return &res, model.BuildResponse(resp), nil
|
||||
}
|
||||
|
||||
func testUploadFilesPost(
|
||||
|
||||
+3
-3
@@ -114,8 +114,8 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
groupPatch := model.GroupPatchFromJson(r.Body)
|
||||
if groupPatch == nil {
|
||||
var groupPatch model.GroupPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&groupPatch); jsonErr != nil {
|
||||
c.SetInvalidParam("group")
|
||||
return
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
group.Patch(groupPatch)
|
||||
group.Patch(&groupPatch)
|
||||
|
||||
group, err = c.App.UpdateGroup(group)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,10 +23,8 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
actionRequest := model.DoPostActionRequestFromJson(r.Body)
|
||||
if actionRequest == nil {
|
||||
actionRequest = &model.DoPostActionRequest{}
|
||||
}
|
||||
var actionRequest model.DoPostActionRequest
|
||||
json.NewDecoder(r.Body).Decode(&actionRequest)
|
||||
|
||||
var cookie *model.PostActionCookie
|
||||
if actionRequest.Cookie != "" {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -25,7 +24,9 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
bb, err := ioutil.ReadAll(r.Body)
|
||||
assert.NoError(th.t, err)
|
||||
assert.NotEmpty(th.t, string(bb))
|
||||
poir := model.PostActionIntegrationRequestFromJson(bytes.NewReader(bb))
|
||||
var poir model.PostActionIntegrationRequest
|
||||
jsonErr := json.Unmarshal(bb, &poir)
|
||||
assert.NoError(th.t, jsonErr)
|
||||
assert.NotEmpty(th.t, poir.UserId)
|
||||
assert.NotEmpty(th.t, poir.UserName)
|
||||
assert.NotEmpty(th.t, poir.ChannelId)
|
||||
|
||||
+18
-8
@@ -104,8 +104,8 @@ func downloadJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
job := model.JobFromJson(r.Body)
|
||||
if job == nil {
|
||||
var job model.Job
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&job); jsonErr != nil {
|
||||
c.SetInvalidParam("job")
|
||||
return
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("job", job)
|
||||
|
||||
hasPermission, permissionRequired := c.App.SessionHasPermissionToCreateJob(*c.AppContext.Session(), job)
|
||||
hasPermission, permissionRequired := c.App.SessionHasPermissionToCreateJob(*c.AppContext.Session(), &job)
|
||||
if permissionRequired == nil {
|
||||
c.Err = model.NewAppError("unableToCreateJob", "api.job.unable_to_create_job.incorrect_job_type", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
@@ -125,17 +125,17 @@ func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
job, err := c.App.CreateJob(job)
|
||||
rjob, err := c.App.CreateJob(&job)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("job", job) // overwrite meta
|
||||
auditRec.AddMeta("job", rjob) // overwrite meta
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
if err := json.NewEncoder(w).Encode(job); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(rjob); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,12 @@ func getJobs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.JobsToJson(jobs)))
|
||||
js, jsonErr := json.Marshal(jobs)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getJobs", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -192,7 +197,12 @@ func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.JobsToJson(jobs)))
|
||||
js, jsonErr := json.Marshal(jobs)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getJobsByType", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func cancelJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ func unlinkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func migrateIdLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
toAttribute, ok := props["toAttribute"].(string)
|
||||
if !ok || toAttribute == "" {
|
||||
c.SetInvalidParam("toAttribute")
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
clientLicense = c.App.Srv().GetSanitizedClientLicense()
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJson(clientLicense)))
|
||||
w.Write([]byte(model.MapToJSON(clientLicense)))
|
||||
}
|
||||
|
||||
func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -302,5 +302,5 @@ func getPrevTrialLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
clientLicense = utils.GetSanitizedClientLicense(utils.GetClientLicense(license))
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJson(clientLicense)))
|
||||
w.Write([]byte(model.MapToJSON(clientLicense)))
|
||||
}
|
||||
|
||||
@@ -224,11 +224,12 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
nUsers := 1
|
||||
license := model.NewTestLicense()
|
||||
license.Features.Users = model.NewInt(nUsers)
|
||||
licenseStr := license.ToJson()
|
||||
licenseJSON, jsonErr := json.Marshal(license)
|
||||
require.NoError(t, jsonErr)
|
||||
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
res.WriteHeader(http.StatusOK)
|
||||
response := map[string]string{
|
||||
"license": licenseStr,
|
||||
"license": string(licenseJSON),
|
||||
}
|
||||
err := json.NewEncoder(res).Encode(response)
|
||||
require.NoError(t, err)
|
||||
@@ -238,7 +239,7 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
mockLicenseValidator := mocks2.LicenseValidatorIface{}
|
||||
defer testutils.ResetLicenseValidator()
|
||||
|
||||
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, licenseStr)
|
||||
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, string(licenseJSON))
|
||||
utils.LicenseValidator = &mockLicenseValidator
|
||||
licenseManagerMock := &mocks.LicenseInterface{}
|
||||
licenseManagerMock.On("CanStartTrial").Return(true, nil).Once()
|
||||
|
||||
+18
-9
@@ -25,9 +25,8 @@ func (api *API) InitOAuth() {
|
||||
}
|
||||
|
||||
func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oauthApp := model.OAuthAppFromJson(r.Body)
|
||||
|
||||
if oauthApp == nil {
|
||||
var oauthApp model.OAuthApp
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&oauthApp); jsonErr != nil {
|
||||
c.SetInvalidParam("oauth_app")
|
||||
return
|
||||
}
|
||||
@@ -46,7 +45,7 @@ func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
oauthApp.CreatorId = c.AppContext.Session().UserId
|
||||
|
||||
rapp, err := c.App.CreateOAuthApp(oauthApp)
|
||||
rapp, err := c.App.CreateOAuthApp(&oauthApp)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -78,8 +77,8 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oauthApp := model.OAuthAppFromJson(r.Body)
|
||||
if oauthApp == nil {
|
||||
var oauthApp model.OAuthApp
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&oauthApp); jsonErr != nil {
|
||||
c.SetInvalidParam("oauth_app")
|
||||
return
|
||||
}
|
||||
@@ -106,7 +105,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oauthApp.IsTrusted = oldOAuthApp.IsTrusted
|
||||
}
|
||||
|
||||
updatedOAuthApp, err := c.App.UpdateOAuthApp(oldOAuthApp, oauthApp)
|
||||
updatedOAuthApp, err := c.App.UpdateOAuthApp(oldOAuthApp, &oauthApp)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -143,7 +142,12 @@ func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.OAuthAppListToJson(apps)))
|
||||
js, jsonErr := json.Marshal(apps)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getOAuthApps", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -289,5 +293,10 @@ func getAuthorizedOAuthApps(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.OAuthAppListToJson(apps)))
|
||||
js, jsonErr := json.Marshal(apps)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAuthorizedOAuthApps", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
|
||||
url := ""
|
||||
ok := false
|
||||
|
||||
+6
-1
@@ -264,7 +264,12 @@ func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ManifestListToJson(clientManifests)))
|
||||
js, jsonErr := json.Marshal(clientManifests)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getWebappPlugins", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getMarketplacePlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
+19
-16
@@ -36,8 +36,8 @@ func (api *API) InitPost() {
|
||||
}
|
||||
|
||||
func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
post := model.PostFromJson(r.Body)
|
||||
if post == nil {
|
||||
var post model.Post
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
|
||||
c.SetInvalidParam("post")
|
||||
return
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := c.MakeAuditRecord("createPost", audit.Fail)
|
||||
defer c.LogAuditRecWithLevel(auditRec, app.LevelContent)
|
||||
auditRec.AddMeta("post", post)
|
||||
auditRec.AddMeta("post", &post)
|
||||
|
||||
hasPermission := false
|
||||
if c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), post.ChannelId, model.PermissionCreatePost) {
|
||||
@@ -78,7 +78,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
rp, err := c.App.CreatePostAsUser(c.AppContext, c.App.PostWithProxyRemovedFromImageURLs(post), c.AppContext.Session().Id, setOnlineBool)
|
||||
rp, err := c.App.CreatePostAsUser(c.AppContext, c.App.PostWithProxyRemovedFromImageURLs(&post), c.AppContext.Session().Id, setOnlineBool)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -484,8 +484,8 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
params, jsonErr := model.SearchParameterFromJson(r.Body)
|
||||
if jsonErr != nil {
|
||||
var params model.SearchParameter
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(¶ms); jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchPosts", "api.post.search_posts.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -558,9 +558,8 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
post := model.PostFromJson(r.Body)
|
||||
|
||||
if post == nil {
|
||||
var post model.Post
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
|
||||
c.SetInvalidParam("post")
|
||||
return
|
||||
}
|
||||
@@ -598,7 +597,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
post.Id = c.Params.PostId
|
||||
|
||||
rpost, err := c.App.UpdatePost(c.AppContext, c.App.PostWithProxyRemovedFromImageURLs(post), false)
|
||||
rpost, err := c.App.UpdatePost(c.AppContext, c.App.PostWithProxyRemovedFromImageURLs(&post), false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -618,9 +617,8 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
post := model.PostPatchFromJson(r.Body)
|
||||
|
||||
if post == nil {
|
||||
var post model.PostPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
|
||||
c.SetInvalidParam("post")
|
||||
return
|
||||
}
|
||||
@@ -650,7 +648,7 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
patchedPost, err := c.App.PatchPost(c.AppContext, c.Params.PostId, c.App.PostPatchWithProxyRemovedFromImageURLs(post))
|
||||
patchedPost, err := c.App.PatchPost(c.AppContext, c.Params.PostId, c.App.PostPatchWithProxyRemovedFromImageURLs(&post))
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -670,7 +668,7 @@ func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapBoolFromJson(r.Body)
|
||||
props := model.MapBoolFromJSON(r.Body)
|
||||
collapsedThreadsSupported := props["collapsed_threads_supported"]
|
||||
|
||||
if c.AppContext.Session().UserId != c.Params.UserId && !c.App.SessionHasPermissionToUser(*c.AppContext.Session(), c.Params.UserId) {
|
||||
@@ -777,7 +775,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(infos)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getFileInfosForPost", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "max-age=2592000, private")
|
||||
w.Header().Set(model.HeaderEtagServer, model.GetEtagForFileInfos(infos))
|
||||
w.Write([]byte(model.FileInfosToJson(infos)))
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
+15
-5
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -341,7 +342,9 @@ func testCreatePostWithOutgoingHook(
|
||||
ResponseType: respPostType,
|
||||
}
|
||||
|
||||
fmt.Fprint(w, outGoingHookResponse.ToJson())
|
||||
hookJSON, jsonErr := json.Marshal(outGoingHookResponse)
|
||||
require.NoError(t, jsonErr)
|
||||
w.Write(hookJSON)
|
||||
success <- true
|
||||
}))
|
||||
defer ts.Close()
|
||||
@@ -578,7 +581,9 @@ func TestCreatePostSendOutOfChannelMentions(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
wpost := model.PostFromJson(strings.NewReader(event.GetData()["post"].(string)))
|
||||
var wpost model.Post
|
||||
err := json.Unmarshal([]byte(event.GetData()["post"].(string)), &wpost)
|
||||
require.NoError(t, err)
|
||||
|
||||
acm, ok := wpost.GetProp(model.PropsAddChannelMember).(map[string]interface{})
|
||||
require.True(t, ok, "should have received ephemeral post with 'add_channel_member' in props")
|
||||
@@ -634,7 +639,9 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
||||
Message: "some message",
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("POST", "/api/v4/posts?set_online=false", strings.NewReader(post.ToJson()))
|
||||
postJSON, jsonErr := json.Marshal(post)
|
||||
require.NoError(t, jsonErr)
|
||||
req := httptest.NewRequest("POST", "/api/v4/posts?set_online=false", bytes.NewReader(postJSON))
|
||||
req.Header.Set(model.HeaderAuth, "Bearer "+session.Token)
|
||||
|
||||
handler.ServeHTTP(resp, req)
|
||||
@@ -645,7 +652,9 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) {
|
||||
require.NotNil(t, appErr)
|
||||
assert.Equal(t, "app.status.get.missing.app_error", appErr.Id)
|
||||
|
||||
req = httptest.NewRequest("POST", "/api/v4/posts", strings.NewReader(post.ToJson()))
|
||||
postJSON, jsonErr = json.Marshal(post)
|
||||
require.NoError(t, jsonErr)
|
||||
req = httptest.NewRequest("POST", "/api/v4/posts", bytes.NewReader(postJSON))
|
||||
req.Header.Set(model.HeaderAuth, "Bearer "+session.Token)
|
||||
|
||||
handler.ServeHTTP(resp, req)
|
||||
@@ -1945,7 +1954,8 @@ func TestGetPost(t *testing.T) {
|
||||
|
||||
require.Equal(t, th.BasicPost.Id, post.Id, "post ids don't match")
|
||||
|
||||
post, resp, _ = c.GetPost(th.BasicPost.Id, resp.Etag)
|
||||
post, resp, err = c.GetPost(th.BasicPost.Id, resp.Etag)
|
||||
require.NoError(t, err)
|
||||
CheckEtag(t, post, resp)
|
||||
|
||||
_, resp, err = c.GetPost("", "")
|
||||
|
||||
+4
-4
@@ -100,8 +100,8 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
preferences, err := model.PreferencesFromJson(r.Body)
|
||||
if err != nil {
|
||||
var preferences model.Preferences
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&preferences); jsonErr != nil {
|
||||
c.SetInvalidParam("preferences")
|
||||
return
|
||||
}
|
||||
@@ -148,8 +148,8 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
preferences, err := model.PreferencesFromJson(r.Body)
|
||||
if err != nil {
|
||||
var preferences model.Preferences
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&preferences); jsonErr != nil {
|
||||
c.SetInvalidParam("preferences")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -297,8 +297,9 @@ func TestUpdatePreferencesWebsocket(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
received, err := model.PreferencesFromJson(strings.NewReader(event.GetData()["preferences"].(string)))
|
||||
require.NoError(t, err)
|
||||
var received model.Preferences
|
||||
jsonErr := json.Unmarshal([]byte(event.GetData()["preferences"].(string)), &received)
|
||||
require.NoError(t, jsonErr)
|
||||
|
||||
for i, p := range preferences {
|
||||
require.Equal(t, received[i].UserId, p.UserId, "received incorrect UserId")
|
||||
@@ -629,8 +630,9 @@ func TestDeletePreferencesWebsocket(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
received, err := model.PreferencesFromJson(strings.NewReader(event.GetData()["preferences"].(string)))
|
||||
require.NoError(t, err)
|
||||
var received model.Preferences
|
||||
jsonErr := json.Unmarshal([]byte(event.GetData()["preferences"].(string)), &received)
|
||||
require.NoError(t, jsonErr)
|
||||
|
||||
for i, preference := range preferences {
|
||||
require.Equal(t, preference.UserId, received[i].UserId)
|
||||
|
||||
+17
-7
@@ -19,8 +19,8 @@ func (api *API) InitReaction() {
|
||||
}
|
||||
|
||||
func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
reaction := model.ReactionFromJson(r.Body)
|
||||
if reaction == nil {
|
||||
var reaction model.Reaction
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&reaction); jsonErr != nil {
|
||||
c.SetInvalidParam("reaction")
|
||||
return
|
||||
}
|
||||
@@ -40,13 +40,13 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
reaction, err := c.App.SaveReactionForPost(c.AppContext, reaction)
|
||||
re, err := c.App.SaveReactionForPost(c.AppContext, &reaction)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(reaction); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(re); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,12 @@ func getReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ReactionsToJson(reactions)))
|
||||
js, jsonErr := json.Marshal(reactions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getReactions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -113,7 +118,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getBulkReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
postIds := model.ArrayFromJson(r.Body)
|
||||
postIds := model.ArrayFromJSON(r.Body)
|
||||
for _, postId := range postIds {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.AppContext.Session(), postId, model.PermissionReadChannel) {
|
||||
c.SetPermissionError(model.PermissionReadChannel)
|
||||
@@ -126,5 +131,10 @@ func getBulkReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapPostIdToReactionsToJson(reactions)))
|
||||
js, jsonErr := json.Marshal(reactions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getBulkReactions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
+18
-18
@@ -31,13 +31,13 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
frame, appErr := model.RemoteClusterFrameFromJSON(r.Body)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
var frame model.RemoteClusterFrame
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterPing", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if appErr = frame.IsValid(); appErr != nil {
|
||||
if appErr := frame.IsValid(); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
@@ -54,8 +54,8 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ping, err := model.RemoteClusterPingFromRawJSON(frame.Msg.Payload)
|
||||
if err != nil {
|
||||
var ping model.RemoteClusterPing
|
||||
if jsonErr := json.Unmarshal(frame.Msg.Payload, &ping); jsonErr != nil {
|
||||
c.SetInvalidParam("msg.payload")
|
||||
return
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
metrics.IncrementRemoteClusterMsgReceivedCounter(rc.RemoteId)
|
||||
}
|
||||
|
||||
resp, _ := json.Marshal(ping)
|
||||
resp, _ := json.Marshal(&ping)
|
||||
w.Write(resp)
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
frame, appErr := model.RemoteClusterFrameFromJSON(r.Body)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
var frame model.RemoteClusterFrame
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if appErr = frame.IsValid(); appErr != nil {
|
||||
if appErr := frame.IsValid(); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
@@ -122,13 +122,13 @@ func remoteClusterConfirmInvite(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
frame, appErr := model.RemoteClusterFrameFromJSON(r.Body)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
var frame model.RemoteClusterFrame
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterConfirmInvite", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if appErr = frame.IsValid(); appErr != nil {
|
||||
if appErr := frame.IsValid(); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
@@ -154,9 +154,9 @@ func remoteClusterConfirmInvite(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
confirm, appErr := model.RemoteClusterInviteFromRawJSON(frame.Msg.Payload)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
var confirm model.RemoteClusterInvite
|
||||
if jsonErr := json.Unmarshal(frame.Msg.Payload, &confirm); jsonErr != nil {
|
||||
c.SetInvalidParam("msg.payload")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+11
-6
@@ -60,7 +60,7 @@ func getRoleByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getRolesByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
rolenames := model.ArrayFromJson(r.Body)
|
||||
rolenames := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(rolenames) == 0 {
|
||||
c.SetInvalidParam("rolenames")
|
||||
@@ -79,7 +79,12 @@ func getRolesByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.RoleListToJson(roles)))
|
||||
js, jsonErr := json.Marshal(roles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getRolesByNames", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -88,8 +93,8 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
patch := model.RolePatchFromJson(r.Body)
|
||||
if patch == nil {
|
||||
var patch model.RolePatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
}
|
||||
@@ -127,7 +132,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Licensed instances can not change permissions in the blacklist set.
|
||||
if patch.Permissions != nil {
|
||||
deltaPermissions := model.PermissionsChangedByPatch(oldRole, patch)
|
||||
deltaPermissions := model.PermissionsChangedByPatch(oldRole, &patch)
|
||||
|
||||
for _, permission := range deltaPermissions {
|
||||
notAllowed := false
|
||||
@@ -163,7 +168,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
role, err := c.App.PatchRole(oldRole, patch)
|
||||
role, err := c.App.PatchRole(oldRole, &patch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+1
-1
@@ -242,7 +242,7 @@ func getSamlMetadataFromIdp(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
url := props["saml_metadata_url"]
|
||||
if url == "" {
|
||||
c.SetInvalidParam("saml_metadata_url")
|
||||
|
||||
+20
-10
@@ -23,8 +23,8 @@ func (api *API) InitScheme() {
|
||||
}
|
||||
|
||||
func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
scheme := model.SchemeFromJson(r.Body)
|
||||
if scheme == nil {
|
||||
var scheme model.Scheme
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&scheme); jsonErr != nil {
|
||||
c.SetInvalidParam("scheme")
|
||||
return
|
||||
}
|
||||
@@ -43,17 +43,17 @@ func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
scheme, err := c.App.CreateScheme(scheme)
|
||||
returnedScheme, err := c.App.CreateScheme(&scheme)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("scheme", scheme) // overwrite meta
|
||||
auditRec.AddMeta("scheme", returnedScheme) // overwrite meta
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
if err := json.NewEncoder(w).Encode(scheme); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(returnedScheme); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,12 @@ func getSchemes(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.SchemesToJson(schemes)))
|
||||
js, jsonErr := json.Marshal(schemes)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getSchemes", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getTeamsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -129,7 +134,12 @@ func getTeamsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.TeamListToJson(teams)))
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsForScheme", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getChannelsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -171,8 +181,8 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
patch := model.SchemePatchFromJson(r.Body)
|
||||
if patch == nil {
|
||||
var patch model.SchemePatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
|
||||
c.SetInvalidParam("scheme")
|
||||
return
|
||||
}
|
||||
@@ -197,7 +207,7 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
scheme, err = c.App.PatchScheme(scheme, patch)
|
||||
scheme, err = c.App.PatchScheme(scheme, &patch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+17
-12
@@ -49,7 +49,7 @@ func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getUserStatusesByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
@@ -64,14 +64,18 @@ func getUserStatusesByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// No permission check required
|
||||
|
||||
statusMap, err := c.App.GetUserStatusesByIds(userIds)
|
||||
statuses, err := c.App.GetUserStatusesByIds(userIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.StatusListToJson(statusMap)))
|
||||
js, jsonErr := json.Marshal(statuses)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUserStatusesByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -80,8 +84,8 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
status := model.StatusFromJson(r.Body)
|
||||
if status == nil {
|
||||
var status model.Status
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&status); jsonErr != nil {
|
||||
c.SetInvalidParam("status")
|
||||
return
|
||||
}
|
||||
@@ -134,8 +138,9 @@ func updateUserCustomStatus(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
customStatus := model.CustomStatusFromJson(r.Body)
|
||||
if customStatus == nil || (customStatus.Emoji == "" && customStatus.Text == "") || !customStatus.AreDurationAndExpirationTimeValid() {
|
||||
var customStatus model.CustomStatus
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&customStatus)
|
||||
if jsonErr != nil || (customStatus.Emoji == "" && customStatus.Text == "") || !customStatus.AreDurationAndExpirationTimeValid() {
|
||||
c.SetInvalidParam("custom_status")
|
||||
return
|
||||
}
|
||||
@@ -146,7 +151,7 @@ func updateUserCustomStatus(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
customStatus.PreSave()
|
||||
err := c.App.SetCustomStatus(c.Params.UserId, customStatus)
|
||||
err := c.App.SetCustomStatus(c.Params.UserId, &customStatus)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -190,8 +195,8 @@ func removeUserRecentCustomStatus(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
recentCustomStatus := model.CustomStatusFromJson(r.Body)
|
||||
if recentCustomStatus == nil {
|
||||
var recentCustomStatus model.CustomStatus
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&recentCustomStatus); jsonErr != nil {
|
||||
c.SetInvalidParam("recent_custom_status")
|
||||
return
|
||||
}
|
||||
@@ -201,7 +206,7 @@ func removeUserRecentCustomStatus(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.RemoveRecentCustomStatus(c.Params.UserId, recentCustomStatus); err != nil {
|
||||
if err := c.App.RemoveRecentCustomStatus(c.Params.UserId, &recentCustomStatus); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
+33
-23
@@ -186,11 +186,11 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if s[model.STATUS] != model.StatusOk {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
w.Write([]byte(model.MapToJson(s)))
|
||||
w.Write([]byte(model.MapToJSON(s)))
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func testSiteURL(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
siteURL := props["site_url"]
|
||||
if siteURL == "" {
|
||||
c.SetInvalidParam("site_url")
|
||||
@@ -334,7 +334,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("page", c.Params.Page)
|
||||
auditRec.AddMeta("logs_per_page", c.Params.LogsPerPage)
|
||||
|
||||
w.Write([]byte(model.ArrayToJson(lines)))
|
||||
w.Write([]byte(model.ArrayToJSON(lines)))
|
||||
}
|
||||
|
||||
func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -351,7 +351,7 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
m := model.MapFromJson(r.Body)
|
||||
m := model.MapFromJSON(r.Body)
|
||||
lvl := m["level"]
|
||||
msg := m["message"]
|
||||
|
||||
@@ -372,7 +372,7 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
m["message"] = msg
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
}
|
||||
|
||||
func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -420,7 +420,7 @@ func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJson(r.Body)
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
@@ -459,7 +459,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m["location"] = ""
|
||||
|
||||
if !*c.App.Config().ServiceSettings.EnableLinkPreviews {
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var location string
|
||||
if err := redirectLocationDataCache.Get(url, &location); err == nil {
|
||||
m["location"] = location
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// Cache failures to prevent retries.
|
||||
redirectLocationDataCache.SetWithExpiry(url, "", 1*time.Hour)
|
||||
// Always return a success status and a JSON string to limit information returned to client.
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
@@ -498,16 +498,16 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
redirectLocationDataCache.SetWithExpiry(url, location, 1*time.Hour)
|
||||
m["location"] = location
|
||||
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
}
|
||||
|
||||
func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ack, err := model.PushNotificationAckFromJson(r.Body)
|
||||
if err != nil {
|
||||
var ack model.PushNotificationAck
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&ack); jsonErr != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck",
|
||||
"api.push_notifications_ack.message.parse.app_error",
|
||||
nil,
|
||||
err.Error(),
|
||||
jsonErr.Error(),
|
||||
http.StatusBadRequest,
|
||||
)
|
||||
return
|
||||
@@ -523,7 +523,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.SendAckToPushProxy(ack)
|
||||
err := c.App.SendAckToPushProxy(&ack)
|
||||
if ack.IsIdLoaded {
|
||||
if err != nil {
|
||||
// Log the error only, then continue to fetch notification message
|
||||
@@ -542,7 +542,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
msg, appError := notificationInterface.GetNotificationMessage(ack, c.AppContext.Session().UserId)
|
||||
msg, appError := notificationInterface.GetNotificationMessage(&ack, c.AppContext.Session().UserId)
|
||||
if appError != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.id_loaded.fetch.app_error", nil, appError.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -612,9 +612,14 @@ func getServerBusyExpires(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// We call to ToJson because it actually returns a different struct
|
||||
// We call to ToJSON because it actually returns a different struct
|
||||
// along with doing some computations.
|
||||
if _, err := w.Write([]byte(c.App.Srv().Busy.ToJson())); err != nil {
|
||||
sbsJSON, jsonErr := c.App.Srv().Busy.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn(jsonErr.Error())
|
||||
}
|
||||
|
||||
if _, err := w.Write(sbsJSON); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -700,7 +705,7 @@ func upgradeToEnterpriseStatus(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
s = map[string]interface{}{"percentage": percentage, "error": nil}
|
||||
}
|
||||
|
||||
w.Write([]byte(model.StringInterfaceToJson(s)))
|
||||
w.Write([]byte(model.StringInterfaceToJSON(s)))
|
||||
}
|
||||
|
||||
func restart(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -739,7 +744,12 @@ func getWarnMetricsStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapWarnMetricStatusToJson(status)))
|
||||
js, jsonErr := json.Marshal(status)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getWarnMetricsStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func sendWarnMetricAckEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -764,8 +774,8 @@ func sendWarnMetricAckEmail(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
ack := model.SendWarnMetricAckFromJson(r.Body)
|
||||
if ack == nil {
|
||||
var ack model.SendWarnMetricAck
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&ack); jsonErr != nil {
|
||||
c.SetInvalidParam("ack")
|
||||
return
|
||||
}
|
||||
@@ -838,7 +848,7 @@ func updateViewedProductNotices(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
defer c.LogAuditRec(auditRec)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
ids := model.ArrayFromJson(r.Body)
|
||||
ids := model.ArrayFromJSON(r.Body)
|
||||
err := c.App.UpdateViewedProductNotices(c.AppContext.Session().UserId, ids)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
||||
+122
-62
@@ -78,8 +78,8 @@ func (api *API) InitTeam() {
|
||||
}
|
||||
|
||||
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
team := model.TeamFromJson(r.Body)
|
||||
if team == nil {
|
||||
var team model.Team
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
|
||||
c.SetInvalidParam("team")
|
||||
return
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rteam, err := c.App.CreateTeamWithUser(c.AppContext, team, c.AppContext.Session().UserId)
|
||||
rteam, err := c.App.CreateTeamWithUser(c.AppContext, &team, c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -163,12 +163,12 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
team := model.TeamFromJson(r.Body)
|
||||
|
||||
if team == nil {
|
||||
var team model.Team
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
|
||||
c.SetInvalidParam("team")
|
||||
return
|
||||
}
|
||||
|
||||
team.Email = strings.ToLower(team.Email)
|
||||
|
||||
// The team being updated in the payload must be the same one as indicated in the URL.
|
||||
@@ -186,7 +186,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
updatedTeam, err := c.App.UpdateTeam(team)
|
||||
updatedTeam, err := c.App.UpdateTeam(&team)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -207,9 +207,8 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
team := model.TeamPatchFromJson(r.Body)
|
||||
|
||||
if team == nil {
|
||||
var team model.TeamPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
|
||||
c.SetInvalidParam("team")
|
||||
return
|
||||
}
|
||||
@@ -226,7 +225,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("team", oldTeam)
|
||||
}
|
||||
|
||||
patchedTeam, err := c.App.PatchTeam(c.Params.TeamId, team)
|
||||
patchedTeam, err := c.App.PatchTeam(c.Params.TeamId, &team)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -286,7 +285,7 @@ func updateTeamPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
privacy, ok := props["privacy"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("privacy")
|
||||
@@ -421,7 +420,13 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
w.Write([]byte(model.TeamListToJson(teams)))
|
||||
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -445,7 +450,12 @@ func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.TeamsUnreadToJson(unreadTeamsList)))
|
||||
js, jsonErr := json.Marshal(unreadTeamsList)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsUnreadForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -514,7 +524,12 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.TeamMembersToJson(members)))
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -545,7 +560,12 @@ func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.TeamMembersToJson(members)))
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -554,7 +574,7 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
@@ -578,7 +598,12 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.TeamMembersToJson(members)))
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -588,9 +613,9 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
member := model.TeamMemberFromJson(r.Body)
|
||||
if member == nil {
|
||||
c.Err = model.NewAppError("addTeamMember", "api.team.add_team_member.invalid_body.app_error", nil, "Error in model.TeamMemberFromJson()", http.StatusBadRequest)
|
||||
var member model.TeamMember
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&member); jsonErr != nil {
|
||||
c.Err = model.NewAppError("addTeamMember", "api.team.add_team_member.invalid_body.app_error", nil, "Error in model.TeamMemberFromJSON()", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if member.TeamId != c.Params.TeamId {
|
||||
@@ -653,8 +678,8 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
member, err = c.App.AddTeamMember(c.AppContext, member.TeamId, member.UserId)
|
||||
|
||||
var tm *model.TeamMember
|
||||
tm, err = c.App.AddTeamMember(c.AppContext, member.TeamId, member.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -663,7 +688,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.Success()
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
if err := json.NewEncoder(w).Encode(member); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(tm); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -717,7 +742,11 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
members := model.TeamMembersFromJson(r.Body)
|
||||
var members []*model.TeamMember
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&members); jsonErr != nil {
|
||||
c.SetInvalidParam("members")
|
||||
return
|
||||
}
|
||||
|
||||
if len(members) > MaxAddMembersBatch {
|
||||
c.SetInvalidParam("too many members in batch")
|
||||
@@ -798,17 +827,23 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var js []byte
|
||||
var jsonErr error
|
||||
if graceful {
|
||||
// in 'graceful' mode we allow a different return value, notifying the client which users were not added
|
||||
js, jsonErr = json.Marshal(membersWithErrors)
|
||||
} else {
|
||||
js, jsonErr = json.Marshal(model.TeamMembersWithErrorToTeamMembers(membersWithErrors))
|
||||
}
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("addTeamMembers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
if graceful {
|
||||
// in 'graceful' mode we allow a different return value, notifying the client which users were not added
|
||||
w.Write([]byte(model.TeamMembersWithErrorToJson(membersWithErrors)))
|
||||
} else {
|
||||
w.Write([]byte(model.TeamMembersToJson(model.TeamMembersWithErrorToTeamMembers(membersWithErrors))))
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func removeTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -916,7 +951,7 @@ func updateTeamMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
newRoles := props["roles"]
|
||||
if !model.IsValidUserRoles(newRoles) {
|
||||
@@ -951,8 +986,8 @@ func updateTeamMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
schemeRoles := model.SchemeRolesFromJson(r.Body)
|
||||
if schemeRoles == nil {
|
||||
var schemeRoles model.SchemeRoles
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&schemeRoles); jsonErr != nil {
|
||||
c.SetInvalidParam("scheme_roles")
|
||||
return
|
||||
}
|
||||
@@ -1022,20 +1057,24 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
|
||||
var resBody []byte
|
||||
|
||||
var js []byte
|
||||
var jsonErr error
|
||||
if c.Params.IncludeTotalCount {
|
||||
resBody = model.TeamsWithCountToJson(teamsWithCount)
|
||||
js, jsonErr = json.Marshal(teamsWithCount)
|
||||
} else {
|
||||
resBody = model.ToJson(teams)
|
||||
js, jsonErr = json.Marshal(teams)
|
||||
}
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAllTeams", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(resBody)
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.TeamSearchFromJson(r.Body)
|
||||
if props == nil {
|
||||
var props model.TeamSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParam("team_search")
|
||||
return
|
||||
}
|
||||
@@ -1055,19 +1094,19 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var err *model.AppError
|
||||
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPrivateTeams) && c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPublicTeams) {
|
||||
teams, totalCount, err = c.App.SearchAllTeams(props)
|
||||
teams, totalCount, err = c.App.SearchAllTeams(&props)
|
||||
} else if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPrivateTeams) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.private_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
teams, err = c.App.SearchPrivateTeams(props)
|
||||
teams, err = c.App.SearchPrivateTeams(&props)
|
||||
} else if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPublicTeams) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.public_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
teams, err = c.App.SearchPublicTeams(props)
|
||||
teams, err = c.App.SearchPublicTeams(&props)
|
||||
} else {
|
||||
teams = []*model.Team{}
|
||||
}
|
||||
@@ -1082,9 +1121,14 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var payload []byte
|
||||
if props.Page != nil && props.PerPage != nil {
|
||||
twc := map[string]interface{}{"teams": teams, "total_count": totalCount}
|
||||
payload = model.ToJson(twc)
|
||||
payload = model.ToJSON(twc)
|
||||
} else {
|
||||
payload = []byte(model.TeamListToJson(teams))
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
payload = js
|
||||
}
|
||||
|
||||
w.Write(payload)
|
||||
@@ -1121,7 +1165,7 @@ func teamExists(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
resp := map[string]bool{"exists": exists}
|
||||
w.Write([]byte(model.MapBoolToJson(resp)))
|
||||
w.Write([]byte(model.MapBoolToJSON(resp)))
|
||||
}
|
||||
|
||||
func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1210,7 +1254,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
w.Write([]byte(model.MapToJson(data)))
|
||||
w.Write([]byte(model.MapToJSON(data)))
|
||||
}
|
||||
|
||||
func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1231,7 +1275,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
emailList := model.ArrayFromJson(r.Body)
|
||||
emailList := model.ArrayFromJSON(r.Body)
|
||||
|
||||
for i := range emailList {
|
||||
emailList[i] = strings.ToLower(emailList[i])
|
||||
@@ -1271,7 +1315,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
scheduledAt := model.GetMillis()
|
||||
jobData := map[string]string{
|
||||
"emailList": model.ArrayToJson(emailList),
|
||||
"emailList": model.ArrayToJSON(emailList),
|
||||
"teamID": c.Params.TeamId,
|
||||
"senderID": c.AppContext.Session().UserId,
|
||||
"scheduledAt": strconv.FormatInt(scheduledAt, 10),
|
||||
@@ -1308,7 +1352,12 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
js, jsonErr := json.Marshal(invitesWithError)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("inviteUsersToTeam", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
} else {
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
@@ -1346,9 +1395,9 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
guestsInvite := model.GuestsInviteFromJson(r.Body)
|
||||
if guestsInvite == nil {
|
||||
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, "", http.StatusBadRequest)
|
||||
var guestsInvite model.GuestsInvite
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&guestsInvite); jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1387,7 +1436,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
var err *model.AppError
|
||||
|
||||
if guestsInvite.Emails != nil {
|
||||
invitesWithError, err = c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.AppContext.Session().UserId)
|
||||
invitesWithError, err = c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
}
|
||||
|
||||
if len(invitesOverLimit) > 0 {
|
||||
@@ -1404,9 +1453,14 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
js, jsonErr := json.Marshal(invitesWithError)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("inviteGuestsToChannel", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
} else {
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, guestsInvite, c.AppContext.Session().UserId)
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1438,7 +1492,7 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
result["description"] = team.Description
|
||||
result["name"] = team.Name
|
||||
result["id"] = team.Id
|
||||
w.Write([]byte(model.MapToJson(result)))
|
||||
w.Write([]byte(model.MapToJSON(result)))
|
||||
}
|
||||
|
||||
func invalidateAllEmailInvites(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1581,8 +1635,14 @@ func updateTeamScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
schemeID := model.SchemeIDFromJson(r.Body)
|
||||
if schemeID == nil || (!model.IsValidId(*schemeID) && *schemeID != "") {
|
||||
var p model.SchemeIDPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&p); jsonErr != nil {
|
||||
c.SetInvalidParam("scheme_id")
|
||||
return
|
||||
}
|
||||
|
||||
schemeID := p.SchemeID
|
||||
if p.SchemeID == nil || (!model.IsValidId(*p.SchemeID) && *p.SchemeID != "") {
|
||||
c.SetInvalidParam("scheme_id")
|
||||
return
|
||||
}
|
||||
|
||||
+11
-5
@@ -76,7 +76,7 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
emailList := model.ArrayFromJson(r.Body)
|
||||
emailList := model.ArrayFromJSON(r.Body)
|
||||
if len(emailList) == 0 {
|
||||
c.SetInvalidParam("user_email")
|
||||
return
|
||||
@@ -142,7 +142,12 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithErrors)))
|
||||
js, jsonErr := json.Marshal(invitesWithErrors)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
} else {
|
||||
var invalidEmailList []string
|
||||
|
||||
@@ -200,18 +205,19 @@ func normalizeDomains(domains string) []string {
|
||||
}
|
||||
|
||||
func localCreateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
team := model.TeamFromJson(r.Body)
|
||||
if team == nil {
|
||||
var team model.Team
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
|
||||
c.SetInvalidParam("team")
|
||||
return
|
||||
}
|
||||
|
||||
team.Email = strings.ToLower(team.Email)
|
||||
|
||||
auditRec := c.MakeAuditRecord("localCreateTeam", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("team", team)
|
||||
|
||||
rteam, err := c.App.CreateTeam(c.AppContext, team)
|
||||
rteam, err := c.App.CreateTeam(c.AppContext, &team)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
+7
-4
@@ -6,6 +6,7 @@ package api4
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -343,7 +344,9 @@ func TestUpdateTeam(t *testing.T) {
|
||||
originalTeamId := team.Id
|
||||
team.Id = model.NewId()
|
||||
|
||||
r, err := th.Client.DoAPIPut("/teams/"+originalTeamId, team.ToJson())
|
||||
teamJSON, jsonErr := json.Marshal(team)
|
||||
require.NoError(t, jsonErr)
|
||||
r, err := th.Client.DoAPIPut("/teams/"+originalTeamId, string(teamJSON))
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
|
||||
@@ -2038,7 +2041,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -2074,7 +2077,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
testId := GenerateTestId()
|
||||
token = model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": testId}),
|
||||
model.MapToJSON(map[string]string{"teamId": testId}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -2119,7 +2122,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
// Attempt to use a token on a group-constrained team
|
||||
token = model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
_, _, err = client.AddTeamMemberFromInvite(token.Token, "")
|
||||
|
||||
@@ -44,7 +44,7 @@ func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("createTermsOfService", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
text := props["text"]
|
||||
userId := c.AppContext.Session().UserId
|
||||
|
||||
|
||||
+4
-4
@@ -29,8 +29,8 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
us := model.UploadSessionFromJson(r.Body)
|
||||
if us == nil {
|
||||
var us model.UploadSession
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&us); jsonErr != nil {
|
||||
c.SetInvalidParam("upload")
|
||||
return
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.AppContext.Session().UserId != "" {
|
||||
us.UserId = c.AppContext.Session().UserId
|
||||
}
|
||||
us, err := c.App.CreateUploadSession(us)
|
||||
rus, err := c.App.CreateUploadSession(&us)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -68,7 +68,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.Success()
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
if err := json.NewEncoder(w).Encode(us); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(rus); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@@ -326,8 +327,10 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
req.Header.Set(model.HeaderAuth, th.Client.AuthType+" "+th.Client.AuthToken)
|
||||
res, err := th.Client.HTTPClient.Do(req)
|
||||
require.NoError(t, err)
|
||||
info := model.FileInfoFromJson(res.Body)
|
||||
var info model.FileInfo
|
||||
err = json.NewDecoder(res.Body).Decode(&info)
|
||||
res.Body.Close()
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, us.Filename, info.Name)
|
||||
|
||||
@@ -361,8 +364,10 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
req.Header.Set(model.HeaderAuth, th.Client.AuthType+" "+th.Client.AuthToken)
|
||||
res, err = th.Client.HTTPClient.Do(req)
|
||||
require.NoError(t, err)
|
||||
info := model.FileInfoFromJson(res.Body)
|
||||
var info model.FileInfo
|
||||
err = json.NewDecoder(res.Body).Decode(&info)
|
||||
res.Body.Close()
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, u.Filename, info.Name)
|
||||
|
||||
|
||||
+132
-67
@@ -102,8 +102,8 @@ func (api *API) InitUser() {
|
||||
}
|
||||
|
||||
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
user := model.UserFromJson(r.Body)
|
||||
if user == nil {
|
||||
var user model.User
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&user); jsonErr != nil {
|
||||
c.SetInvalidParam("user")
|
||||
return
|
||||
}
|
||||
@@ -148,14 +148,14 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
ruser, err = c.App.CreateUserWithToken(c.AppContext, user, token)
|
||||
ruser, err = c.App.CreateUserWithToken(c.AppContext, &user, token)
|
||||
} else if inviteId != "" {
|
||||
ruser, err = c.App.CreateUserWithInviteId(c.AppContext, user, inviteId, redirect)
|
||||
ruser, err = c.App.CreateUserWithInviteId(c.AppContext, &user, inviteId, redirect)
|
||||
} else if c.IsSystemAdmin() {
|
||||
ruser, err = c.App.CreateUserAsAdmin(c.AppContext, user, redirect)
|
||||
ruser, err = c.App.CreateUserAsAdmin(c.AppContext, &user, redirect)
|
||||
auditRec.AddMeta("admin", true)
|
||||
} else {
|
||||
ruser, err = c.App.CreateUserFromSignup(c.AppContext, user, redirect)
|
||||
ruser, err = c.App.CreateUserFromSignup(c.AppContext, &user, redirect)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -624,7 +624,7 @@ func getFilteredUsersStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getUsersByGroupChannelIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channelIds := model.ArrayFromJson(r.Body)
|
||||
channelIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(channelIds) == 0 {
|
||||
c.SetInvalidParam("channel_ids")
|
||||
@@ -830,11 +830,18 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
}
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.AppContext.Session())
|
||||
w.Write([]byte(model.UserListToJson(profiles)))
|
||||
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
@@ -869,11 +876,17 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserListToJson(users)))
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
usernames := model.ArrayFromJson(r.Body)
|
||||
usernames := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(usernames) == 0 {
|
||||
c.SetInvalidParam("usernames")
|
||||
@@ -892,7 +905,13 @@ func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserListToJson(users)))
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsersByNames", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getKnownUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -908,12 +927,16 @@ func getKnownUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.UserSearchFromJson(r.Body)
|
||||
if props == nil {
|
||||
var props model.UserSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParam("")
|
||||
return
|
||||
}
|
||||
|
||||
if props.Limit == 0 {
|
||||
props.Limit = model.UserSearchDefaultLimit
|
||||
}
|
||||
|
||||
if props.Term == "" {
|
||||
c.SetInvalidParam("term")
|
||||
return
|
||||
@@ -986,13 +1009,19 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err := c.App.SearchUsers(props, options)
|
||||
profiles, err := c.App.SearchUsers(&props, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserListToJson(profiles)))
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1092,8 +1121,8 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user := model.UserFromJson(r.Body)
|
||||
if user == nil {
|
||||
var user model.User
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&user); jsonErr != nil {
|
||||
c.SetInvalidParam("user")
|
||||
return
|
||||
}
|
||||
@@ -1151,7 +1180,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
ruser, err := c.App.UpdateUserAsUser(user, c.IsSystemAdmin())
|
||||
ruser, err := c.App.UpdateUserAsUser(&user, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1172,8 +1201,8 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
patch := model.UserPatchFromJson(r.Body)
|
||||
if patch == nil {
|
||||
var patch model.UserPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
|
||||
c.SetInvalidParam("user")
|
||||
return
|
||||
}
|
||||
@@ -1207,7 +1236,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
conflictField := c.App.CheckProviderAttributes(ouser, patch)
|
||||
conflictField := c.App.CheckProviderAttributes(ouser, &patch)
|
||||
if conflictField != "" {
|
||||
c.Err = model.NewAppError(
|
||||
"patchUser", "api.user.patch_user.login_provider_attribute_set.app_error",
|
||||
@@ -1228,7 +1257,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
ruser, err := c.App.PatchUser(c.Params.UserId, patch, c.IsSystemAdmin())
|
||||
ruser, err := c.App.PatchUser(c.Params.UserId, &patch, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1304,7 +1333,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
newRoles := props["roles"]
|
||||
if !model.IsValidUserRoles(newRoles) {
|
||||
@@ -1352,7 +1381,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
|
||||
active, ok := props["active"].(bool)
|
||||
if !ok {
|
||||
@@ -1451,8 +1480,8 @@ func updateUserAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("updateUserAuth", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
userAuth := model.UserAuthFromJson(r.Body)
|
||||
if userAuth == nil {
|
||||
var userAuth model.UserAuth
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&userAuth); jsonErr != nil {
|
||||
c.SetInvalidParam("user")
|
||||
return
|
||||
}
|
||||
@@ -1466,7 +1495,7 @@ func updateUserAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("user", user)
|
||||
}
|
||||
|
||||
user, err := c.App.UpdateUserAuth(c.Params.UserId, userAuth)
|
||||
user, err := c.App.UpdateUserAuth(c.Params.UserId, &userAuth)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1490,7 +1519,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
loginId := props["login_id"]
|
||||
if loginId == "" {
|
||||
@@ -1502,7 +1531,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
resp["mfa_required"] = false
|
||||
|
||||
if !*c.App.Config().ServiceSettings.EnableMultifactorAuthentication {
|
||||
w.Write([]byte(model.StringInterfaceToJson(resp)))
|
||||
w.Write([]byte(model.StringInterfaceToJSON(resp)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1512,7 +1541,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
resp["mfa_required"] = user.MfaActive
|
||||
}
|
||||
|
||||
w.Write([]byte(model.StringInterfaceToJson(resp)))
|
||||
w.Write([]byte(model.StringInterfaceToJSON(resp)))
|
||||
}
|
||||
|
||||
func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1539,7 +1568,7 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("user", user)
|
||||
}
|
||||
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
activate, ok := props["activate"].(bool)
|
||||
if !ok {
|
||||
c.SetInvalidParam("activate")
|
||||
@@ -1606,7 +1635,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
newPassword := props["new_password"]
|
||||
|
||||
auditRec := c.MakeAuditRecord("updatePassword", audit.Fail)
|
||||
@@ -1665,7 +1694,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
token := props["token"]
|
||||
if len(token) != model.TokenSize {
|
||||
@@ -1693,7 +1722,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
email := props["email"]
|
||||
email = strings.ToLower(email)
|
||||
@@ -1782,7 +1811,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = model.NewAppError("login", "api.user.login.invalid_credentials_email_username", nil, "", http.StatusUnauthorized)
|
||||
}()
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
id := props["id"]
|
||||
loginId := props["login_id"]
|
||||
password := props["password"]
|
||||
@@ -1952,7 +1981,12 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
session.Sanitize()
|
||||
}
|
||||
|
||||
w.Write([]byte(model.SessionsToJson(sessions)))
|
||||
js, jsonErr := json.Marshal(sessions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getSessions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1969,7 +2003,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
sessionId := props["session_id"]
|
||||
if sessionId == "" {
|
||||
c.SetInvalidParam("session_id")
|
||||
@@ -2046,7 +2080,7 @@ func revokeAllSessionsAllUsers(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
deviceId := props["device_id"]
|
||||
if deviceId == "" {
|
||||
@@ -2135,7 +2169,7 @@ func getUserAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func verifyUserEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
token := props["token"]
|
||||
if len(token) != model.TokenSize {
|
||||
@@ -2158,7 +2192,7 @@ func verifyUserEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
email := props["email"]
|
||||
email = strings.ToLower(email)
|
||||
@@ -2192,8 +2226,8 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
switchRequest := model.SwitchRequestFromJson(r.Body)
|
||||
if switchRequest == nil {
|
||||
var switchRequest model.SwitchRequest
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&switchRequest); jsonErr != nil {
|
||||
c.SetInvalidParam("switch_request")
|
||||
return
|
||||
}
|
||||
@@ -2233,7 +2267,7 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.Success()
|
||||
c.LogAudit("success")
|
||||
|
||||
w.Write([]byte(model.MapToJson(map[string]string{"follow_link": link})))
|
||||
w.Write([]byte(model.MapToJSON(map[string]string{"follow_link": link})))
|
||||
}
|
||||
|
||||
func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -2255,8 +2289,8 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
accessToken := model.UserAccessTokenFromJson(r.Body)
|
||||
if accessToken == nil {
|
||||
var accessToken model.UserAccessToken
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&accessToken); jsonErr != nil {
|
||||
c.SetInvalidParam("user_access_token")
|
||||
return
|
||||
}
|
||||
@@ -2281,17 +2315,17 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
accessToken.UserId = c.Params.UserId
|
||||
accessToken.Token = ""
|
||||
|
||||
accessToken, err := c.App.CreateUserAccessToken(accessToken)
|
||||
token, err := c.App.CreateUserAccessToken(&accessToken)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("token_id", accessToken.Id)
|
||||
c.LogAudit("success - token_id=" + accessToken.Id)
|
||||
auditRec.AddMeta("token_id", token.Id)
|
||||
c.LogAudit("success - token_id=" + token.Id)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(accessToken); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(token); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -2301,8 +2335,9 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
c.SetPermissionError(model.PermissionManageSystem)
|
||||
return
|
||||
}
|
||||
props := model.UserAccessTokenSearchFromJson(r.Body)
|
||||
if props == nil {
|
||||
|
||||
var props model.UserAccessTokenSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParam("user_access_token_search")
|
||||
return
|
||||
}
|
||||
@@ -2318,7 +2353,13 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserAccessTokenListToJson(accessTokens)))
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -2333,7 +2374,13 @@ func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserAccessTokenListToJson(accessTokens)))
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -2358,7 +2405,13 @@ func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserAccessTokenListToJson(accessTokens)))
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -2389,7 +2442,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
tokenId := props["token_id"]
|
||||
if tokenId == "" {
|
||||
@@ -2433,7 +2486,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
tokenId := props["token_id"]
|
||||
|
||||
if tokenId == "" {
|
||||
@@ -2478,7 +2531,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
props := model.MapFromJSON(r.Body)
|
||||
|
||||
tokenId := props["token_id"]
|
||||
if tokenId == "" {
|
||||
@@ -2523,7 +2576,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
|
||||
userId := c.AppContext.Session().UserId
|
||||
termsOfServiceId, ok := props["termsOfServiceId"].(string)
|
||||
@@ -2666,8 +2719,8 @@ func publishUserTyping(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
typingRequest := model.TypingRequestFromJson(r.Body)
|
||||
if typingRequest == nil {
|
||||
var typingRequest model.TypingRequest
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&typingRequest); jsonErr != nil {
|
||||
c.SetInvalidParam("typing_request")
|
||||
return
|
||||
}
|
||||
@@ -2751,10 +2804,17 @@ func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("convertedTo", bot)
|
||||
|
||||
w.Write(bot.ToJson())
|
||||
js, jsonErr := json.Marshal(bot)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("convertUserToBot", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getUploadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -2774,11 +2834,16 @@ func getUploadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UploadSessionsToJson(uss)))
|
||||
js, jsonErr := json.Marshal(uss)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUploadsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func migrateAuthToLDAP(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
from, ok := props["from"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("from")
|
||||
@@ -2837,7 +2902,7 @@ func migrateAuthToLDAP(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func migrateAuthToSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
props := model.StringInterfaceFromJSON(r.Body)
|
||||
from, ok := props["from"].(string)
|
||||
if !ok {
|
||||
c.SetInvalidParam("from")
|
||||
@@ -2858,7 +2923,7 @@ func migrateAuthToSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("matches")
|
||||
return
|
||||
}
|
||||
usersMap := model.MapFromJson(strings.NewReader(model.StringInterfaceToJson(matches)))
|
||||
usersMap := model.MapFromJSON(strings.NewReader(model.StringInterfaceToJSON(matches)))
|
||||
|
||||
auditRec := c.MakeAuditRecord("migrateAuthToSaml", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
+22
-4
@@ -145,11 +145,18 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if etag != "" {
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
}
|
||||
w.Write([]byte(model.UserListToJson(profiles)))
|
||||
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJson(r.Body)
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
@@ -177,7 +184,13 @@ func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UserListToJson(users)))
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUsersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func localGetUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -335,5 +348,10 @@ func localGetUploadsForUser(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.UploadSessionsToJson(uss)))
|
||||
js, jsonErr := json.Marshal(uss)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUploadsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
+11
-9
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -221,7 +222,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -246,7 +247,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -271,7 +272,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -287,7 +288,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
past49Hours := timeNow.Add(-49*time.Hour).UnixNano() / int64(time.Millisecond)
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
token.CreateAt = past49Hours
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
@@ -319,7 +320,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -340,7 +341,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -358,7 +359,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
app.TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -5761,8 +5762,9 @@ func TestThreadSocketEvents(t *testing.T) {
|
||||
case ev := <-userWSClient.EventChannel:
|
||||
if ev.EventType() == model.WebsocketEventThreadUpdated {
|
||||
caught = true
|
||||
thread, err2 := model.ThreadResponseFromJson(ev.GetData()["thread"].(string))
|
||||
require.NoError(t, err2)
|
||||
var thread model.ThreadResponse
|
||||
jsonErr := json.Unmarshal([]byte(ev.GetData()["thread"].(string)), &thread)
|
||||
require.NoError(t, jsonErr)
|
||||
for _, p := range thread.Participants {
|
||||
if p.Id != th.BasicUser.Id && p.Id != th.BasicUser2.Id {
|
||||
require.Fail(t, "invalid participants")
|
||||
|
||||
+24
-14
@@ -28,8 +28,8 @@ func (api *API) InitWebhook() {
|
||||
}
|
||||
|
||||
func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
hook := model.IncomingWebhookFromJson(r.Body)
|
||||
if hook == nil {
|
||||
var hook model.IncomingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
|
||||
c.SetInvalidParam("incoming_webhook")
|
||||
return
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userId = hook.UserId
|
||||
}
|
||||
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(userId, channel, hook)
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(userId, channel, &hook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -94,8 +94,8 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
updatedHook := model.IncomingWebhookFromJson(r.Body)
|
||||
if updatedHook == nil {
|
||||
var updatedHook model.IncomingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&updatedHook); jsonErr != nil {
|
||||
c.SetInvalidParam("incoming_webhook")
|
||||
return
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
incomingHook, err := c.App.UpdateIncomingWebhook(oldHook, updatedHook)
|
||||
incomingHook, err := c.App.UpdateIncomingWebhook(oldHook, &updatedHook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -210,7 +210,12 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.IncomingWebhookListToJson(hooks)))
|
||||
js, jsonErr := json.Marshal(hooks)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getIncomingHooks", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -326,8 +331,8 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
updatedHook := model.OutgoingWebhookFromJson(r.Body)
|
||||
if updatedHook == nil {
|
||||
var updatedHook model.OutgoingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&updatedHook); jsonErr != nil {
|
||||
c.SetInvalidParam("outgoing_webhook")
|
||||
return
|
||||
}
|
||||
@@ -374,7 +379,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
updatedHook.CreatorId = c.AppContext.Session().UserId
|
||||
|
||||
rhook, err := c.App.UpdateOutgoingWebhook(oldHook, updatedHook)
|
||||
rhook, err := c.App.UpdateOutgoingWebhook(oldHook, &updatedHook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -389,8 +394,8 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
hook := model.OutgoingWebhookFromJson(r.Body)
|
||||
if hook == nil {
|
||||
var hook model.OutgoingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
|
||||
c.SetInvalidParam("outgoing_webhook")
|
||||
return
|
||||
}
|
||||
@@ -421,7 +426,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
rhook, err := c.App.CreateOutgoingWebhook(hook)
|
||||
rhook, err := c.App.CreateOutgoingWebhook(&hook)
|
||||
if err != nil {
|
||||
c.LogAudit("fail")
|
||||
c.Err = err
|
||||
@@ -491,7 +496,12 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.OutgoingWebhookListToJson(hooks)))
|
||||
js, jsonErr := json.Marshal(hooks)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getOutgoingHooks", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -27,8 +27,8 @@ func (api *API) InitWebhookLocal() {
|
||||
}
|
||||
|
||||
func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
hook := model.IncomingWebhookFromJson(r.Body)
|
||||
if hook == nil {
|
||||
var hook model.IncomingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
|
||||
c.SetInvalidParam("incoming_webhook")
|
||||
return
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
auditRec.AddMeta("channel", channel)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(hook.UserId, channel, hook)
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(hook.UserId, channel, &hook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -71,8 +71,8 @@ func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func localCreateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
hook := model.OutgoingWebhookFromJson(r.Body)
|
||||
if hook == nil {
|
||||
var hook model.OutgoingWebhook
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
|
||||
c.SetInvalidParam("outgoing_webhook")
|
||||
return
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func localCreateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
rhook, err := c.App.CreateOutgoingWebhook(hook)
|
||||
rhook, err := c.App.CreateOutgoingWebhook(&hook)
|
||||
if err != nil {
|
||||
c.LogAudit("fail")
|
||||
c.Err = err
|
||||
|
||||
+8
-2
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -136,7 +137,7 @@ func (b *Busy) ClusterEventChanged(sbs *model.ServerBusyState) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Busy) ToJson() string {
|
||||
func (b *Busy) ToJSON() ([]byte, error) {
|
||||
b.mux.RLock()
|
||||
defer b.mux.RUnlock()
|
||||
|
||||
@@ -145,5 +146,10 @@ func (b *Busy) ToJson() string {
|
||||
Expires: b.expires.Unix(),
|
||||
ExpiresTS: b.expires.UTC().Format(TimestampFormat),
|
||||
}
|
||||
return sbs.ToJson()
|
||||
sbsJSON, jsonErr := json.Marshal(sbs)
|
||||
if jsonErr != nil {
|
||||
return []byte{}, fmt.Errorf("failed to encode server busy state to JSON: %w", jsonErr)
|
||||
}
|
||||
|
||||
return sbsJSON, nil
|
||||
}
|
||||
|
||||
+10
-5
@@ -4,7 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -100,11 +100,15 @@ func TestBusyRace(t *testing.T) {
|
||||
func compareBusyState(t *testing.T, busy1 *Busy, busy2 *Busy) bool {
|
||||
t.Helper()
|
||||
if busy1.IsBusy() != busy2.IsBusy() {
|
||||
t.Logf("busy1:%s; busy2:%s\n", busy1.ToJson(), busy2.ToJson())
|
||||
busy1JSON, _ := busy1.ToJSON()
|
||||
busy2JSON, _ := busy2.ToJSON()
|
||||
t.Logf("busy1:%s; busy2:%s\n", busy1JSON, busy2JSON)
|
||||
return false
|
||||
}
|
||||
if busy1.Expires().Unix() != busy2.Expires().Unix() {
|
||||
t.Logf("busy1:%s; busy2:%s\n", busy1.ToJson(), busy2.ToJson())
|
||||
busy1JSON, _ := busy1.ToJSON()
|
||||
busy2JSON, _ := busy2.ToJSON()
|
||||
t.Logf("busy1:%s; busy2:%s\n", busy1JSON, busy2JSON)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -116,8 +120,9 @@ type ClusterMock struct {
|
||||
}
|
||||
|
||||
func (c *ClusterMock) SendClusterMessage(msg *model.ClusterMessage) {
|
||||
sbs := model.ServerBusyStateFromJson(bytes.NewReader(msg.Data))
|
||||
c.Busy.ClusterEventChanged(sbs)
|
||||
var sbs model.ServerBusyState
|
||||
json.Unmarshal(msg.Data, &sbs)
|
||||
c.Busy.ClusterEventChanged(&sbs)
|
||||
}
|
||||
|
||||
func (c *ClusterMock) SendClusterMessageToNode(nodeID string, msg *model.ClusterMessage) error {
|
||||
|
||||
+41
-13
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -510,7 +511,7 @@ func (a *App) CreateGroupChannel(userIDs []string, creatorId string) (*model.Cha
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventGroupAdded, "", channel.Id, "", nil)
|
||||
message.Add("teammate_ids", model.ArrayToJson(userIDs))
|
||||
message.Add("teammate_ids", model.ArrayToJSON(userIDs))
|
||||
a.Publish(message)
|
||||
|
||||
return channel, nil
|
||||
@@ -527,7 +528,7 @@ func (a *App) createGroupChannel(userIDs []string) (*model.Channel, *model.AppEr
|
||||
}
|
||||
|
||||
if len(users) != len(userIDs) {
|
||||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIDs), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJSON(userIDs), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
group := &model.Channel{
|
||||
@@ -606,7 +607,7 @@ func (a *App) GetGroupChannel(userIDs []string) (*model.Channel, *model.AppError
|
||||
}
|
||||
|
||||
if len(users) != len(userIDs) {
|
||||
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIDs), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJSON(userIDs), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, appErr := a.GetChannelByName(model.GetGroupNameFromUserIds(userIDs), "", true)
|
||||
@@ -636,7 +637,11 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
|
||||
a.invalidateCacheForChannel(channel)
|
||||
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventChannelUpdated, "", channel.Id, "", nil)
|
||||
messageWs.Add("channel", channel.ToJson())
|
||||
channelJSON, jsonErr := json.Marshal(channel)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
messageWs.Add("channel", string(channelJSON))
|
||||
a.Publish(messageWs)
|
||||
|
||||
return channel, nil
|
||||
@@ -1248,7 +1253,11 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID s
|
||||
|
||||
// Notify the clients that the member notify props changed
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil)
|
||||
evt.Add("channelMember", member.ToJson())
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
|
||||
return member, nil
|
||||
@@ -1273,7 +1282,11 @@ func (a *App) updateChannelMember(member *model.ChannelMember) (*model.ChannelMe
|
||||
|
||||
// Notify the clients that the member notify props changed
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil)
|
||||
evt.Add("channelMember", member.ToJson())
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
|
||||
return member, nil
|
||||
@@ -2545,10 +2558,12 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string, collapse
|
||||
}
|
||||
a.sanitizeProfiles(thread.Participants, false)
|
||||
thread.Post.SanitizeProps()
|
||||
|
||||
payload := thread.ToJson()
|
||||
payload, jsonErr := json.Marshal(thread)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, channel.TeamId, "", userID, nil)
|
||||
message.Add("thread", payload)
|
||||
message.Add("thread", string(payload))
|
||||
a.Publish(message)
|
||||
}
|
||||
} else if !threadMembership.Following && followThread {
|
||||
@@ -2661,10 +2676,13 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
|
||||
a.sanitizeProfiles(thread.Participants, false)
|
||||
thread.Post.SanitizeProps()
|
||||
|
||||
payload := thread.ToJson()
|
||||
if a.isCRTEnabledForUser(userID) {
|
||||
payload, jsonErr := json.Marshal(thread)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, channel.TeamId, "", userID, nil)
|
||||
message.Add("thread", payload)
|
||||
message.Add("thread", string(payload))
|
||||
a.Publish(message)
|
||||
}
|
||||
channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false, false)
|
||||
@@ -3190,7 +3208,13 @@ func (a *App) setChannelsMuted(channelIDs []string, userID string, muted bool) (
|
||||
a.invalidateCacheForChannelMembersNotifyProps(member.ChannelId)
|
||||
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil)
|
||||
evt.Add("channelMember", member.ToJson())
|
||||
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
}
|
||||
|
||||
@@ -3292,7 +3316,11 @@ func (a *App) ClearChannelMembersCache(channelID string) {
|
||||
clearSessionCache := func(channelMember model.ChannelMember) error {
|
||||
a.ClearSessionCacheForUser(channelMember.UserId)
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", channelMember.UserId, nil)
|
||||
message.Add("channelMember", channelMember.ToJson())
|
||||
memberJSON, jsonErr := json.Marshal(channelMember)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("channelMember", string(memberJSON))
|
||||
a.Publish(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
+23
-6
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
@@ -12,11 +13,19 @@ import (
|
||||
)
|
||||
|
||||
func (s *Server) clusterInstallPluginHandler(msg *model.ClusterMessage) {
|
||||
s.installPluginFromData(model.PluginEventDataFromJson(bytes.NewReader(msg.Data)))
|
||||
var data model.PluginEventData
|
||||
if jsonErr := json.Unmarshal(msg.Data, &data); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
s.installPluginFromData(data)
|
||||
}
|
||||
|
||||
func (s *Server) clusterRemovePluginHandler(msg *model.ClusterMessage) {
|
||||
s.removePluginFromData(model.PluginEventDataFromJson(bytes.NewReader(msg.Data)))
|
||||
var data model.PluginEventData
|
||||
if jsonErr := json.Unmarshal(msg.Data, &data); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
s.removePluginFromData(data)
|
||||
}
|
||||
|
||||
func (s *Server) clusterPluginEventHandler(msg *model.ClusterMessage) {
|
||||
@@ -69,15 +78,19 @@ func (s *Server) registerClusterHandlers() {
|
||||
}
|
||||
|
||||
func (s *Server) clusterPublishHandler(msg *model.ClusterMessage) {
|
||||
event := model.WebSocketEventFromJson(bytes.NewReader(msg.Data))
|
||||
if event == nil {
|
||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to decode event from JSON", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
s.PublishSkipClusterSend(event)
|
||||
}
|
||||
|
||||
func (s *Server) clusterUpdateStatusHandler(msg *model.ClusterMessage) {
|
||||
status := model.StatusFromJson(bytes.NewReader(msg.Data))
|
||||
var status model.Status
|
||||
if jsonErr := json.Unmarshal(msg.Data, &status); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode status from JSON")
|
||||
}
|
||||
s.statusCache.Set(status.UserId, status)
|
||||
}
|
||||
|
||||
@@ -120,7 +133,11 @@ func (s *Server) clusterClearSessionCacheForAllUsersHandler(msg *model.ClusterMe
|
||||
}
|
||||
|
||||
func (s *Server) clusterBusyStateChgHandler(msg *model.ClusterMessage) {
|
||||
s.serverBusyStateChanged(model.ServerBusyStateFromJson(bytes.NewReader(msg.Data)))
|
||||
var sbs model.ServerBusyState
|
||||
if jsonErr := json.Unmarshal(msg.Data, &sbs); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode server busy state from JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
s.serverBusyStateChanged(&sbs)
|
||||
}
|
||||
|
||||
func (s *Server) invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelID string) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@@ -277,7 +278,10 @@ func (a *App) getDynamicListArgument(c *request.Context, commandArgs *model.Comm
|
||||
return false, parsed, toBeParsed, []model.AutocompleteSuggestion{}
|
||||
}
|
||||
|
||||
listItems := model.AutocompleteStaticListItemsFromJSON(resp.Body)
|
||||
var listItems []model.AutocompleteListItem
|
||||
if jsonErr := json.NewDecoder(resp.Body).Decode(&listItems); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
|
||||
return parseListItems(listItems, parsed, toBeParsed)
|
||||
}
|
||||
|
||||
+4
-4
@@ -460,14 +460,14 @@ func (es *Service) SendInviteEmails(team *model.Team, senderName string, senderU
|
||||
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id, "email": invite}),
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id, "email": invite}),
|
||||
)
|
||||
|
||||
tokenProps := make(map[string]string)
|
||||
tokenProps["email"] = invite
|
||||
tokenProps["display_name"] = team.DisplayName
|
||||
tokenProps["name"] = team.Name
|
||||
tokenData := model.MapToJson(tokenProps)
|
||||
tokenData := model.MapToJSON(tokenProps)
|
||||
|
||||
if err := es.store.Token().Save(token); err != nil {
|
||||
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
||||
@@ -531,7 +531,7 @@ func (es *Service) SendGuestInviteEmails(team *model.Team, channels []*model.Cha
|
||||
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{
|
||||
model.MapToJSON(map[string]string{
|
||||
"teamId": team.Id,
|
||||
"channels": strings.Join(channelIDs, " "),
|
||||
"email": invite,
|
||||
@@ -543,7 +543,7 @@ func (es *Service) SendGuestInviteEmails(team *model.Team, channels []*model.Cha
|
||||
tokenProps["email"] = invite
|
||||
tokenProps["display_name"] = team.DisplayName
|
||||
tokenProps["name"] = team.Name
|
||||
tokenData := model.MapToJson(tokenProps)
|
||||
tokenData := model.MapToJSON(tokenProps)
|
||||
|
||||
if err := es.store.Token().Save(token); err != nil {
|
||||
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
||||
|
||||
+6
-1
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
@@ -78,7 +79,11 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventEmojiAdded, "", "", "", nil)
|
||||
message.Add("emoji", emoji.ToJson())
|
||||
emojiJSON, jsonErr := json.Marshal(emoji)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode emoji to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("emoji", string(emojiJSON))
|
||||
a.Publish(message)
|
||||
return emoji, nil
|
||||
}
|
||||
|
||||
+12
-2
@@ -4,10 +4,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
)
|
||||
|
||||
@@ -97,7 +99,11 @@ func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
|
||||
if err == nil {
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventReceivedGroup, "", "", "", nil)
|
||||
messageWs.Add("group", updatedGroup.ToJson())
|
||||
groupJSON, jsonErr := json.Marshal(updatedGroup)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode group to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
messageWs.Add("group", string(groupJSON))
|
||||
a.Publish(messageWs)
|
||||
}
|
||||
|
||||
@@ -122,7 +128,11 @@ func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
|
||||
if err == nil {
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventReceivedGroup, "", "", "", nil)
|
||||
messageWs.Add("group", deletedGroup.ToJson())
|
||||
groupJSON, jsonErr := json.Marshal(deletedGroup)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode group to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
messageWs.Add("group", string(groupJSON))
|
||||
a.Publish(messageWs)
|
||||
}
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppErr
|
||||
}
|
||||
}
|
||||
|
||||
if data.Props != nil && utf8.RuneCountInString(model.StringInterfaceToJson(*data.Props)) > model.PostPropsMaxRunes {
|
||||
if data.Props != nil && utf8.RuneCountInString(model.StringInterfaceToJSON(*data.Props)) > model.PostPropsMaxRunes {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.props_too_large.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,11 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
resp, appErr = a.DoActionRequest(c, upstreamURL, upstreamRequest.ToJson())
|
||||
requestJSON, jsonErr := json.Marshal(upstreamRequest)
|
||||
if jsonErr != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
resp, appErr = a.DoActionRequest(c, upstreamURL, requestJSON)
|
||||
if appErr != nil {
|
||||
return "", appErr
|
||||
}
|
||||
@@ -530,7 +534,7 @@ type MailToLinkContent struct {
|
||||
MailBody string `json:"mail_body"`
|
||||
}
|
||||
|
||||
func (mlc *MailToLinkContent) ToJson() string {
|
||||
func (mlc *MailToLinkContent) ToJSON() string {
|
||||
b, _ := json.Marshal(mlc)
|
||||
return string(b)
|
||||
}
|
||||
@@ -569,7 +573,7 @@ func (a *App) buildWarnMetricMailtoLink(warnMetricId string, user *model.User) s
|
||||
MailBody: mailBody,
|
||||
}
|
||||
|
||||
return mailToLinkContent.ToJson()
|
||||
return mailToLinkContent.ToJSON()
|
||||
}
|
||||
|
||||
func (a *App) DoLocalRequest(c *request.Context, rawURL string, body []byte) (*http.Response, *model.AppError) {
|
||||
|
||||
@@ -29,8 +29,9 @@ func TestPostActionInvalidURL(t *testing.T) {
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
request := model.PostActionIntegrationRequestFromJson(r.Body)
|
||||
assert.NotNil(t, request)
|
||||
var request model.PostActionIntegrationRequest
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&request)
|
||||
assert.NoError(t, jsonErr)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
@@ -155,8 +156,9 @@ func TestPostAction(t *testing.T) {
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
request := model.PostActionIntegrationRequestFromJson(r.Body)
|
||||
assert.NotNil(t, request)
|
||||
var request model.PostActionIntegrationRequest
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&request)
|
||||
assert.NoError(t, jsonErr)
|
||||
|
||||
assert.Equal(t, request.UserId, th.BasicUser.Id)
|
||||
assert.Equal(t, request.UserName, th.BasicUser.Username)
|
||||
@@ -410,8 +412,9 @@ func TestPostActionProps(t *testing.T) {
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
request := model.PostActionIntegrationRequestFromJson(r.Body)
|
||||
assert.NotNil(t, request)
|
||||
var request model.PostActionIntegrationRequest
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&request)
|
||||
assert.NoError(t, jsonErr)
|
||||
|
||||
fmt.Fprintf(w, `{
|
||||
"update": {
|
||||
@@ -536,6 +539,8 @@ func TestSubmitInteractiveDialog(t *testing.T) {
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
@@ -553,7 +558,8 @@ func TestSubmitInteractiveDialog(t *testing.T) {
|
||||
Errors: map[string]string{"name1": errReply},
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(response.ToJson())
|
||||
responseJSON, _ := json.Marshal(response)
|
||||
_, _ = w.Write(responseJSON)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -606,8 +612,9 @@ func TestPostActionRelativeURL(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
request := model.PostActionIntegrationRequestFromJson(r.Body)
|
||||
assert.NotNil(t, request)
|
||||
var request model.PostActionIntegrationRequest
|
||||
jsonErr := json.NewDecoder(r.Body).Decode(&request)
|
||||
assert.NoError(t, jsonErr)
|
||||
fmt.Fprintf(w, `{"post": {"message": "updated"}, "ephemeral_text": "foo"}`)
|
||||
}))
|
||||
defer ts.Close()
|
||||
@@ -824,6 +831,8 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
)
|
||||
@@ -835,7 +844,8 @@ func TestPostActionRelativePluginURL(t *testing.T) {
|
||||
func (p *MyPlugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
response := &model.PostActionIntegrationResponse{}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(response.ToJson())
|
||||
responseJSON, _ := json.Marshal(response)
|
||||
_, _ = w.Write(responseJSON)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
+22
-9
@@ -5,9 +5,9 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
@@ -100,7 +100,11 @@ func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppErr
|
||||
if !success {
|
||||
return nil, model.NewAppError("addLicense", model.InvalidLicenseError, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||
|
||||
var license model.License
|
||||
if jsonErr := json.Unmarshal([]byte(licenseStr), &license); jsonErr != nil {
|
||||
return nil, model.NewAppError("addLicense", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
uniqueUserCount, err := s.Store.User().Count(model.UserCountOptions{})
|
||||
if err != nil {
|
||||
@@ -111,11 +115,11 @@ func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppErr
|
||||
return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if license != nil && license.IsExpired() {
|
||||
if license.IsExpired() {
|
||||
return nil, model.NewAppError("addLicense", model.ExpiredLicenseError, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if ok := s.SetLicense(license); !ok {
|
||||
if ok := s.SetLicense(&license); !ok {
|
||||
return nil, model.NewAppError("addLicense", model.ExpiredLicenseError, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -165,7 +169,7 @@ func (s *Server) SaveLicense(licenseBytes []byte) (*model.License, *model.AppErr
|
||||
}
|
||||
}
|
||||
|
||||
return license, nil
|
||||
return &license, nil
|
||||
}
|
||||
|
||||
func (s *Server) SetLicense(license *model.License) bool {
|
||||
@@ -196,8 +200,12 @@ func (s *Server) SetLicense(license *model.License) bool {
|
||||
|
||||
func (s *Server) ValidateAndSetLicenseBytes(b []byte) bool {
|
||||
if success, licenseStr := utils.LicenseValidator.ValidateLicense(b); success {
|
||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||
s.SetLicense(license)
|
||||
var license model.License
|
||||
if jsonErr := json.Unmarshal([]byte(licenseStr), &license); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode license from JSON", mlog.Err(jsonErr))
|
||||
return false
|
||||
}
|
||||
s.SetLicense(&license)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -254,12 +262,17 @@ func (s *Server) GetSanitizedClientLicense() map[string]string {
|
||||
|
||||
// RequestTrialLicense request a trial license from the mattermost official license server
|
||||
func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *model.AppError {
|
||||
resp, err := http.Post(RequestTrialURL, "application/json", bytes.NewBuffer([]byte(trialRequest.ToJson())))
|
||||
trialRequestJSON, jsonErr := json.Marshal(trialRequest)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("RequestTrialLicense", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
resp, err := http.Post(RequestTrialURL, "application/json", bytes.NewBuffer(trialRequestJSON))
|
||||
if err != nil {
|
||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
licenseResponse := model.MapFromJson(resp.Body)
|
||||
licenseResponse := model.MapFromJSON(resp.Body)
|
||||
|
||||
if _, ok := licenseResponse["license"]; !ok {
|
||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, licenseResponse["message"], http.StatusBadRequest)
|
||||
|
||||
+14
-4
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -524,7 +525,11 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPosted, "", post.ChannelId, "", nil)
|
||||
|
||||
// Note that PreparePostForClient should've already been called by this point
|
||||
message.Add("post", post.ToJson())
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
if jsonErr != nil {
|
||||
return nil, errors.Wrapf(jsonErr, "failed to encode post to JSON")
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
|
||||
message.Add("channel_type", channel.Type)
|
||||
message.Add("channel_display_name", notification.GetChannelName(model.ShowUsername, ""))
|
||||
@@ -552,11 +557,11 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
|
||||
if len(mentionedUsersList) != 0 {
|
||||
message.Add("mentions", model.ArrayToJson(mentionedUsersList))
|
||||
message.Add("mentions", model.ArrayToJSON(mentionedUsersList))
|
||||
}
|
||||
|
||||
if len(notificationsForCRT.Desktop) != 0 {
|
||||
message.Add("followers", model.ArrayToJson(notificationsForCRT.Desktop))
|
||||
message.Add("followers", model.ArrayToJSON(notificationsForCRT.Desktop))
|
||||
}
|
||||
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(post, message)
|
||||
@@ -607,7 +612,12 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
}
|
||||
|
||||
message.Add("thread", userThread.ToJson())
|
||||
payload, jsonErr := json.Marshal(userThread)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message.Add("thread", string(payload))
|
||||
|
||||
a.Publish(message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -367,8 +369,13 @@ func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Sessio
|
||||
mlog.String("status", model.PushSendPrepare),
|
||||
)
|
||||
|
||||
msgJSON, jsonErr := json.Marshal(msg)
|
||||
if jsonErr != nil {
|
||||
return errors.Wrap(jsonErr, "failed to encode to JSON")
|
||||
}
|
||||
|
||||
url := strings.TrimRight(*a.Config().EmailSettings.PushNotificationServer, "/") + model.APIURLSuffixV1 + "/send_push"
|
||||
request, err := http.NewRequest("POST", url, strings.NewReader(msg.ToJson()))
|
||||
request, err := http.NewRequest("POST", url, bytes.NewReader(msgJSON))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -379,7 +386,10 @@ func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Sessio
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
pushResponse := model.PushResponseFromJson(resp.Body)
|
||||
var pushResponse model.PushResponse
|
||||
if jsonErr := json.NewDecoder(resp.Body).Decode(&pushResponse); jsonErr != nil {
|
||||
return errors.Wrap(jsonErr, "failed to decode from JSON")
|
||||
}
|
||||
|
||||
switch pushResponse[model.PushStatus] {
|
||||
case model.PushStatusRemove:
|
||||
@@ -405,10 +415,15 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
|
||||
mlog.String("status", model.PushReceived),
|
||||
)
|
||||
|
||||
ackJSON, jsonErr := json.Marshal(ack)
|
||||
if jsonErr != nil {
|
||||
return errors.Wrap(jsonErr, "failed to encode to JSON")
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(
|
||||
"POST",
|
||||
strings.TrimRight(*a.Config().EmailSettings.PushNotificationServer, "/")+model.APIURLSuffixV1+"/ack",
|
||||
strings.NewReader(ack.ToJson()),
|
||||
bytes.NewReader(ackJSON),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -1024,18 +1025,19 @@ func (h *testPushNotificationHandler) handleReq(w http.ResponseWriter, r *http.R
|
||||
// Don't do any checking if it's a benchmark
|
||||
if _, ok := h.t.(*testing.B); ok {
|
||||
resp := model.NewOkPushResponse()
|
||||
fmt.Fprintln(w, (&resp).ToJson())
|
||||
jsonData, _ := json.Marshal(&resp)
|
||||
fmt.Fprintln(w, jsonData)
|
||||
return
|
||||
}
|
||||
|
||||
var notification *model.PushNotification
|
||||
var notificationAck *model.PushNotificationAck
|
||||
var notification model.PushNotification
|
||||
var notificationAck model.PushNotificationAck
|
||||
var err error
|
||||
if r.URL.Path == "/api/v1/send_push" {
|
||||
notification, err = model.PushNotificationFromJson(r.Body)
|
||||
if err != nil {
|
||||
if err = json.NewDecoder(r.Body).Decode(¬ification); err != nil {
|
||||
resp := model.NewErrorPushResponse("fail")
|
||||
fmt.Fprintln(w, (&resp).ToJson())
|
||||
jsonData, _ := json.Marshal(&resp)
|
||||
fmt.Fprintln(w, jsonData)
|
||||
return
|
||||
}
|
||||
// We verify that messages are being sent in order per-device.
|
||||
@@ -1047,10 +1049,10 @@ func (h *testPushNotificationHandler) handleReq(w http.ResponseWriter, r *http.R
|
||||
defer h.serialUserMap.Delete(notification.DeviceId)
|
||||
}
|
||||
} else {
|
||||
notificationAck, err = model.PushNotificationAckFromJson(r.Body)
|
||||
if err != nil {
|
||||
if err = json.NewDecoder(r.Body).Decode(¬ificationAck); err != nil {
|
||||
resp := model.NewErrorPushResponse("fail")
|
||||
fmt.Fprintln(w, (&resp).ToJson())
|
||||
jsonData, _ := json.Marshal(&resp)
|
||||
fmt.Fprintln(w, jsonData)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1061,9 +1063,9 @@ func (h *testPushNotificationHandler) handleReq(w http.ResponseWriter, r *http.R
|
||||
// Little bit of duplicate condition check so that we can check the in-order property
|
||||
// first.
|
||||
if r.URL.Path == "/api/v1/send_push" {
|
||||
h._notifications = append(h._notifications, notification)
|
||||
h._notifications = append(h._notifications, ¬ification)
|
||||
} else {
|
||||
h._notificationAcks = append(h._notificationAcks, notificationAck)
|
||||
h._notificationAcks = append(h._notificationAcks, ¬ificationAck)
|
||||
}
|
||||
|
||||
var resp model.PushResponse
|
||||
@@ -1077,7 +1079,8 @@ func (h *testPushNotificationHandler) handleReq(w http.ResponseWriter, r *http.R
|
||||
resp = model.NewRemovePushResponse()
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, (&resp).ToJson())
|
||||
jsonData, _ := json.Marshal(&resp)
|
||||
fmt.Fprintln(w, jsonData)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -582,7 +582,7 @@ func (a *App) LoginByOAuth(c *request.Context, service string, userData io.Reade
|
||||
map[string]interface{}{"Service": service}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
authUser, err1 := provider.GetUserFromJson(bytes.NewReader(buf.Bytes()), tokenUser)
|
||||
authUser, err1 := provider.GetUserFromJSON(bytes.NewReader(buf.Bytes()), tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
@@ -633,7 +633,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
ssoUser, err1 := provider.GetUserFromJson(userData, tokenUser)
|
||||
ssoUser, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.parse.app_error",
|
||||
map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
@@ -744,7 +744,7 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
|
||||
}
|
||||
|
||||
props["token"] = stateToken.Token
|
||||
state := b64.StdEncoding.EncodeToString([]byte(model.MapToJson(props)))
|
||||
state := b64.StdEncoding.EncodeToString([]byte(model.MapToJSON(props)))
|
||||
|
||||
siteURL := a.GetSiteURL()
|
||||
if strings.TrimSpace(siteURL) == "" {
|
||||
@@ -783,7 +783,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
}
|
||||
|
||||
stateStr := string(b)
|
||||
stateProps := model.MapFromJson(strings.NewReader(stateStr))
|
||||
stateProps := model.MapFromJSON(strings.NewReader(stateStr))
|
||||
|
||||
expectedToken, appErr := a.GetOAuthStateToken(stateProps["token"])
|
||||
if appErr != nil {
|
||||
|
||||
+4
-4
@@ -152,7 +152,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
}
|
||||
|
||||
makeState := func(token *model.Token) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(model.MapToJson(map[string]string{
|
||||
return base64.StdEncoding.EncodeToString([]byte(model.MapToJSON(map[string]string{
|
||||
"token": token.Token,
|
||||
})))
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
th := setup(t, true, true, true, "")
|
||||
defer th.TearDown()
|
||||
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(map[string]string{
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJSON(map[string]string{
|
||||
"token": model.NewId(),
|
||||
})))
|
||||
|
||||
@@ -235,7 +235,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
token, err := th.App.CreateOAuthStateToken(generateOAuthStateTokenExtra(email, action, cookie))
|
||||
require.Nil(t, err)
|
||||
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(map[string]string{
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJSON(map[string]string{
|
||||
"action": action,
|
||||
"email": email,
|
||||
"token": token.Token,
|
||||
@@ -489,7 +489,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
"team_id": model.NewId(),
|
||||
"token": makeToken(th, cookie).Token,
|
||||
}
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJSON(stateProps)))
|
||||
|
||||
recorder := httptest.ResponseRecorder{}
|
||||
body, receivedTeamId, receivedStateProps, _, err := th.App.AuthorizeOAuthUser(&recorder, request, model.ServiceGitlab, "", state, "")
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -32,9 +32,17 @@ func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Req
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
req := model.WebSocketRequestFromJson(bytes.NewReader(msg))
|
||||
var req model.WebSocketRequest
|
||||
err = json.Unmarshal(msg, &req)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
resp := model.NewWebSocketResponse("OK", req.Seq, map[string]interface{}{"action": req.Action, "value": req.Data["value"]})
|
||||
if err = ws.WriteMessage(mt, resp.ToJson()); err != nil {
|
||||
respJSON, err := resp.ToJSON()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if err = ws.WriteMessage(mt, respJSON); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -99,8 +100,10 @@ func TestInstallPluginLocally(t *testing.T) {
|
||||
Id: id,
|
||||
Version: version,
|
||||
}
|
||||
manifestJSON, jsonErr := json.Marshal(manifest)
|
||||
require.NoError(t, jsonErr)
|
||||
reader := makeInMemoryGzipTarFile(t, []testFile{
|
||||
{"plugin.json", manifest.ToJson()},
|
||||
{"plugin.json", string(manifestJSON)},
|
||||
})
|
||||
|
||||
actualManifest, appError := th.App.installPluginLocally(reader, nil, installationStrategy)
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s *Server) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
||||
s.Log.Error(err.Error())
|
||||
w.WriteHeader(err.StatusCode)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(err.ToJson()))
|
||||
w.Write([]byte(err.ToJSON()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (a *App) ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, so
|
||||
a.Log().Error(err.Error())
|
||||
w.WriteHeader(err.StatusCode)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(err.ToJson()))
|
||||
w.Write([]byte(err.ToJSON()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+27
-5
@@ -522,7 +522,12 @@ func (a *App) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventEphemeralMessage, "", post.ChannelId, userID, nil)
|
||||
post = a.PreparePostForClient(post, true, false)
|
||||
post = model.AddPostActionCookies(post, a.PostActionCookieSecret())
|
||||
message.Add("post", post.ToJson())
|
||||
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
a.Publish(message)
|
||||
|
||||
return post
|
||||
@@ -540,7 +545,11 @@ func (a *App) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPostEdited, "", post.ChannelId, userID, nil)
|
||||
post = a.PreparePostForClient(post, true, false)
|
||||
post = model.AddPostActionCookies(post, a.PostActionCookieSecret())
|
||||
message.Add("post", post.ToJson())
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
a.Publish(message)
|
||||
|
||||
return post
|
||||
@@ -556,7 +565,11 @@ func (a *App) DeleteEphemeralPost(userID, postID string) {
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPostDeleted, "", "", userID, nil)
|
||||
message.Add("post", post.ToJson())
|
||||
postJSON, jsonErr := post.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
@@ -684,7 +697,11 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPostEdited, "", rpost.ChannelId, "", nil)
|
||||
message.Add("post", rpost.ToJson())
|
||||
postJSON, jsonErr := rpost.ToJSON()
|
||||
if jsonErr != nil {
|
||||
return nil, model.NewAppError("UpdatePost", "app.post.marshal.app_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
message.Add("post", postJSON)
|
||||
|
||||
published, err := a.publishWebsocketEventForPermalinkPost(rpost, message)
|
||||
if err != nil {
|
||||
@@ -744,7 +761,12 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
|
||||
broadcastCopy := messageCopy.GetBroadcast()
|
||||
broadcastCopy.UserId = cm.UserId
|
||||
messageCopy.SetBroadcast(broadcastCopy)
|
||||
messageCopy.Add("post", postForUser.ToJson())
|
||||
|
||||
postJSON, jsonErr := postForUser.ToJSON()
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode post to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
messageCopy.Add("post", postJSON)
|
||||
a.Publish(messageCopy)
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -4,10 +4,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
||||
@@ -65,7 +67,11 @@ func (a *App) UpdatePreferences(userID string, preferences model.Preferences) *m
|
||||
a.Publish(message)
|
||||
|
||||
message = model.NewWebSocketEvent(model.WebsocketEventPreferencesChanged, "", "", userID, nil)
|
||||
message.Add("preferences", preferences.ToJson())
|
||||
prefsJSON, jsonErr := json.Marshal(preferences)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("preferences", string(prefsJSON))
|
||||
a.Publish(message)
|
||||
|
||||
return nil
|
||||
@@ -95,7 +101,11 @@ func (a *App) DeletePreferences(userID string, preferences model.Preferences) *m
|
||||
a.Publish(message)
|
||||
|
||||
message = model.NewWebSocketEvent(model.WebsocketEventPreferencesDeleted, "", "", userID, nil)
|
||||
message.Add("preferences", preferences.ToJson())
|
||||
prefsJSON, jsonErr := json.Marshal(preferences)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("preferences", string(prefsJSON))
|
||||
a.Publish(message)
|
||||
|
||||
return nil
|
||||
|
||||
+7
-1
@@ -4,12 +4,14 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
||||
@@ -159,6 +161,10 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction
|
||||
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) {
|
||||
// send out that a reaction has been added/removed
|
||||
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil)
|
||||
message.Add("reaction", reaction.ToJson())
|
||||
reactionJSON, jsonErr := json.Marshal(reaction)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode reaction to JSON")
|
||||
}
|
||||
message.Add("reaction", string(reactionJSON))
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
+7
-1
@@ -5,12 +5,14 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
)
|
||||
@@ -240,7 +242,11 @@ func (a *App) CheckRolesExist(roleNames []string) *model.AppError {
|
||||
|
||||
func (a *App) sendUpdatedRoleEvent(role *model.Role) {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventRoleUpdated, "", "", "", nil)
|
||||
message.Add("role", role.ToJson())
|
||||
roleJSON, jsonErr := json.Marshal(role)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode role to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("role", string(roleJSON))
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.Publish(message)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -88,7 +89,11 @@ func (s *Server) DoSecurityUpdateCheck() {
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
bulletins := model.SecurityBulletinsFromJson(res.Body)
|
||||
var bulletins model.SecurityBulletins
|
||||
if jsonErr := json.NewDecoder(res.Body).Decode(&bulletins); jsonErr != nil {
|
||||
mlog.Error("Failed to decode JSON", mlog.Err(jsonErr))
|
||||
return
|
||||
}
|
||||
|
||||
for _, bulletin := range bulletins {
|
||||
if bulletin.AppliesToVersion == model.CurrentVersion {
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app"
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
type ExpandProvider struct {
|
||||
@@ -75,7 +77,12 @@ func setCollapsePreference(a *app.App, args *model.CommandArgs, isCollapse bool)
|
||||
}
|
||||
|
||||
socketMessage := model.NewWebSocketEvent(model.WebsocketEventPreferenceChanged, "", "", args.UserId, nil)
|
||||
socketMessage.Add("preference", pref.ToJson())
|
||||
|
||||
prefJSON, jsonErr := json.Marshal(pref)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
socketMessage.Add("preference", string(prefJSON))
|
||||
a.Publish(socketMessage)
|
||||
|
||||
var rmsg string
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -542,8 +543,8 @@ func (*LoadTestProvider) JsonCommand(a *app.App, c *request.Context, args *model
|
||||
r.Body.Close()
|
||||
}()
|
||||
|
||||
post := model.PostFromJson(r.Body)
|
||||
if post == nil {
|
||||
var post model.Post
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
|
||||
return &model.CommandResponse{Text: "Unable to decode post", ResponseType: model.CommandResponseTypeEphemeral}, errors.Errorf("could not decode post from json")
|
||||
}
|
||||
post.ChannelId = args.ChannelId
|
||||
@@ -552,7 +553,7 @@ func (*LoadTestProvider) JsonCommand(a *app.App, c *request.Context, args *model
|
||||
post.Message = message
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostMissingChannel(c, post, false); err != nil {
|
||||
if _, err := a.CreatePostMissingChannel(c, &post, false); err != nil {
|
||||
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ func TestShareProviderDoCommand(t *testing.T) {
|
||||
require.Equal(t, "##### "+args.T("api.command_share.channel_shared"), response.Text)
|
||||
|
||||
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
||||
event := model.WebSocketEventFromJson(bytes.NewReader(msg.Data))
|
||||
return event != nil && event.EventType() == model.WebsocketEventChannelConverted
|
||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||
return err == nil && event.EventType() == model.WebsocketEventChannelConverted
|
||||
})
|
||||
assert.Len(t, channelConvertedMessages, 1)
|
||||
})
|
||||
@@ -85,8 +85,8 @@ func TestShareProviderDoCommand(t *testing.T) {
|
||||
require.Equal(t, "##### "+args.T("api.command_share.shared_channel_unavailable"), response.Text)
|
||||
|
||||
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
||||
event := model.WebSocketEventFromJson(bytes.NewReader(msg.Data))
|
||||
return event != nil && event.EventType() == model.WebsocketEventChannelConverted
|
||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||
return err == nil && event.EventType() == model.WebsocketEventChannelConverted
|
||||
})
|
||||
require.Len(t, channelConvertedMessages, 1)
|
||||
})
|
||||
|
||||
+30
-8
@@ -4,9 +4,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@@ -21,10 +21,14 @@ func (a *App) AddStatusCache(status *model.Status) {
|
||||
a.AddStatusCacheSkipClusterSend(status)
|
||||
|
||||
if a.Cluster() != nil {
|
||||
statusJSON, jsonErr := json.Marshal(status)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode status to JSON")
|
||||
}
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.ClusterEventUpdateStatus,
|
||||
SendType: model.ClusterSendBestEffort,
|
||||
Data: []byte(status.ToClusterJson()),
|
||||
Data: statusJSON,
|
||||
}
|
||||
a.Cluster().SendClusterMessage(msg)
|
||||
}
|
||||
@@ -443,15 +447,22 @@ func (a *App) addRecentCustomStatus(userID string, status *model.CustomStatus) *
|
||||
if err != nil || pref.Value == "" {
|
||||
newRCS = model.RecentCustomStatuses{*status}
|
||||
} else {
|
||||
existingRCS := model.RecentCustomStatusesFromJson(strings.NewReader(pref.Value))
|
||||
var existingRCS model.RecentCustomStatuses
|
||||
if jsonErr := json.Unmarshal([]byte(pref.Value), &existingRCS); jsonErr != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
newRCS = existingRCS.Add(status)
|
||||
}
|
||||
|
||||
newRCSJSON, jsonErr := json.Marshal(newRCS)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
pref = &model.Preference{
|
||||
UserId: userID,
|
||||
Category: model.PreferenceCategoryCustomStatus,
|
||||
Name: model.PreferenceNameRecentCustomStatuses,
|
||||
Value: newRCS.ToJson(),
|
||||
Value: string(newRCSJSON),
|
||||
}
|
||||
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
|
||||
return err
|
||||
@@ -470,14 +481,25 @@ func (a *App) RemoveRecentCustomStatus(userID string, status *model.CustomStatus
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
existingRCS := model.RecentCustomStatusesFromJson(strings.NewReader(pref.Value))
|
||||
if !existingRCS.Contains(status) {
|
||||
var existingRCS model.RecentCustomStatuses
|
||||
if jsonErr := json.Unmarshal([]byte(pref.Value), &existingRCS); jsonErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if ok, err := existingRCS.Contains(status); !ok || err != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
newRCS := existingRCS.Remove(status)
|
||||
pref.Value = newRCS.ToJson()
|
||||
newRCS, removeErr := existingRCS.Remove(status)
|
||||
if removeErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, removeErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
newRCSJSON, jsonErr := json.Marshal(newRCS)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
pref.Value = string(newRCSJSON)
|
||||
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+18
-5
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
@@ -337,7 +338,11 @@ func (a *App) sendTeamEvent(team *model.Team, event string) {
|
||||
teamID = team.Id
|
||||
}
|
||||
message := model.NewWebSocketEvent(event, teamID, "", "", nil)
|
||||
message.Add("team", sanitizedTeam.ToJson())
|
||||
teamJSON, jsonErr := json.Marshal(team)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode team to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("team", string(teamJSON))
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
@@ -479,7 +484,11 @@ func (a *App) UpdateTeamMemberSchemeRoles(teamID string, userID string, isScheme
|
||||
|
||||
func (a *App) sendUpdatedMemberRoleEvent(userID string, member *model.TeamMember) {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventMemberroleUpdated, "", "", userID, nil)
|
||||
message.Add("member", member.ToJson())
|
||||
tmJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode team member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("member", string(tmJSON))
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
@@ -563,7 +572,7 @@ func (a *App) AddUserToTeamByToken(c *request.Context, userID string, tokenID st
|
||||
return nil, nil, model.NewAppError("AddUserToTeamByToken", "api.user.create_user.signup_link_expired.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tokenData := model.MapFromJson(strings.NewReader(token.Extra))
|
||||
tokenData := model.MapFromJSON(strings.NewReader(token.Extra))
|
||||
|
||||
tchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
@@ -1862,7 +1871,7 @@ func (a *App) GetTeamIdFromQuery(query url.Values) (string, *model.AppError) {
|
||||
return "", model.NewAppError("GetTeamIdFromQuery", "api.oauth.singup_with_oauth.expired_link.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tokenData := model.MapFromJson(strings.NewReader(token.Extra))
|
||||
tokenData := model.MapFromJSON(strings.NewReader(token.Extra))
|
||||
|
||||
return tokenData["teamId"], nil
|
||||
}
|
||||
@@ -2027,7 +2036,11 @@ func (a *App) ClearTeamMembersCache(teamID string) {
|
||||
a.ClearSessionCacheForUser(teamMember.UserId)
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventMemberroleUpdated, "", "", teamMember.UserId, nil)
|
||||
message.Add("member", teamMember.ToJson())
|
||||
tmJSON, jsonErr := json.Marshal(teamMember)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode team member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
message.Add("member", string(tmJSON))
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -202,7 +202,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("invalid token type", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeVerifyEmail,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
@@ -215,7 +215,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("expired token", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
|
||||
token.CreateAt = model.GetMillis() - InvitationExpiryTime - 1
|
||||
@@ -229,7 +229,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("invalid team id", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": model.NewId()}),
|
||||
model.MapToJSON(map[string]string{"teamId": model.NewId()}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -241,7 +241,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("invalid user id", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -253,7 +253,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("valid request", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, ruser.Id, token.Token)
|
||||
@@ -270,7 +270,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("invalid add a guest using a regular invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, rguest.Id, token.Token)
|
||||
@@ -280,7 +280,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("invalid add a regular user using a guest invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, ruser.Id, token.Token)
|
||||
@@ -295,7 +295,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.RestrictCreationToDomains = "restricted.com" })
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
_, _, err := th.App.AddUserToTeamByToken(th.Context, rguest.Id, token.Token)
|
||||
@@ -311,7 +311,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.RestrictCreationToDomains = "restricted.com" })
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
guestEmail := rguest.Email
|
||||
rguest.Email = "test@restricted.com"
|
||||
@@ -337,7 +337,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictCreationToDomains = "restricted.com" })
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
_, err = th.App.Srv().Store.User().Update(rguest, false)
|
||||
require.NoError(t, err)
|
||||
@@ -352,7 +352,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
t.Run("valid request from guest invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -375,7 +375,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -399,7 +399,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
@@ -414,7 +414,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
|
||||
+13
-5
@@ -54,7 +54,7 @@ func (a *App) CreateUserWithToken(c *request.Context, user *model.User, token *m
|
||||
return nil, model.NewAppError("CreateUserWithToken", "api.user.create_user.signup_link_expired.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tokenData := model.MapFromJson(strings.NewReader(token.Extra))
|
||||
tokenData := model.MapFromJSON(strings.NewReader(token.Extra))
|
||||
|
||||
team, nErr := a.Srv().Store.Team().Get(tokenData["teamId"])
|
||||
if nErr != nil {
|
||||
@@ -294,7 +294,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
user, err1 := provider.GetUserFromJson(userData, tokenUser)
|
||||
user, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, err1.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -1816,7 +1816,7 @@ func (a *App) AutocompleteUsersInTeam(teamID string, term string, options *model
|
||||
}
|
||||
|
||||
func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError {
|
||||
oauthUser, err1 := provider.GetUserFromJson(userData, tokenUser)
|
||||
oauthUser, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]interface{}{"Service": service}, err1.Error(), http.StatusBadRequest)
|
||||
}
|
||||
@@ -2060,7 +2060,11 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
a.invalidateCacheForChannelMembers(member.ChannelId)
|
||||
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil)
|
||||
evt.Add("channelMember", member.ToJson())
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
}
|
||||
}
|
||||
@@ -2101,7 +2105,11 @@ func (a *App) DemoteUserToGuest(user *model.User) *model.AppError {
|
||||
a.invalidateCacheForChannelMembers(member.ChannelId)
|
||||
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil)
|
||||
evt.Add("channelMember", member.ToJson())
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -38,9 +38,10 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
|
||||
t.Run("create user successfully", func(t *testing.T) {
|
||||
glUser := oauthgitlab.GitLabUser{Id: 42, Username: "o" + model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
|
||||
json := glUser.ToJson()
|
||||
js, jsonErr := json.Marshal(glUser)
|
||||
require.NoError(t, jsonErr)
|
||||
|
||||
user, err := th.App.CreateOAuthUser(th.Context, model.UserAuthServiceGitlab, strings.NewReader(json), th.BasicTeam.Id, nil)
|
||||
user, err := th.App.CreateOAuthUser(th.Context, model.UserAuthServiceGitlab, bytes.NewReader(js), th.BasicTeam.Id, nil)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, glUser.Username, user.Username, "usernames didn't match")
|
||||
@@ -59,7 +60,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
mockUser := &model.User{Id: "abcdef", AuthData: model.NewString("e7110007-64be-43d8-9840-4a7e9c26b710"), Email: dbUser.Email}
|
||||
providerMock := &mocks.OAuthProvider{}
|
||||
providerMock.On("IsSameUser", mock.Anything, mock.Anything).Return(true)
|
||||
providerMock.On("GetUserFromJson", mock.Anything, mock.Anything).Return(mockUser, nil)
|
||||
providerMock.On("GetUserFromJSON", mock.Anything, mock.Anything).Return(mockUser, nil)
|
||||
einterfaces.RegisterOAuthProvider(model.ServiceOffice365, providerMock)
|
||||
|
||||
// Update user to be OAuth, formatting to match Office365 OAuth data
|
||||
@@ -734,7 +735,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
t.Run("invalid token type", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeVerifyEmail,
|
||||
model.MapToJson(map[string]string{"teamID": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamID": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -745,7 +746,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
t.Run("expired token", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
token.CreateAt = model.GetMillis() - InvitationExpiryTime - 1
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
@@ -757,7 +758,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
t.Run("invalid team id", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": model.NewId(), "email": user.Email}),
|
||||
model.MapToJSON(map[string]string{"teamId": model.NewId(), "email": user.Email}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
@@ -769,7 +770,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
invitationEmail := model.NewId() + "other-email@test.com"
|
||||
token := model.NewToken(
|
||||
TokenTypeTeamInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
newUser, err := th.App.CreateUserWithToken(th.Context, &user, token)
|
||||
@@ -789,7 +790,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
invitationEmail := model.NewId() + "other-email@test.com"
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
guest := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
@@ -819,11 +820,11 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
grantedInvitationEmail := model.NewId() + "other-email@restricted.com"
|
||||
forbiddenDomainToken := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": forbiddenInvitationEmail, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": forbiddenInvitationEmail, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
grantedDomainToken := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": grantedInvitationEmail, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": grantedInvitationEmail, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(forbiddenDomainToken))
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(grantedDomainToken))
|
||||
@@ -866,7 +867,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
invitationEmail := model.NewId() + "other-email@test.com"
|
||||
token := model.NewToken(
|
||||
TokenTypeGuestInvitation,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail, "channels": th.BasicChannel.Id}),
|
||||
model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.NoError(t, th.App.Srv().Store.Token().Save(token))
|
||||
guest := model.User{
|
||||
|
||||
@@ -254,10 +254,13 @@ func TestWebConnDrainDeadQueue(t *testing.T) {
|
||||
i := seqNum
|
||||
for err == nil {
|
||||
_, buf, err = conn.ReadMessage()
|
||||
ev := model.WebSocketEventFromJson(bytes.NewReader(buf))
|
||||
require.LessOrEqual(t, int(i), limit)
|
||||
assert.Equal(t, i, ev.GetSequence())
|
||||
i++
|
||||
if err != nil && len(buf) > 0 {
|
||||
ev, jsonErr := model.WebSocketEventFromJSON(bytes.NewReader(buf))
|
||||
require.NoError(t, jsonErr)
|
||||
require.LessOrEqual(t, int(i), limit)
|
||||
assert.Equal(t, i, ev.GetSequence())
|
||||
i++
|
||||
}
|
||||
}
|
||||
if _, ok := err.(*websocket.CloseError); !ok {
|
||||
require.NoError(t, err)
|
||||
|
||||
+5
-1
@@ -168,10 +168,14 @@ func (s *Server) Publish(message *model.WebSocketEvent) {
|
||||
s.PublishSkipClusterSend(message)
|
||||
|
||||
if s.Cluster != nil {
|
||||
data, err := message.ToJSON()
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to encode message to JSON", mlog.Err(err))
|
||||
}
|
||||
cm := &model.ClusterMessage{
|
||||
Event: model.ClusterEventPublish,
|
||||
SendType: model.ClusterSendBestEffort,
|
||||
Data: message.ToJson(),
|
||||
Data: data,
|
||||
}
|
||||
|
||||
if message.EventType() == model.WebsocketEventPosted ||
|
||||
|
||||
+18
-4
@@ -4,7 +4,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -96,7 +98,11 @@ func (a *App) TriggerWebhook(c *request.Context, payload *model.OutgoingWebhookP
|
||||
var body io.Reader
|
||||
var contentType string
|
||||
if hook.ContentType == "application/json" {
|
||||
body = strings.NewReader(payload.ToJSON())
|
||||
js, jsonErr := json.Marshal(payload)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
body = bytes.NewReader(js)
|
||||
contentType = "application/json"
|
||||
} else {
|
||||
body = strings.NewReader(payload.ToFormValues())
|
||||
@@ -164,7 +170,15 @@ func (a *App) doOutgoingWebhookRequest(url string, body io.Reader, contentType s
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
return model.OutgoingWebhookResponseFromJson(io.LimitReader(resp.Body, MaxIntegrationResponseSize))
|
||||
var hookResp model.OutgoingWebhookResponse
|
||||
if jsonErr := json.NewDecoder(io.LimitReader(resp.Body, MaxIntegrationResponseSize)).Decode(&hookResp); jsonErr != nil {
|
||||
if jsonErr == io.EOF {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, model.NewAppError("doOutgoingWebhookRequest", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return &hookResp, nil
|
||||
}
|
||||
|
||||
func SplitWebhookPost(post *model.Post, maxPostSize int) ([]*model.Post, *model.AppError) {
|
||||
@@ -180,7 +194,7 @@ func SplitWebhookPost(post *model.Post, maxPostSize int) ([]*model.Post, *model.
|
||||
}
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(model.StringInterfaceToJson(base.GetProps())) > model.PostPropsMaxUserRunes {
|
||||
if utf8.RuneCountInString(model.StringInterfaceToJSON(base.GetProps())) > model.PostPropsMaxUserRunes {
|
||||
return nil, model.NewAppError("SplitWebhookPost", "web.incoming_webhook.split_props_length.app_error", map[string]interface{}{"Max": model.PostPropsMaxUserRunes}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -213,7 +227,7 @@ func SplitWebhookPost(post *model.Post, maxPostSize int) ([]*model.Post, *model.
|
||||
}
|
||||
origAttachments, _ := newProps["attachments"].([]*model.SlackAttachment)
|
||||
newProps["attachments"] = append(origAttachments, &newAttachment)
|
||||
newPropsString := model.StringInterfaceToJson(newProps)
|
||||
newPropsString := model.StringInterfaceToJSON(newProps)
|
||||
runeCount := utf8.RuneCountInString(newPropsString)
|
||||
|
||||
if runeCount <= model.PostPropsMaxUserRunes {
|
||||
|
||||
+6
-4
@@ -673,7 +673,9 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if testCase.WebhookResponse != nil {
|
||||
w.Write([]byte(testCase.WebhookResponse.ToJson()))
|
||||
js, jsonErr := json.Marshal(testCase.WebhookResponse)
|
||||
require.NoError(t, jsonErr)
|
||||
w.Write(js)
|
||||
} else {
|
||||
w.Write([]byte(`{"text": "sample response text from test server"}`))
|
||||
}
|
||||
@@ -755,7 +757,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
|
||||
|
||||
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
|
||||
require.Error(t, err)
|
||||
require.IsType(t, &json.SyntaxError{}, err)
|
||||
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
||||
})
|
||||
|
||||
t.Run("with a large, valid response", func(t *testing.T) {
|
||||
@@ -766,7 +768,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
|
||||
|
||||
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, io.ErrUnexpectedEOF, err)
|
||||
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
||||
})
|
||||
|
||||
t.Run("with a large, invalid response", func(t *testing.T) {
|
||||
@@ -777,7 +779,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
|
||||
|
||||
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
|
||||
require.Error(t, err)
|
||||
require.IsType(t, &json.SyntaxError{}, err)
|
||||
require.Equal(t, "api.unmarshal_error", err.(*model.AppError).Id)
|
||||
})
|
||||
|
||||
t.Run("with a slow response", func(t *testing.T) {
|
||||
|
||||
@@ -62,8 +62,8 @@ func (_m *OAuthProvider) GetUserFromIdToken(idToken string) (*model.User, error)
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetUserFromJson provides a mock function with given fields: data, tokenUser
|
||||
func (_m *OAuthProvider) GetUserFromJson(data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
// GetUserFromJSON provides a mock function with given fields: data, tokenUser
|
||||
func (_m *OAuthProvider) GetUserFromJSON(data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
ret := _m.Called(data, tokenUser)
|
||||
|
||||
var r0 *model.User
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type OAuthProvider interface {
|
||||
GetUserFromJson(data io.Reader, tokenUser *model.User) (*model.User, error)
|
||||
GetUserFromJSON(data io.Reader, tokenUser *model.User) (*model.User, error)
|
||||
GetSSOSettings(config *model.Config, service string) (*model.SSOSettings, error)
|
||||
GetUserFromIdToken(idToken string) (*model.User, error)
|
||||
IsSameUser(dbUser, oAuthUser *model.User) bool
|
||||
|
||||
+9
-1
@@ -1970,7 +1970,7 @@
|
||||
},
|
||||
{
|
||||
"id": "api.marshal_error",
|
||||
"translation": "marshal error"
|
||||
"translation": "Failed to marshal."
|
||||
},
|
||||
{
|
||||
"id": "api.migrate_to_saml.error",
|
||||
@@ -3722,6 +3722,10 @@
|
||||
"id": "api.unable_to_read_file_from_backend",
|
||||
"translation": "Error reading file from backend"
|
||||
},
|
||||
{
|
||||
"id": "api.unmarshal_error",
|
||||
"translation": "Failed to unmarshal."
|
||||
},
|
||||
{
|
||||
"id": "api.upgrade_to_enterprise.already-done.app_error",
|
||||
"translation": "You have already upgraded to Mattermost Enterprise Edition. Please restart the server to finish the upgrade."
|
||||
@@ -5810,6 +5814,10 @@
|
||||
"id": "app.post.get_root_posts.app_error",
|
||||
"translation": "Unable to get the posts for the channel."
|
||||
},
|
||||
{
|
||||
"id": "app.post.marshal.app_error",
|
||||
"translation": "Failed to marshal post."
|
||||
},
|
||||
{
|
||||
"id": "app.post.overwrite.app_error",
|
||||
"translation": "Unable to overwrite the Post."
|
||||
|
||||
@@ -19,12 +19,12 @@ type AdvancedPermissionsPhase2Progress struct {
|
||||
LastUserId string `json:"last_user"`
|
||||
}
|
||||
|
||||
func (p *AdvancedPermissionsPhase2Progress) ToJson() string {
|
||||
func (p *AdvancedPermissionsPhase2Progress) ToJSON() string {
|
||||
b, _ := json.Marshal(p)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func AdvancedPermissionsPhase2ProgressFromJson(data io.Reader) *AdvancedPermissionsPhase2Progress {
|
||||
func AdvancedPermissionsPhase2ProgressFromJSON(data io.Reader) *AdvancedPermissionsPhase2Progress {
|
||||
var o *AdvancedPermissionsPhase2Progress
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
@@ -63,9 +63,9 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo
|
||||
progress.LastTeamId = strings.Repeat("0", 26)
|
||||
progress.LastUserId = strings.Repeat("0", 26)
|
||||
} else {
|
||||
progress = AdvancedPermissionsPhase2ProgressFromJson(strings.NewReader(lastDone))
|
||||
progress = AdvancedPermissionsPhase2ProgressFromJSON(strings.NewReader(lastDone))
|
||||
if !progress.IsValid() {
|
||||
return false, "", model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "migrations.worker.run_advanced_permissions_phase_2_migration.invalid_progress", map[string]interface{}{"progress": progress.ToJson()}, "", http.StatusInternalServerError)
|
||||
return false, "", model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "migrations.worker.run_advanced_permissions_phase_2_migration.invalid_progress", map[string]interface{}{"progress": progress.ToJSON()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,13 +73,13 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo
|
||||
// Run a TeamMembers migration batch.
|
||||
result, err := worker.srv.Store.Team().MigrateTeamMembers(progress.LastTeamId, progress.LastUserId)
|
||||
if err != nil {
|
||||
return false, progress.ToJson(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.team.migrate_team_members.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.team.migrate_team_members.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if result == nil {
|
||||
// We haven't progressed. That means that we've reached the end of this stage of the migration, and should now advance to the next stage.
|
||||
progress.LastUserId = strings.Repeat("0", 26)
|
||||
progress.CurrentTable = "ChannelMembers"
|
||||
return false, progress.ToJson(), nil
|
||||
return false, progress.ToJSON(), nil
|
||||
}
|
||||
|
||||
progress.LastTeamId = result["TeamId"]
|
||||
@@ -88,17 +88,17 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo
|
||||
// Run a ChannelMembers migration batch.
|
||||
data, err := worker.srv.Store.Channel().MigrateChannelMembers(progress.LastChannelId, progress.LastUserId)
|
||||
if err != nil {
|
||||
return false, progress.ToJson(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.channel.migrate_channel_members.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return false, progress.ToJSON(), model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "app.channel.migrate_channel_members.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if data == nil {
|
||||
// We haven't progressed. That means we've reached the end of this final stage of the migration.
|
||||
|
||||
return true, progress.ToJson(), nil
|
||||
return true, progress.ToJSON(), nil
|
||||
}
|
||||
|
||||
progress.LastChannelId = data["ChannelId"]
|
||||
progress.LastUserId = data["UserId"]
|
||||
}
|
||||
|
||||
return false, progress.ToJson(), nil
|
||||
return false, progress.ToJSON(), nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -114,12 +113,6 @@ func (b *Bot) Etag() string {
|
||||
return Etag(b.UserId, b.UpdateAt)
|
||||
}
|
||||
|
||||
// ToJson serializes the bot to json.
|
||||
func (b *Bot) ToJson() []byte {
|
||||
data, _ := json.Marshal(b)
|
||||
return data
|
||||
}
|
||||
|
||||
// Patch modifies an existing bot with optional fields from the given patch.
|
||||
// TODO 6.0: consider returning a boolean to indicate whether or not the patch
|
||||
// applied any changes.
|
||||
@@ -154,16 +147,6 @@ func (b *Bot) WouldPatch(patch *BotPatch) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ToJson serializes the bot patch to json.
|
||||
func (b *BotPatch) ToJson() []byte {
|
||||
data, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// UserFromBot returns a user model describing the bot fields stored in the User store.
|
||||
func UserFromBot(b *Bot) *User {
|
||||
return &User{
|
||||
@@ -185,12 +168,6 @@ func BotFromUser(u *User) *Bot {
|
||||
}
|
||||
}
|
||||
|
||||
// ToJson serializes a list of bots to json.
|
||||
func (l *BotList) ToJson() []byte {
|
||||
b, _ := json.Marshal(l)
|
||||
return b
|
||||
}
|
||||
|
||||
// Etag computes the etag for a list of bots.
|
||||
func (l *BotList) Etag() string {
|
||||
id := "0"
|
||||
|
||||
@@ -6,7 +6,6 @@ package model
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
@@ -165,11 +164,6 @@ func (o *Channel) DeepCopy() *Channel {
|
||||
return ©
|
||||
}
|
||||
|
||||
func (o *Channel) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *Channel) Etag() string {
|
||||
return Etag(o.Id, o.UpdateAt)
|
||||
}
|
||||
|
||||
@@ -3,20 +3,8 @@
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type ChannelList []*Channel
|
||||
|
||||
func (o *ChannelList) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return "[]"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *ChannelList) Etag() string {
|
||||
|
||||
id := "0"
|
||||
@@ -41,14 +29,6 @@ func (o *ChannelList) Etag() string {
|
||||
|
||||
type ChannelListWithTeamData []*ChannelWithTeamData
|
||||
|
||||
func (o *ChannelListWithTeamData) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return "[]"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *ChannelListWithTeamData) Etag() string {
|
||||
|
||||
id := "0"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
@@ -69,11 +68,6 @@ type ChannelMemberForExport struct {
|
||||
Username string
|
||||
}
|
||||
|
||||
func (o *ChannelMember) ToJson() string {
|
||||
b, _ := json.Marshal(o)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (o *ChannelMember) IsValid() *AppError {
|
||||
|
||||
if !IsValidId(o.ChannelId) {
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const ChannelSearchDefaultLimit = 50
|
||||
|
||||
type ChannelSearch struct {
|
||||
@@ -24,9 +20,3 @@ type ChannelSearch struct {
|
||||
Page *int `json:"page,omitempty"`
|
||||
PerPage *int `json:"per_page,omitempty"`
|
||||
}
|
||||
|
||||
// ToJson convert a Channel to a json string
|
||||
func (c *ChannelSearch) ToJson() string {
|
||||
b, _ := json.Marshal(c)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@@ -73,27 +72,6 @@ type SidebarChannel struct {
|
||||
type SidebarChannels []*SidebarChannel
|
||||
type SidebarCategoriesWithChannels []*SidebarCategoryWithChannels
|
||||
|
||||
func (o SidebarCategoryWithChannels) ToJson() []byte {
|
||||
b, _ := json.Marshal(o)
|
||||
return b
|
||||
}
|
||||
|
||||
func SidebarCategoriesWithChannelsToJson(o []*SidebarCategoryWithChannels) []byte {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return []byte("[]")
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (o OrderedSidebarCategories) ToJson() []byte {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return []byte("[]")
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
var categoryIdPattern = regexp.MustCompile("(favorites|channels|direct_messages)_[a-z0-9]{26}_[a-z0-9]{26}")
|
||||
|
||||
func IsValidCategoryId(s string) bool {
|
||||
|
||||
@@ -3,20 +3,9 @@
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelStats struct {
|
||||
ChannelId string `json:"channel_id"`
|
||||
MemberCount int64 `json:"member_count"`
|
||||
GuestCount int64 `json:"guest_count"`
|
||||
PinnedPostCount int64 `json:"pinnedpost_count"`
|
||||
}
|
||||
|
||||
func ChannelStatsFromJson(data io.Reader) *ChannelStats {
|
||||
var o *ChannelStats
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
@@ -3,30 +3,13 @@
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ChannelView struct {
|
||||
ChannelId string `json:"channel_id"`
|
||||
PrevChannelId string `json:"prev_channel_id"`
|
||||
CollapsedThreadsSupported bool `json:"collapsed_threads_supported"`
|
||||
}
|
||||
|
||||
func ChannelViewFromJson(data io.Reader) *ChannelView {
|
||||
var o *ChannelView
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
type ChannelViewResponse struct {
|
||||
Status string `json:"status"`
|
||||
LastViewedAtTimes map[string]int64 `json:"last_viewed_at_times"`
|
||||
}
|
||||
|
||||
func ChannelViewResponseFromJson(data io.Reader) *ChannelViewResponse {
|
||||
var o *ChannelViewResponse
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
+1266
-314
File diff suppressed because it is too large
Load Diff
+11
-1
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -48,7 +49,10 @@ func TestClient4CreatePost(t *testing.T) {
|
||||
}
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
attachments := PostFromJson(r.Body).Attachments()
|
||||
var post Post
|
||||
err := json.NewDecoder(r.Body).Decode(&post)
|
||||
assert.NoError(t, err)
|
||||
attachments := post.Attachments()
|
||||
assert.Equal(t, []*SlackAttachment{
|
||||
{
|
||||
Actions: []*PostAction{
|
||||
@@ -64,6 +68,8 @@ func TestClient4CreatePost(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, attachments)
|
||||
err = json.NewEncoder(w).Encode(&post)
|
||||
assert.NoError(t, err)
|
||||
}))
|
||||
|
||||
client := NewAPIv4Client(server.URL)
|
||||
@@ -85,6 +91,10 @@ func TestClient4SetToken(t *testing.T) {
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, strings.TrimSpace(token[1]))
|
||||
|
||||
var user User
|
||||
err := json.NewEncoder(w).Encode(&user)
|
||||
assert.NoError(t, err)
|
||||
}))
|
||||
|
||||
client := NewAPIv4Client(server.URL)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user