From 846ccac6e5d4647c6eec5a1ab1e41ad5ee6d29f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 4 Apr 2018 17:21:31 +0200 Subject: MM-9934: More robust slack imports parsing (#8576) --- app/slackimport.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'app/slackimport.go') diff --git a/app/slackimport.go b/app/slackimport.go index ed522671a..d5e7fe2b2 100644 --- a/app/slackimport.go +++ b/app/slackimport.go @@ -30,10 +30,16 @@ type SlackChannel struct { Purpose map[string]string `json:"purpose"` } +type SlackProfile struct { + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email string `json:"email"` +} + type SlackUser struct { - Id string `json:"id"` - Username string `json:"name"` - Profile map[string]string `json:"profile"` + Id string `json:"id"` + Username string `json:"name"` + Profile SlackProfile `json:"profile"` } type SlackFile struct { @@ -144,16 +150,9 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Bu } for _, sUser := range slackusers { - firstName := "" - lastName := "" - if name, ok := sUser.Profile["first_name"]; ok { - firstName = name - } - if name, ok := sUser.Profile["last_name"]; ok { - lastName = name - } - - email := sUser.Profile["email"] + firstName := sUser.Profile.FirstName + lastName := sUser.Profile.LastName + email := sUser.Profile.Email if email == "" { email = sUser.Username + "@example.com" log.WriteString(utils.T("api.slackimport.slack_add_users.missing_email_address", map[string]interface{}{"Email": email, "Username": sUser.Username})) -- cgit v1.2.3-1-g7c22