summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcpanato <ctadeu@gmail.com>2018-06-15 17:38:08 +0200
committercpanato <ctadeu@gmail.com>2018-06-15 17:38:08 +0200
commite38b18565ecd9dbe46b0ba8a263c7a39caa0bfda (patch)
tree3df8e817eafd710bbc3b5ef04ea42c3d2581c74f
parentc8b99b97dffbc7c96b3911f6301f0ec69399cea2 (diff)
parent85a75526c7c03fca1d14a39cfb3f2638d98d3fe1 (diff)
downloadchat-e38b18565ecd9dbe46b0ba8a263c7a39caa0bfda.tar.gz
chat-e38b18565ecd9dbe46b0ba8a263c7a39caa0bfda.tar.bz2
chat-e38b18565ecd9dbe46b0ba8a263c7a39caa0bfda.zip
Merge remote-tracking branch 'upstream/release-5.0' into release-5.0-merge-to-master-20180615
-rw-r--r--app/oauth.go15
-rw-r--r--i18n/en.json4
-rw-r--r--store/sqlstore/team_store.go2
3 files changed, 19 insertions, 2 deletions
diff --git a/app/oauth.go b/app/oauth.go
index 13fbd5a73..477c0aeaf 100644
--- a/app/oauth.go
+++ b/app/oauth.go
@@ -8,6 +8,7 @@ import (
b64 "encoding/base64"
"fmt"
"io"
+ "io/ioutil"
"net/http"
"net/url"
"strings"
@@ -690,10 +691,13 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
if resp, err := a.HTTPClient(true).Do(req); err != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
+ bodyBytes, _ = ioutil.ReadAll(resp.Body)
+ resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
+
ar = model.AccessResponseFromJson(resp.Body)
consumeAndClose(resp)
- if ar == nil {
+ if ar == nil || resp.StatusCode != http.StatusOK {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, "response_body="+string(bodyBytes), http.StatusInternalServerError)
}
}
@@ -717,6 +721,15 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
if resp, err := a.HTTPClient(true).Do(req); err != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]interface{}{"Service": service}, err.Error(), http.StatusInternalServerError)
} else {
+ bodyBytes, _ = ioutil.ReadAll(resp.Body)
+ if resp.StatusCode != http.StatusOK {
+ bodyString := string(bodyBytes)
+ mlog.Error("Error getting OAuth user: " + bodyString)
+ if service == model.SERVICE_GITLAB && resp.StatusCode == http.StatusForbidden && strings.Contains(bodyString, "Terms of Service") {
+ return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "oauth.gitlab.tos.error", nil, "", http.StatusBadRequest)
+ }
+ }
+ resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
return resp.Body, teamId, stateProps, nil
}
diff --git a/i18n/en.json b/i18n/en.json
index 2f7aa47fc..843f9b807 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -2827,6 +2827,10 @@
"translation": "Blank email"
},
{
+ "id": "oauth.gitlab.tos.error",
+ "translation": "GitLab's Terms of Service have updated. Please go to gitlab.com to accept them and then try logging into Mattermost again."
+ },
+ {
"id": "api.user.complete_switch_with_oauth.parse.app_error",
"translation": "Could not parse auth data out of {{.Service}} user object"
},
diff --git a/store/sqlstore/team_store.go b/store/sqlstore/team_store.go
index 22f0bdb29..95b73e542 100644
--- a/store/sqlstore/team_store.go
+++ b/store/sqlstore/team_store.go
@@ -342,7 +342,7 @@ func (s SqlTeamStore) GetAll() store.StoreChannel {
func (s SqlTeamStore) GetAllPage(offset int, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var data []*model.Team
- if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
+ if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetAllTeams", "store.sql_team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
}