summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorHarshil Sharma <harshil.sharma@joshtechnologygroup.com>2018-10-10 00:55:47 +0000
committerJesse Hallam <jesse.hallam@gmail.com>2018-10-09 20:55:47 -0400
commitbffcccf99de8a8f3c68cff9e39d2847f0996b67b (patch)
tree10bf45d87927dc792a233d0653d6ba273c9a7b28 /api4
parent59319b7915b8eb4c20a0d4878382cc0e41fc536d (diff)
downloadchat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.tar.gz
chat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.tar.bz2
chat-bffcccf99de8a8f3c68cff9e39d2847f0996b67b.zip
Refactored to rename "service terms" to "terms of service" (#9581)
* #124 renamed identififers from service terms to terms of service * #124 renamed identififers from service terms to terms of service * 124 renamed ServiceTerms model to TermsOfService * 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService * 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService * #124 fixed formatting * #124 fixed formatting * #132 renamed table ServiceTerms to TermsOfService * #124 renamed some missed files from 'service_terms' to 'terms_of_service' * #124 removed fixed TODOs * drop migrate of ServiceTerms table, since backporting * s/ServiceTerms/TermsOfService/ in tests * s/AcceptedServiceTermsId/AcceptedTermsOfServiceId/ Change the model attribute, even though the column name will eventually be removed. * s/accepted_service_terms_id/accepted_terms_of_service_id/ to match redux * s/serviceTerms/termsOfService * rename column too, and add max size constraint * s/EnableCustomServiceTerms/EnableCustomTermsOfService
Diffstat (limited to 'api4')
-rw-r--r--api4/api.go6
-rw-r--r--api4/service_terms.go64
-rw-r--r--api4/service_terms_test.go53
-rw-r--r--api4/terms_of_service.go64
-rw-r--r--api4/terms_of_service_test.go53
-rw-r--r--api4/user.go12
-rw-r--r--api4/user_test.go12
7 files changed, 132 insertions, 132 deletions
diff --git a/api4/api.go b/api4/api.go
index ed3dda054..b324959e9 100644
--- a/api4/api.go
+++ b/api4/api.go
@@ -108,7 +108,7 @@ type Routes struct {
Webrtc *mux.Router // 'api/v4/webrtc'
- ServiceTerms *mux.Router // 'api/v4/service_terms
+ TermsOfService *mux.Router // 'api/v4/terms_of_service
}
type API struct {
@@ -205,7 +205,7 @@ func Init(a *app.App, root *mux.Router) *API {
api.BaseRoutes.Image = api.BaseRoutes.ApiRoot.PathPrefix("/image").Subrouter()
- api.BaseRoutes.ServiceTerms = api.BaseRoutes.ApiRoot.PathPrefix("/terms_of_service").Subrouter()
+ api.BaseRoutes.TermsOfService = api.BaseRoutes.ApiRoot.PathPrefix("/terms_of_service").Subrouter()
api.InitUser()
api.InitTeam()
@@ -235,7 +235,7 @@ func Init(a *app.App, root *mux.Router) *API {
api.InitRole()
api.InitScheme()
api.InitImage()
- api.InitServiceTerms()
+ api.InitTermsOfService()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
diff --git a/api4/service_terms.go b/api4/service_terms.go
deleted file mode 100644
index ff953102d..000000000
--- a/api4/service_terms.go
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package api4
-
-import (
- "github.com/mattermost/mattermost-server/app"
- "github.com/mattermost/mattermost-server/model"
- "net/http"
-)
-
-func (api *API) InitServiceTerms() {
- api.BaseRoutes.ServiceTerms.Handle("", api.ApiSessionRequired(getServiceTerms)).Methods("GET")
- api.BaseRoutes.ServiceTerms.Handle("", api.ApiSessionRequired(createServiceTerms)).Methods("POST")
-}
-
-func getServiceTerms(c *Context, w http.ResponseWriter, r *http.Request) {
- serviceTerms, err := c.App.GetLatestServiceTerms()
- if err != nil {
- c.Err = err
- return
- }
-
- w.Write([]byte(serviceTerms.ToJson()))
-}
-
-func createServiceTerms(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("createServiceTerms", "api.create_service_terms.custom_service_terms_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_service_terms.empty_text.app_error", nil, "", http.StatusBadRequest)
- return
- }
-
- oldServiceTerms, err := c.App.GetLatestServiceTerms()
- if err != nil && err.Id != app.ERROR_SERVICE_TERMS_NO_ROWS_FOUND {
- c.Err = err
- return
- }
-
- if oldServiceTerms == nil || oldServiceTerms.Text != text {
- serviceTerms, err := c.App.CreateServiceTerms(text, userId)
- if err != nil {
- c.Err = err
- return
- }
-
- w.Write([]byte(serviceTerms.ToJson()))
- } else {
- w.Write([]byte(oldServiceTerms.ToJson()))
- }
-}
diff --git a/api4/service_terms_test.go b/api4/service_terms_test.go
deleted file mode 100644
index 607c104a6..000000000
--- a/api4/service_terms_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package api4
-
-import (
- "github.com/mattermost/mattermost-server/model"
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func TestGetServiceTerms(t *testing.T) {
- th := Setup().InitBasic()
- defer th.TearDown()
- Client := th.Client
-
- _, err := th.App.CreateServiceTerms("abc", th.BasicUser.Id)
- if err != nil {
- t.Fatal(err)
- }
-
- serviceTerms, resp := Client.GetServiceTerms("")
- CheckNoError(t, resp)
-
- assert.NotNil(t, serviceTerms)
- assert.Equal(t, "abc", serviceTerms.Text)
- assert.NotEmpty(t, serviceTerms.Id)
- assert.NotEmpty(t, serviceTerms.CreateAt)
-}
-
-func TestCreateServiceTerms(t *testing.T) {
- th := Setup().InitBasic()
- defer th.TearDown()
- Client := th.Client
-
- _, resp := Client.CreateServiceTerms("service terms new", th.BasicUser.Id)
- CheckErrorMessage(t, resp, "api.context.permissions.app_error")
-}
-
-func TestCreateServiceTermsAdminUser(t *testing.T) {
- th := Setup().InitSystemAdmin()
- defer th.TearDown()
- Client := th.SystemAdminClient
-
- serviceTerms, resp := Client.CreateServiceTerms("service terms new", th.SystemAdminUser.Id)
- CheckErrorMessage(t, resp, "api.create_service_terms.custom_service_terms_disabled.app_error")
-
- th.App.SetLicense(model.NewTestLicense("EnableCustomServiceTerms"))
-
- serviceTerms, resp = Client.CreateServiceTerms("service terms new_2", th.SystemAdminUser.Id)
- CheckNoError(t, resp)
- assert.NotEmpty(t, serviceTerms.Id)
- assert.NotEmpty(t, serviceTerms.CreateAt)
- assert.Equal(t, "service terms new_2", serviceTerms.Text)
- assert.Equal(t, th.SystemAdminUser.Id, serviceTerms.UserId)
-}
diff --git a/api4/terms_of_service.go b/api4/terms_of_service.go
new file mode 100644
index 000000000..de3f7499b
--- /dev/null
+++ b/api4/terms_of_service.go
@@ -0,0 +1,64 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "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(createTermsOfService)).Methods("POST")
+}
+
+func getTermsOfService(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()))
+ }
+}
diff --git a/api4/terms_of_service_test.go b/api4/terms_of_service_test.go
new file mode 100644
index 000000000..c1709df2b
--- /dev/null
+++ b/api4/terms_of_service_test.go
@@ -0,0 +1,53 @@
+package api4
+
+import (
+ "github.com/mattermost/mattermost-server/model"
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestGetTermsOfService(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+ Client := th.Client
+
+ _, err := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ termsOfService, resp := Client.GetTermsOfService("")
+ CheckNoError(t, resp)
+
+ assert.NotNil(t, termsOfService)
+ assert.Equal(t, "abc", termsOfService.Text)
+ assert.NotEmpty(t, termsOfService.Id)
+ assert.NotEmpty(t, termsOfService.CreateAt)
+}
+
+func TestCreateTermsOfService(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+ Client := th.Client
+
+ _, resp := Client.CreateTermsOfService("terms of service new", th.BasicUser.Id)
+ CheckErrorMessage(t, resp, "api.context.permissions.app_error")
+}
+
+func TestCreateTermsOfServiceAdminUser(t *testing.T) {
+ th := Setup().InitSystemAdmin()
+ defer th.TearDown()
+ Client := th.SystemAdminClient
+
+ termsOfService, resp := Client.CreateTermsOfService("terms of service new", th.SystemAdminUser.Id)
+ CheckErrorMessage(t, resp, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
+
+ th.App.SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
+
+ termsOfService, resp = Client.CreateTermsOfService("terms of service new_2", th.SystemAdminUser.Id)
+ CheckNoError(t, resp)
+ assert.NotEmpty(t, termsOfService.Id)
+ assert.NotEmpty(t, termsOfService.CreateAt)
+ assert.Equal(t, "terms of service new_2", termsOfService.Text)
+ assert.Equal(t, th.SystemAdminUser.Id, termsOfService.UserId)
+}
diff --git a/api4/user.go b/api4/user.go
index 404457285..c97e90e89 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -41,7 +41,7 @@ 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(registerServiceTermsAction)).Methods("POST")
+ api.BaseRoutes.User.Handle("/terms_of_service", api.ApiSessionRequired(registerTermsOfServiceAction)).Methods("POST")
api.BaseRoutes.User.Handle("/auth", api.ApiSessionRequiredTrustRequester(updateUserAuth)).Methods("PUT")
@@ -1615,23 +1615,23 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}
-func registerServiceTermsAction(c *Context, w http.ResponseWriter, r *http.Request) {
+func registerTermsOfServiceAction(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
userId := c.Session.UserId
- serviceTermsId := props["serviceTermsId"].(string)
+ termsOfServiceId := props["termsOfServiceId"].(string)
accepted := props["accepted"].(bool)
- if _, err := c.App.GetServiceTerms(serviceTermsId); err != nil {
+ if _, err := c.App.GetTermsOfService(termsOfServiceId); err != nil {
c.Err = err
return
}
- if err := c.App.RecordUserServiceTermsAction(userId, serviceTermsId, accepted); err != nil {
+ if err := c.App.RecordUserTermsOfServiceAction(userId, termsOfServiceId, accepted); err != nil {
c.Err = err
return
}
- c.LogAudit("ServiceTermsId=" + serviceTermsId + ", accepted=" + strconv.FormatBool(accepted))
+ c.LogAudit("TermsOfServiceId=" + termsOfServiceId + ", accepted=" + strconv.FormatBool(accepted))
ReturnStatusOK(w)
}
diff --git a/api4/user_test.go b/api4/user_test.go
index 405102373..b99011aeb 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -3069,20 +3069,20 @@ func TestGetUsersByStatus(t *testing.T) {
})
}
-func TestRegisterServiceTermsAction(t *testing.T) {
+func TestRegisterTermsOfServiceAction(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
- success, resp := Client.RegisterServiceTermsAction(th.BasicUser.Id, "st_1", true)
- CheckErrorMessage(t, resp, "store.sql_service_terms_store.get.no_rows.app_error")
+ success, resp := Client.RegisteTermsOfServiceAction(th.BasicUser.Id, "st_1", true)
+ CheckErrorMessage(t, resp, "store.sql_terms_of_service_store.get.no_rows.app_error")
- serviceTerms, err := th.App.CreateServiceTerms("service terms", th.BasicUser.Id)
+ termsOfService, err := th.App.CreateTermsOfService("terms of service", th.BasicUser.Id)
if err != nil {
t.Fatal(err)
}
- success, resp = Client.RegisterServiceTermsAction(th.BasicUser.Id, serviceTerms.Id, true)
+ success, resp = Client.RegisteTermsOfServiceAction(th.BasicUser.Id, termsOfService.Id, true)
CheckNoError(t, resp)
assert.True(t, *success)
@@ -3091,5 +3091,5 @@ func TestRegisterServiceTermsAction(t *testing.T) {
t.Fatal(err)
}
- assert.Equal(t, user.AcceptedServiceTermsId, serviceTerms.Id)
+ assert.Equal(t, user.AcceptedTermsOfServiceId, termsOfService.Id)
}