Migrate to idiomatic error handling app/a*.go and app/b*.go (#9455)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
3785ad48c1
Коммит
7636650a25
@@ -238,15 +238,16 @@ func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
|
|||||||
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
|
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if user, err := a.GetUser(userId); err != nil {
|
user, err := a.GetUser(userId)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
T := utils.GetUserTranslations(user.Locale)
|
T := utils.GetUserTranslations(user.Locale)
|
||||||
license := a.License()
|
license := a.License()
|
||||||
if err := mailservice.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), cfg, license != nil && *license.Features.Compliance); err != nil {
|
if err := mailservice.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), cfg, license != nil && *license.Features.Compliance); err != nil {
|
||||||
return model.NewAppError("testEmail", "app.admin.test_email.failure", map[string]interface{}{"Error": err.Error()}, "", http.StatusInternalServerError)
|
return model.NewAppError("testEmail", "app.admin.test_email.failure", map[string]interface{}{"Error": err.Error()}, "", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
122
app/analytics.go
122
app/analytics.go
@@ -19,15 +19,16 @@ const (
|
|||||||
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||||
skipIntensiveQueries := false
|
skipIntensiveQueries := false
|
||||||
var systemUserCount int64
|
var systemUserCount int64
|
||||||
if r := <-a.Srv.Store.User().AnalyticsUniqueUserCount(""); r.Err != nil {
|
r := <-a.Srv.Store.User().AnalyticsUniqueUserCount("")
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
systemUserCount = r.Data.(int64)
|
systemUserCount = r.Data.(int64)
|
||||||
if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) {
|
if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) {
|
||||||
mlog.Debug(fmt.Sprintf("More than %v users on the system, intensive queries skipped", *a.Config().AnalyticsSettings.MaxUsersForStatistics))
|
mlog.Debug(fmt.Sprintf("More than %v users on the system, intensive queries skipped", *a.Config().AnalyticsSettings.MaxUsersForStatistics))
|
||||||
skipIntensiveQueries = true
|
skipIntensiveQueries = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if name == "standard" {
|
if name == "standard" {
|
||||||
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 11)
|
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 11)
|
||||||
@@ -63,53 +64,53 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||||
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||||
|
|
||||||
if r := <-openChan; r.Err != nil {
|
r := <-openChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[0].Value = float64(r.Data.(int64))
|
rows[0].Value = float64(r.Data.(int64))
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-privateChan; r.Err != nil {
|
r = <-privateChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[1].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[1].Value = float64(r.Data.(int64))
|
||||||
|
|
||||||
if postChan == nil {
|
if postChan == nil {
|
||||||
rows[2].Value = -1
|
rows[2].Value = -1
|
||||||
} else {
|
} else {
|
||||||
if r := <-postChan; r.Err != nil {
|
r := <-postChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[2].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[2].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if userChan == nil {
|
if userChan == nil {
|
||||||
rows[3].Value = float64(systemUserCount)
|
rows[3].Value = float64(systemUserCount)
|
||||||
} else {
|
} else {
|
||||||
if r := <-userChan; r.Err != nil {
|
r := <-userChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[3].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[3].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if userInactiveChan == nil {
|
if userInactiveChan == nil {
|
||||||
rows[10].Value = -1
|
rows[10].Value = -1
|
||||||
} else {
|
} else {
|
||||||
if r := <-userInactiveChan; r.Err != nil {
|
r := <-userInactiveChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[10].Value = float64(r.Data.(int64))
|
rows[10].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-teamChan; r.Err != nil {
|
r = <-teamChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[4].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[4].Value = float64(r.Data.(int64))
|
||||||
|
|
||||||
// If in HA mode then aggregrate all the stats
|
// If in HA mode then aggregrate all the stats
|
||||||
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
|
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
|
||||||
@@ -138,17 +139,17 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
rows[7].Value = float64(a.Srv.Store.TotalReadDbConnections())
|
rows[7].Value = float64(a.Srv.Store.TotalReadDbConnections())
|
||||||
}
|
}
|
||||||
|
|
||||||
if r := <-dailyActiveChan; r.Err != nil {
|
r = <-dailyActiveChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[8].Value = float64(r.Data.(int64))
|
rows[8].Value = float64(r.Data.(int64))
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-monthlyActiveChan; r.Err != nil {
|
r = <-monthlyActiveChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[9].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[9].Value = float64(r.Data.(int64))
|
||||||
|
|
||||||
return rows, nil
|
return rows, nil
|
||||||
} else if name == "post_counts_day" {
|
} else if name == "post_counts_day" {
|
||||||
@@ -157,22 +158,22 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if r := <-a.Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil {
|
r := <-a.Srv.Store.Post().AnalyticsPostCountsByDay(teamId)
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
return r.Data.(model.AnalyticsRows), nil
|
|
||||||
}
|
}
|
||||||
|
return r.Data.(model.AnalyticsRows), nil
|
||||||
} else if name == "user_counts_with_posts_day" {
|
} else if name == "user_counts_with_posts_day" {
|
||||||
if skipIntensiveQueries {
|
if skipIntensiveQueries {
|
||||||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if r := <-a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil {
|
r := <-a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
return r.Data.(model.AnalyticsRows), nil
|
|
||||||
}
|
}
|
||||||
|
return r.Data.(model.AnalyticsRows), nil
|
||||||
} else if name == "extra_counts" {
|
} else if name == "extra_counts" {
|
||||||
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
|
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
|
||||||
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
|
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
|
||||||
@@ -197,46 +198,46 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
if fileChan == nil {
|
if fileChan == nil {
|
||||||
rows[0].Value = -1
|
rows[0].Value = -1
|
||||||
} else {
|
} else {
|
||||||
if r := <-fileChan; r.Err != nil {
|
r := <-fileChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[0].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[0].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if hashtagChan == nil {
|
if hashtagChan == nil {
|
||||||
rows[1].Value = -1
|
rows[1].Value = -1
|
||||||
} else {
|
} else {
|
||||||
if r := <-hashtagChan; r.Err != nil {
|
r := <-hashtagChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[1].Value = float64(r.Data.(int64))
|
rows[1].Value = float64(r.Data.(int64))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-iHookChan; r.Err != nil {
|
r := <-iHookChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[2].Value = float64(r.Data.(int64))
|
rows[2].Value = float64(r.Data.(int64))
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-oHookChan; r.Err != nil {
|
r = <-oHookChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[3].Value = float64(r.Data.(int64))
|
rows[3].Value = float64(r.Data.(int64))
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-commandChan; r.Err != nil {
|
r = <-commandChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
}
|
||||||
rows[4].Value = float64(r.Data.(int64))
|
rows[4].Value = float64(r.Data.(int64))
|
||||||
}
|
|
||||||
|
|
||||||
if r := <-sessionChan; r.Err != nil {
|
r = <-sessionChan
|
||||||
|
if r.Err != nil {
|
||||||
return nil, r.Err
|
return nil, r.Err
|
||||||
} else {
|
|
||||||
rows[5].Value = float64(r.Data.(int64))
|
|
||||||
}
|
}
|
||||||
|
rows[5].Value = float64(r.Data.(int64))
|
||||||
|
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
@@ -245,9 +246,11 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError) {
|
func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100); result.Err != nil {
|
result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
users := result.Data.([]*model.User)
|
users := result.Data.([]*model.User)
|
||||||
userMap := make(map[string]*model.User)
|
userMap := make(map[string]*model.User)
|
||||||
|
|
||||||
@@ -257,26 +260,25 @@ func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.Us
|
|||||||
|
|
||||||
return userMap, nil
|
return userMap, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||||
var users []*model.User
|
var users []*model.User
|
||||||
if result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
users = result.Data.([]*model.User)
|
|
||||||
}
|
}
|
||||||
|
users = result.Data.([]*model.User)
|
||||||
|
|
||||||
return a.sanitizeProfiles(users, asAdmin), nil
|
return a.sanitizeProfiles(users, asAdmin), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||||
var users []*model.User
|
var users []*model.User
|
||||||
if result := <-a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
result := <-a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
users = result.Data.([]*model.User)
|
|
||||||
}
|
}
|
||||||
|
users = result.Data.([]*model.User)
|
||||||
|
|
||||||
return a.sanitizeProfiles(users, asAdmin), nil
|
return a.sanitizeProfiles(users, asAdmin), nil
|
||||||
}
|
}
|
||||||
|
|||||||
12
app/audit.go
12
app/audit.go
@@ -8,17 +8,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
func (a *App) GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Audit().Get(userId, 0, limit); result.Err != nil {
|
result := <-a.Srv.Store.Audit().Get(userId, 0, limit)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
return result.Data.(model.Audits), nil
|
|
||||||
}
|
}
|
||||||
|
return result.Data.(model.Audits), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
func (a *App) GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Audit().Get(userId, page*perPage, perPage); result.Err != nil {
|
result := <-a.Srv.Store.Audit().Get(userId, page*perPage, perPage)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
return result.Data.(model.Audits), nil
|
return result.Data.(model.Audits), nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||||||
channel, err := a.GetChannel(channelId)
|
channel, err := a.GetChannel(channelId)
|
||||||
if err == nil && channel.TeamId != "" {
|
if err == nil && channel.TeamId != "" {
|
||||||
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||||
} else if err != nil && err.StatusCode == http.StatusNotFound {
|
}
|
||||||
|
|
||||||
|
if err != nil && err.StatusCode == http.StatusNotFound {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
|
|||||||
config, _, err := image.DecodeConfig(file)
|
config, _, err := image.DecodeConfig(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.decode_config.app_error", nil, err.Error(), http.StatusBadRequest)
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.decode_config.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
} else if config.Width*config.Height > model.MaxImageSize {
|
}
|
||||||
|
|
||||||
|
if config.Width*config.Height > model.MaxImageSize {
|
||||||
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.too_large.app_error", nil, err.Error(), http.StatusBadRequest)
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.too_large.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user