MM-10570: Make permissions reset command clear custom role assignments. (#8976)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1c194e5fbd
Коммит
fc158fce90
@@ -806,3 +806,72 @@ func (s SqlTeamStore) ResetAllTeamSchemes() store.StoreChannel {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) ClearAllCustomRoleAssignments() store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
builtInRoles := model.MakeDefaultRoles()
|
||||
lastUserId := strings.Repeat("0", 26)
|
||||
lastTeamId := strings.Repeat("0", 26)
|
||||
|
||||
for true {
|
||||
var transaction *gorp.Transaction
|
||||
var err error
|
||||
|
||||
if transaction, err = s.GetMaster().Begin(); err != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var teamMembers []*teamMember
|
||||
if _, err := transaction.Select(&teamMembers, "SELECT * from TeamMembers WHERE (TeamId, UserId) > (:TeamId, :UserId) ORDER BY TeamId, UserId LIMIT 1000", map[string]interface{}{"TeamId": lastTeamId, "UserId": lastUserId}); err != nil {
|
||||
if err2 := transaction.Rollback(); err2 != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.rollback_transaction.app_error", nil, err2.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if len(teamMembers) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, member := range teamMembers {
|
||||
lastUserId = member.UserId
|
||||
lastTeamId = member.TeamId
|
||||
|
||||
var newRoles []string
|
||||
|
||||
for _, role := range strings.Fields(member.Roles) {
|
||||
for name := range builtInRoles {
|
||||
if name == role {
|
||||
newRoles = append(newRoles, role)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRolesString := strings.Join(newRoles, " ")
|
||||
if newRolesString != member.Roles {
|
||||
if _, err := transaction.Exec("UPDATE TeamMembers SET Roles = :Roles WHERE UserId = :UserId AND TeamId = :TeamId", map[string]interface{}{"Roles": newRolesString, "TeamId": member.TeamId, "UserId": member.UserId}); err != nil {
|
||||
if err2 := transaction.Rollback(); err2 != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.rollback_transaction.app_error", nil, err2.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
if err2 := transaction.Rollback(); err2 != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.rollback_transaction.app_error", nil, err2.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
result.Err = model.NewAppError("SqlTeamStore.ClearAllCustomRoleAssignments", "store.sql_team.clear_all_custom_role_assignments.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user