Merge branch 'master' into post-metadata
Этот коммит содержится в:
@@ -4,17 +4,18 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetTermsOfService(t *testing.T) {
|
||||
|
||||
19
api4/user.go
19
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")
|
||||
|
||||
@@ -845,7 +846,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAuditWithUserId(user.Id, fmt.Sprintf("active=%v", active))
|
||||
if isSelfDeactive {
|
||||
c.App.Go(func() {
|
||||
c.App.Srv.Go(func() {
|
||||
if err = c.App.SendDeactivateAccountEmail(user.Email, user.Locale, c.App.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3087,10 +3087,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