From 5a718f3c6300e926b1ad8277bacddfe7ecc4c3c2 Mon Sep 17 00:00:00 2001 From: kshitij katiyar <90389917+Kshitij-Katiyar@users.noreply.github.com> Date: Thu, 8 Sep 2022 15:34:00 +0530 Subject: [PATCH] MM-29123: Removed the hard coded gitlab.com in Terms of Service error (#20830) Automatic Merge --- app/oauth.go | 8 ++++++-- i18n/en.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/oauth.go b/app/oauth.go index d9b41e4210..e78596ea41 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -8,7 +8,6 @@ import ( "context" b64 "encoding/base64" "encoding/json" - "errors" "fmt" "io" "net/http" @@ -25,6 +24,7 @@ import ( "github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/mattermost/mattermost-server/v6/store" "github.com/mattermost/mattermost-server/v6/utils" + "github.com/pkg/errors" ) const ( @@ -896,8 +896,12 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service mlog.Error("Error getting OAuth user", mlog.Int("response", resp.StatusCode), mlog.String("body_string", bodyString)) if service == model.ServiceGitlab && resp.StatusCode == http.StatusForbidden && strings.Contains(bodyString, "Terms of Service") { + url, err := url.Parse(*sso.UserAPIEndpoint) + if err != nil { + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", model.NoTranslation, nil, "", http.StatusInternalServerError).Wrap(errors.Wrapf(err, "error parsing %s", *sso.UserAPIEndpoint)) + } // Return a nicer error when the user hasn't accepted GitLab's terms of service - return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "oauth.gitlab.tos.error", nil, "", http.StatusBadRequest) + return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "oauth.gitlab.tos.error", map[string]any{"URL": url.Hostname()}, "", http.StatusBadRequest) } return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.response.app_error", nil, "response_body="+bodyString, http.StatusInternalServerError) diff --git a/i18n/en.json b/i18n/en.json index 6f98b980f6..4e59009f9a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -9273,7 +9273,7 @@ }, { "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." + "translation": "GitLab's Terms of Service have updated. Please go to {{.URL}} to accept them and then try logging into Mattermost again." }, { "id": "plugin.api.get_users_in_channel",