summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-24 09:00:05 -0700
committerGitHub <noreply@github.com>2017-10-24 09:00:05 -0700
commit2a2af0e390e0323e02919598881783f38131b5ee (patch)
treee8e9dc4e3d7aecb93f0b67b1f6dcf238af7deadb /api
parent673df81669ebb1f8ec278f3cb86fadcc09f5d030 (diff)
downloadchat-2a2af0e390e0323e02919598881783f38131b5ee.tar.gz
chat-2a2af0e390e0323e02919598881783f38131b5ee.tar.bz2
chat-2a2af0e390e0323e02919598881783f38131b5ee.zip
eliminate more utils.Cfg references (#7701)
Diffstat (limited to 'api')
-rw-r--r--api/admin_test.go84
-rw-r--r--api/oauth_test.go68
-rw-r--r--api/user.go51
-rw-r--r--api/webrtc.go3
4 files changed, 2 insertions, 204 deletions
diff --git a/api/admin_test.go b/api/admin_test.go
index 5c11d5a5c..a9d59000d 100644
--- a/api/admin_test.go
+++ b/api/admin_test.go
@@ -358,90 +358,6 @@ func TestGetTeamAnalyticsStandard(t *testing.T) {
}
}
-/*func TestGetPostCount(t *testing.T) {
- th := Setup().InitBasic().InitSystemAdmin()
-
- // manually update creation time, since it's always set to 0 upon saving and we only retrieve posts < today
- app.Srv.Store.(*store.SqlStore).GetMaster().Exec("UPDATE Posts SET CreateAt = :CreateAt WHERE ChannelId = :ChannelId",
- map[string]interface{}{"ChannelId": th.BasicChannel.Id, "CreateAt": utils.MillisFromTime(utils.Yesterday())})
-
- if _, err := th.BasicClient.GetTeamAnalytics(th.BasicTeam.Id, "post_counts_day"); err == nil {
- t.Fatal("Shouldn't have permissions")
- }
-
- maxUsersForStats := *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics
- defer func() {
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats
- }()
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000
-
- if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "post_counts_day"); err != nil {
- t.Fatal(err)
- } else {
- rows := result.Data.(model.AnalyticsRows)
-
- if rows[0].Value != 1 {
- t.Log(rows.ToJson())
- t.Fatal()
- }
- }
-
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1
-
- if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "post_counts_day"); err != nil {
- t.Fatal(err)
- } else {
- rows := result.Data.(model.AnalyticsRows)
-
- if rows[0].Value != -1 {
- t.Log(rows.ToJson())
- t.Fatal()
- }
- }
-}
-
-func TestUserCountsWithPostsByDay(t *testing.T) {
- th := Setup().InitBasic().InitSystemAdmin()
-
- // manually update creation time, since it's always set to 0 upon saving and we only retrieve posts < today
- app.Srv.Store.(*store.SqlStore).GetMaster().Exec("UPDATE Posts SET CreateAt = :CreateAt WHERE ChannelId = :ChannelId",
- map[string]interface{}{"ChannelId": th.BasicChannel.Id, "CreateAt": utils.MillisFromTime(utils.Yesterday())})
-
- if _, err := th.BasicClient.GetTeamAnalytics(th.BasicTeam.Id, "user_counts_with_posts_day"); err == nil {
- t.Fatal("Shouldn't have permissions")
- }
-
- maxUsersForStats := *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics
- defer func() {
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = maxUsersForStats
- }()
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1000000
-
- if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "user_counts_with_posts_day"); err != nil {
- t.Fatal(err)
- } else {
- rows := result.Data.(model.AnalyticsRows)
-
- if rows[0].Value != 1 {
- t.Log(rows.ToJson())
- t.Fatal()
- }
- }
-
- *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics = 1
-
- if result, err := th.SystemAdminClient.GetTeamAnalytics(th.BasicTeam.Id, "user_counts_with_posts_day"); err != nil {
- t.Fatal(err)
- } else {
- rows := result.Data.(model.AnalyticsRows)
-
- if rows[0].Value != -1 {
- t.Log(rows.ToJson())
- t.Fatal()
- }
- }
-}*/
-
func TestGetTeamAnalyticsExtra(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
diff --git a/api/oauth_test.go b/api/oauth_test.go
index 1510e3520..0b18a4e47 100644
--- a/api/oauth_test.go
+++ b/api/oauth_test.go
@@ -489,74 +489,6 @@ func TestOAuthDeleteApp(t *testing.T) {
}
}
-/*func TestOAuthAuthorize(t *testing.T) {
- if testing.Short() {
- t.SkipNow()
- }
-
- th := Setup().InitBasic()
- Client := th.BasicClient
-
- enableOAuth := utils.Cfg.ServiceSettings.EnableOAuthServiceProvider
- adminOnly := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
- defer func() {
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly
- utils.SetDefaultRolesBasedOnConfig()
- }()
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
- utils.SetDefaultRolesBasedOnConfig()
-
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
- if r, err := HttpGet(Client.Url+"/oauth/authorize", Client.HttpClient, "", true); err == nil {
- t.Fatal("should have failed - oauth providing turned off")
- closeBody(r)
- }
- }
-
- utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
- if r, err := HttpGet(Client.Url+"/oauth/authorize", Client.HttpClient, "", true); err == nil {
- t.Fatal("should have failed - scope not provided")
- closeBody(r)
- }
-
- if r, err := HttpGet(Client.Url+"/oauth/authorize?client_id=bad&&redirect_uri=http://example.com&response_type="+model.AUTHCODE_RESPONSE_TYPE, Client.HttpClient, "", true); err == nil {
- t.Fatal("should have failed - scope not provided")
- closeBody(r)
- }
-
- // register an app to authorize it
- oauthApp := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://example.com"}}
- oauthApp = Client.Must(Client.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
- if r, err := HttpGet(Client.Url+"/oauth/authorize?client_id="+oauthApp.Id+"&&redirect_uri=http://example.com&response_type="+model.AUTHCODE_RESPONSE_TYPE, Client.HttpClient, "", true); err == nil {
- t.Fatal("should have failed - user not logged")
- closeBody(r)
- }
-
- authToken := Client.AuthType + " " + Client.AuthToken
- if _, err := HttpGet(Client.Url+"/oauth/authorize?client_id="+oauthApp.Id+"&redirect_uri=http://bad-redirect.com&response_type="+model.AUTHCODE_RESPONSE_TYPE, Client.HttpClient, authToken, true); err == nil {
- t.Fatal("should have failed - bad redirect uri")
- }
-
- if _, err := HttpGet(Client.Url+"/oauth/authorize?client_id="+oauthApp.Id+"&redirect_uri=https://example.com&response_type="+model.AUTHCODE_RESPONSE_TYPE, Client.HttpClient, authToken, true); err != nil {
- t.Fatal(err)
- }
-
- // lets authorize the app
- if _, err := Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, oauthApp.Id, oauthApp.CallbackUrls[0], "user", ""); err != nil {
- t.Fatal(err)
- }
-
- if r, err := HttpGet(Client.Url+"/oauth/authorize?client_id="+oauthApp.Id+"&&redirect_uri="+oauthApp.CallbackUrls[0]+"&response_type="+model.AUTHCODE_RESPONSE_TYPE,
- Client.HttpClient, authToken, true); err != nil {
- // it will return an error as there is no connection to https://nowhere.com
- if r != nil {
- closeBody(r)
- }
- }
-}*/
-
func TestOAuthAccessToken(t *testing.T) {
if testing.Short() {
t.SkipNow()
diff --git a/api/user.go b/api/user.go
index 365e082ae..9e31e68ec 100644
--- a/api/user.go
+++ b/api/user.go
@@ -985,55 +985,6 @@ func ldapToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(model.MapToJson(map[string]string{"follow_link": link})))
}
-/* Disabling for security reasons. Use apiv4
-func verifyEmail(c *Context, w http.ResponseWriter, r *http.Request) {
- props := model.MapFromJson(r.Body)
-
- userId := props["uid"]
- if len(userId) != 26 {
- c.SetInvalidParam("verifyEmail", "uid")
- return
- }
-
- hashedId := props["hid"]
- if len(hashedId) == 0 {
- c.SetInvalidParam("verifyEmail", "hid")
- return
- }
-
- if model.ComparePassword(hashedId, userId+utils.Cfg.EmailSettings.InviteSalt) {
- if c.Err = app.VerifyUserEmail(userId); c.Err != nil {
- return
- } else {
- c.LogAudit("Email Verified")
- return
- }
- }
-
- c.Err = model.NewAppError("verifyEmail", "api.user.verify_email.bad_link.app_error", nil, "", http.StatusBadRequest)
-}
-
-func resendVerification(c *Context, w http.ResponseWriter, r *http.Request) {
- props := model.MapFromJson(r.Body)
-
- email := props["email"]
- if len(email) == 0 {
- c.SetInvalidParam("resendVerification", "email")
- return
- }
-
- if user, error := app.GetUserForLogin(email, false); error != nil {
- c.Err = error
- return
- } else {
- if _, err := app.GetStatus(user.Id); err != nil {
- go app.SendVerifyEmail(user.Id, user.Email, user.Locale, utils.GetSiteURL())
- } else {
- go app.SendEmailChangeVerifyEmail(user.Id, user.Email, user.Locale, utils.GetSiteURL())
- }
- }
-}*/
-
func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
secret, err := c.App.GenerateMfaSecret(c.Session.UserId)
if err != nil {
@@ -1224,7 +1175,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
}
c.LogAuditWithUserId(user.Id, "Revoked all sessions for user")
c.App.Go(func() {
- if err := app.SendSignInChangeEmail(user.Email, strings.Title(model.USER_AUTH_SERVICE_SAML)+" SSO", user.Locale, utils.GetSiteURL()); err != nil {
+ if err := c.App.SendSignInChangeEmail(user.Email, strings.Title(model.USER_AUTH_SERVICE_SAML)+" SSO", user.Locale, utils.GetSiteURL()); err != nil {
l4g.Error(err.Error())
}
})
diff --git a/api/webrtc.go b/api/webrtc.go
index 96ff67e56..92c44159f 100644
--- a/api/webrtc.go
+++ b/api/webrtc.go
@@ -7,7 +7,6 @@ import (
"net/http"
l4g "github.com/alecthomas/log4go"
- "github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/utils"
)
@@ -18,7 +17,7 @@ func (api *API) InitWebrtc() {
}
func webrtcToken(c *Context, w http.ResponseWriter, r *http.Request) {
- result, err := app.GetWebrtcInfoForSession(c.Session.Id)
+ result, err := c.App.GetWebrtcInfoForSession(c.Session.Id)
if err != nil {
c.Err = err