PLT-2905 fixing upgrade of SSO accounts (#2962)
* PLT-2905 fixing upgrade of SSO accounts * Fixing multiple Auths mapped to different emails
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
a574397a72
Коммит
3928535456
@@ -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
|
||||
|
||||
Ссылка в новой задаче
Block a user