summaryrefslogtreecommitdiffstats
path: root/mattermost.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-05-11 11:04:30 -0700
committerChristopher Speller <crspeller@gmail.com>2016-05-11 14:04:30 -0400
commit3928535456f9fcb025ed86edeb4d258f2c524150 (patch)
tree010f4bd298f23b92711affcdef81cc329c522e67 /mattermost.go
parenta574397a7256bed7738f499019f97ab468b5161d (diff)
downloadchat-3928535456f9fcb025ed86edeb4d258f2c524150.tar.gz
chat-3928535456f9fcb025ed86edeb4d258f2c524150.tar.bz2
chat-3928535456f9fcb025ed86edeb4d258f2c524150.zip
PLT-2905 fixing upgrade of SSO accounts (#2962)
* PLT-2905 fixing upgrade of SSO accounts * Fixing multiple Auths mapped to different emails
Diffstat (limited to 'mattermost.go')
-rw-r--r--mattermost.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/mattermost.go b/mattermost.go
index be9b08a95..6fe285d58 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -373,14 +373,15 @@ func cmdUpdateDb30() {
uniqueEmails := make(map[string]bool)
uniqueUsernames := make(map[string]bool)
- primaryUsers := convertTeamTo30(team.Name, team, uniqueEmails, uniqueUsernames)
+ uniqueAuths := make(map[string]bool)
+ primaryUsers := convertTeamTo30(team.Name, team, uniqueEmails, uniqueUsernames, uniqueAuths)
l4g.Info("Upgraded %v users", len(primaryUsers))
for _, otherTeam := range teams {
if otherTeam.Id != team.Id {
l4g.Info("Upgrading team %v", otherTeam.Name)
- users := convertTeamTo30(team.Name, otherTeam, uniqueEmails, uniqueUsernames)
+ users := convertTeamTo30(team.Name, otherTeam, uniqueEmails, uniqueUsernames, uniqueAuths)
l4g.Info("Upgraded %v users", len(users))
}
@@ -400,6 +401,18 @@ func cmdUpdateDb30() {
flushLogAndExit(1)
}
+ if _, err := store.GetMaster().Exec(`
+ UPDATE Users
+ SET
+ AuthData = NULL
+ WHERE
+ AuthData = ''
+ `,
+ ); err != nil {
+ l4g.Error("Failed to update AuthData types details=%v", err)
+ flushLogAndExit(1)
+ }
+
extraLength := store.GetMaxLengthOfColumnIfExists("Audits", "ExtraInfo")
if len(extraLength) > 0 && extraLength != "1024" {
store.AlterColumnTypeIfExists("Audits", "ExtraInfo", "VARCHAR(1024)", "VARCHAR(1024)")
@@ -424,6 +437,7 @@ func cmdUpdateDb30() {
store.RemoveIndexIfExists("idx_users_team_id", "Users")
store.CreateUniqueIndexIfNotExists("idx_users_email_unique", "Users", "Email")
store.CreateUniqueIndexIfNotExists("idx_users_username_unique", "Users", "Username")
+ store.CreateUniqueIndexIfNotExists("idx_users_authdata_unique", "Users", "AuthData")
store.RemoveColumnIfExists("Teams", "AllowTeamListing")
store.RemoveColumnIfExists("Users", "TeamId")
}
@@ -448,12 +462,13 @@ type UserForUpgrade struct {
Email string
Roles string
TeamId string
+ AuthData *string
}
-func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails map[string]bool, uniqueUsernames map[string]bool) []*UserForUpgrade {
+func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails map[string]bool, uniqueUsernames map[string]bool, uniqueAuths map[string]bool) []*UserForUpgrade {
store := api.Srv.Store.(*store.SqlStore)
var users []*UserForUpgrade
- if _, err := store.GetMaster().Select(&users, "SELECT Users.Id, Users.Username, Users.Email, Users.Roles, Users.TeamId FROM Users WHERE Users.TeamId = :TeamId", map[string]interface{}{"TeamId": team.Id}); err != nil {
+ if _, err := store.GetMaster().Select(&users, "SELECT Users.Id, Users.Username, Users.Email, Users.Roles, Users.TeamId, Users.AuthData FROM Users WHERE Users.TeamId = :TeamId", map[string]interface{}{"TeamId": team.Id}); err != nil {
l4g.Error("Failed to load profiles for team details=%v", err)
flushLogAndExit(1)
}
@@ -530,13 +545,19 @@ func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails
}
}
+ if user.AuthData != nil && *user.AuthData != "" && uniqueAuths[*user.AuthData] {
+ shouldUpdateUser = true
+ }
+
if shouldUpdateUser {
if _, err := store.GetMaster().Exec(`
UPDATE Users
SET
Email = :Email,
Username = :Username,
- Roles = :Roles
+ Roles = :Roles,
+ AuthService = '',
+ AuthData = NULL
WHERE
Id = :Id
`,
@@ -590,6 +611,10 @@ func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails
uniqueEmails[user.Email] = true
uniqueUsernames[user.Username] = true
+
+ if user.AuthData != nil && *user.AuthData != "" {
+ uniqueAuths[*user.AuthData] = true
+ }
}
return users