* #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
66 строки
1.9 KiB
Go
66 строки
1.9 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost-server/app"
|
|
"github.com/mattermost/mattermost-server/model"
|
|
)
|
|
|
|
func (api *API) InitTermsOfService() {
|
|
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(getLatestTermsOfService)).Methods("GET")
|
|
api.BaseRoutes.TermsOfService.Handle("", api.ApiSessionRequired(createTermsOfService)).Methods("POST")
|
|
}
|
|
|
|
func getLatestTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
termsOfService, err := c.App.GetLatestTermsOfService()
|
|
if err != nil {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
w.Write([]byte(termsOfService.ToJson()))
|
|
}
|
|
|
|
func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
|
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
|
return
|
|
}
|
|
|
|
if license := c.App.License(); license == nil || !*license.Features.CustomTermsOfService {
|
|
c.Err = model.NewAppError("createTermsOfService", "api.create_terms_of_service.custom_terms_of_service_disabled.app_error", nil, "", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
props := model.MapFromJson(r.Body)
|
|
text := props["text"]
|
|
userId := c.Session.UserId
|
|
|
|
if text == "" {
|
|
c.Err = model.NewAppError("Config.IsValid", "api.create_terms_of_service.empty_text.app_error", nil, "", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
oldTermsOfService, err := c.App.GetLatestTermsOfService()
|
|
if err != nil && err.Id != app.ERROR_TERMS_OF_SERVICE_NO_ROWS_FOUND {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
if oldTermsOfService == nil || oldTermsOfService.Text != text {
|
|
termsOfService, err := c.App.CreateTermsOfService(text, userId)
|
|
if err != nil {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
w.Write([]byte(termsOfService.ToJson()))
|
|
} else {
|
|
w.Write([]byte(oldTermsOfService.ToJson()))
|
|
}
|
|
}
|