* #132 added UserTermsOfService model * #132 added UserTermsOfService model * #132 added logic to save user TOS data in a new table * #132 Added logic to save and delete user TOS. Updated user TOS action logic * #132 updated store mocks * #132 added tests * #132 removed cache from UserTermsOfService SQL store * #132 fixed styling and license check * #132 added message translations in en.json * #132 fixed save user TOS logic to work second time as well * #132 removed User.AcceptedTermsOfService colum and migrated accepted TOS data into new table * #132 fixed formatting * #132 fixed formatting * #146 added field 'mandatory' to terms of service * #146 updated tests * #146 added getLatestTermsOfService API * #146 Added tests * #146 fixed styling * #146 removed code for managing mandatory/optional TOS * #146 Added TOS re-acceptance period config * #146 fixed styling * #146 removed some code left for debugging * #146 added TOS re-acceptance period in config * #146 fixed a json name from service_terms to terms_of_service * #146 Minor refactoring and added TOS re-acceptance period to diagnistics * Fixed style * Updated upgraded script to keep app backward compatible
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
c52e808e34
Коммит
0c5f60f89b
@@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
func (api *API) InitTermsOfService() {
|
||||
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(getTermsOfService)).Methods("GET")
|
||||
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(getLatestTermsOfService)).Methods("GET")
|
||||
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(createTermsOfService)).Methods("POST")
|
||||
}
|
||||
|
||||
func getTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func getLatestTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
termsOfService, err := c.App.GetLatestTermsOfService()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
||||
17
api4/user.go
17
api4/user.go
@@ -40,7 +40,8 @@ func (api *API) InitUser() {
|
||||
api.BaseRoutes.Users.Handle("/password/reset/send", api.ApiHandler(sendPasswordReset)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/email/verify", api.ApiHandler(verifyUserEmail)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/email/verify/send", api.ApiHandler(sendVerificationEmail)).Methods("POST")
|
||||
api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(registerTermsOfServiceAction)).Methods("POST")
|
||||
api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(saveUserTermsOfService)).Methods("POST")
|
||||
api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(getUserTermsOfService)).Methods("GET")
|
||||
|
||||
api.BaseRoutes.User.Handle("/auth", api.ApiSessionRequiredTrustRequester(updateUserAuth)).Methods("PUT")
|
||||
|
||||
@@ -1626,7 +1627,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func registerTermsOfServiceAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
|
||||
userId := c.Session.UserId
|
||||
@@ -1638,7 +1639,7 @@ func registerTermsOfServiceAction(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.RecordUserTermsOfServiceAction(userId, termsOfServiceId, accepted); err != nil {
|
||||
if err := c.App.SaveUserTermsOfService(userId, termsOfServiceId, accepted); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -1646,3 +1647,13 @@ func registerTermsOfServiceAction(c *Context, w http.ResponseWriter, r *http.Req
|
||||
c.LogAudit("TermsOfServiceId=" + termsOfServiceId + ", accepted=" + strconv.FormatBool(accepted))
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func getUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userId := c.Session.UserId
|
||||
if result, err := c.App.GetUserTermsOfService(userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(result.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3086,10 +3086,34 @@ func TestRegisterTermsOfServiceAction(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.True(t, *success)
|
||||
user, err := th.App.GetUser(th.BasicUser.Id)
|
||||
_, err = th.App.GetUser(th.BasicUser.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestGetUserTermsOfService(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
_, resp := Client.GetUserTermsOfService(th.BasicUser.Id, "")
|
||||
CheckErrorMessage(t, resp, "store.sql_user_terms_of_service.get_by_user.no_rows.app_error")
|
||||
|
||||
termsOfService, err := th.App.CreateTermsOfService("terms of service", th.BasicUser.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, user.AcceptedTermsOfServiceId, termsOfService.Id)
|
||||
success, resp := Client.RegisteTermsOfServiceAction(th.BasicUser.Id, termsOfService.Id, true)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, *success)
|
||||
|
||||
userTermsOfService, resp := Client.GetUserTermsOfService(th.BasicUser.Id, "")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Equal(t, th.BasicUser.Id, userTermsOfService.UserId)
|
||||
assert.Equal(t, termsOfService.Id, userTermsOfService.TermsOfServiceId)
|
||||
assert.NotEmpty(t, userTermsOfService.CreateAt)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user