[MM-22051] Remove To/From JSON (#18070)
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6861efb47e
Коммит
92837fa1ee
199
api4/user.go
199
api4/user.go
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user