From 83a0e965d3a08f70aa16de4860a151505c8d573d Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Tue, 16 Apr 2019 17:59:07 +0100 Subject: [PATCH] [MM-15126] Adding terms of service to the login response (#10625) --- api4/user.go | 11 +++++++++++ api4/user_test.go | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/api4/user.go b/api4/user.go index 770f3e5a9c..dab4808590 100644 --- a/api4/user.go +++ b/api4/user.go @@ -1192,6 +1192,17 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAuditWithUserId(user.Id, "success") + userTermsOfService, err := c.App.GetUserTermsOfService(user.Id) + if err != nil && err.StatusCode != http.StatusNotFound { + c.Err = err + return + } + + if userTermsOfService != nil { + user.TermsOfServiceId = userTermsOfService.TermsOfServiceId + user.TermsOfServiceCreateAt = userTermsOfService.CreateAt + } + c.App.Session = *session user.Sanitize(map[string]bool{}) diff --git a/api4/user_test.go b/api4/user_test.go index 3dd34abbc0..ea414b53bc 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -2649,6 +2649,26 @@ func TestLogin(t *testing.T) { _, resp = th.Client.Login(botUser.Email, "password") CheckErrorMessage(t, resp, "api.user.login.bot_login_forbidden.app_error") }) + + t.Run("login with terms_of_service set", func(t *testing.T) { + termsOfService, err := th.App.CreateTermsOfService("terms of service", th.BasicUser.Id) + if err != nil { + t.Fatal(err) + } + + success, resp := th.Client.RegisterTermsOfServiceAction(th.BasicUser.Id, termsOfService.Id, true) + CheckNoError(t, resp) + assert.True(t, *success) + + userTermsOfService, resp := th.Client.GetUserTermsOfService(th.BasicUser.Id, "") + CheckNoError(t, resp) + + user, resp := th.Client.Login(th.BasicUser.Email, th.BasicUser.Password) + CheckNoError(t, resp) + assert.Equal(t, user.Id, th.BasicUser.Id) + assert.Equal(t, user.TermsOfServiceId, userTermsOfService.TermsOfServiceId) + assert.Equal(t, user.TermsOfServiceCreateAt, userTermsOfService.CreateAt) + }) } func TestCBALogin(t *testing.T) {