Migrate User.ClearAllCustomRoleAssignments to sync by default (#11506)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
89d8dd6816
Коммит
4380c0b7a8
@@ -1436,60 +1436,56 @@ func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) store.StoreCha
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) ClearAllCustomRoleAssignments() store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
builtInRoles := model.MakeDefaultRoles()
|
||||
lastUserId := strings.Repeat("0", 26)
|
||||
func (us SqlUserStore) ClearAllCustomRoleAssignments() *model.AppError {
|
||||
builtInRoles := model.MakeDefaultRoles()
|
||||
lastUserId := strings.Repeat("0", 26)
|
||||
|
||||
for {
|
||||
var transaction *gorp.Transaction
|
||||
var err error
|
||||
for {
|
||||
var transaction *gorp.Transaction
|
||||
var err error
|
||||
|
||||
if transaction, err = us.GetMaster().Begin(); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
if transaction, err = us.GetMaster().Begin(); err != nil {
|
||||
return model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
var users []*model.User
|
||||
if _, err := transaction.Select(&users, "SELECT * from Users WHERE Id > :Id ORDER BY Id LIMIT 1000", map[string]interface{}{"Id": lastUserId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var users []*model.User
|
||||
if _, err := transaction.Select(&users, "SELECT * from Users WHERE Id > :Id ORDER BY Id LIMIT 1000", map[string]interface{}{"Id": lastUserId}); err != nil {
|
||||
return model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(users) == 0 {
|
||||
break
|
||||
}
|
||||
if len(users) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
lastUserId = user.Id
|
||||
for _, user := range users {
|
||||
lastUserId = user.Id
|
||||
|
||||
var newRoles []string
|
||||
var newRoles []string
|
||||
|
||||
for _, role := range strings.Fields(user.Roles) {
|
||||
for name := range builtInRoles {
|
||||
if name == role {
|
||||
newRoles = append(newRoles, role)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRolesString := strings.Join(newRoles, " ")
|
||||
if newRolesString != user.Roles {
|
||||
if _, err := transaction.Exec("UPDATE Users SET Roles = :Roles WHERE Id = :Id", map[string]interface{}{"Roles": newRolesString, "Id": user.Id}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
for _, role := range strings.Fields(user.Roles) {
|
||||
for name := range builtInRoles {
|
||||
if name == role {
|
||||
newRoles = append(newRoles, role)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
newRolesString := strings.Join(newRoles, " ")
|
||||
if newRolesString != user.Roles {
|
||||
if _, err := transaction.Exec("UPDATE Users SET Roles = :Roles WHERE Id = :Id", map[string]interface{}{"Roles": newRolesString, "Id": user.Id}); err != nil {
|
||||
return model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return model.NewAppError("SqlUserStore.ClearAllCustomRoleAssignments", "store.sql_user.clear_all_custom_role_assignments.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) InferSystemInstallDate() store.StoreChannel {
|
||||
|
||||
Ссылка в новой задаче
Block a user