Skip to content

Commit

Permalink
PLT-3063 fix upgrade when user is a team admin (mattermost#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhulen authored and crspeller committed May 27, 2016
1 parent 40743af commit cb74547
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails

for _, user := range users {
shouldUpdateUser := false
shouldUpdateRole := false
previousRole := user.Roles
previousEmail := user.Email
previousUsername := user.Username
Expand All @@ -495,7 +496,7 @@ func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails
if model.IsInRole(user.Roles, model.ROLE_TEAM_ADMIN) {
member.Roles = model.ROLE_TEAM_ADMIN
user.Roles = ""
shouldUpdateUser = true
shouldUpdateRole = true
}

exists := false
Expand Down Expand Up @@ -609,6 +610,25 @@ func convertTeamTo30(primaryTeamName string, team *TeamForUpgrade, uniqueEmails
}
}

if shouldUpdateRole {
if _, err := store.GetMaster().Exec(`
UPDATE Users
SET
Roles = ''
WHERE
Id = :Id
`,
map[string]interface{}{
"Id": user.Id,
},
); err != nil {
l4g.Error("Failed to update user role %v details=%v", user.Email, err)
flushLogAndExit(1)
}

l4g.Info("modified user_id=%v, changed roles from=%v to=%v", user.Id, previousRole, user.Roles)
}

uniqueEmails[user.Email] = true
uniqueUsernames[user.Username] = true

Expand Down

0 comments on commit cb74547

Please sign in to comment.