mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
eliminate more utils.Cfg references (#7701)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
51
api/user.go
51
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())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1517,32 +1517,6 @@ func TestUpdateUserMfa(t *testing.T) {
|
||||
|
||||
_, resp := Client.UpdateUserMfa(th.BasicUser.Id, "12345", false)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
/*
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
rteam, _ := Client.CreateTeam(&team)
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user)
|
||||
th.LinkUserToTeam(ruser, rteam)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
Client.Logout()
|
||||
_, resp := Client.UpdateUserMfa(ruser.Id, "12334", true)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
_, resp = Client.UpdateUserMfa("fail", "56789", false)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.UpdateUserMfa(ruser.Id, "", true)
|
||||
CheckErrorMessage(t, resp, "api.context.invalid_body_param.app_error")
|
||||
|
||||
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
|
||||
|
||||
_, resp = Client.UpdateUserMfa(ruser.Id, "123456", false)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
*/
|
||||
}
|
||||
|
||||
func TestCheckUserMfa(t *testing.T) {
|
||||
|
||||
@@ -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
|
||||
|
||||
34
app/email.go
34
app/email.go
@@ -14,18 +14,18 @@ import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
|
||||
func (a *App) SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.username_change_subject",
|
||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"],
|
||||
"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
"TeamDisplayName": a.Config().TeamSettings.SiteName})
|
||||
|
||||
bodyPage := utils.NewHTMLTemplate("email_change_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.username_change_body.title")
|
||||
bodyPage.Html["Info"] = utils.TranslateAsHtml(T, "api.templates.username_change_body.info",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName, "NewUsername": newUsername})
|
||||
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "NewUsername": newUsername})
|
||||
|
||||
if err := utils.SendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return model.NewAppError("SendChangeUsernameEmail", "api.user.send_email_change_username_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -34,20 +34,20 @@ func SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL st
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError {
|
||||
func (a *App) SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(newUserEmail))
|
||||
|
||||
subject := T("api.templates.email_change_verify_subject",
|
||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"],
|
||||
"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
"TeamDisplayName": a.Config().TeamSettings.SiteName})
|
||||
|
||||
bodyPage := utils.NewHTMLTemplate("email_change_verify_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.email_change_verify_body.title")
|
||||
bodyPage.Props["Info"] = T("api.templates.email_change_verify_body.info",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName})
|
||||
bodyPage.Props["VerifyUrl"] = link
|
||||
bodyPage.Props["VerifyButton"] = T("api.templates.email_change_verify_body.button")
|
||||
|
||||
@@ -58,18 +58,18 @@ func SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *mo
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError {
|
||||
func (a *App) SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.email_change_subject",
|
||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"],
|
||||
"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
"TeamDisplayName": a.Config().TeamSettings.SiteName})
|
||||
|
||||
bodyPage := utils.NewHTMLTemplate("email_change_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.email_change_body.title")
|
||||
bodyPage.Html["Info"] = utils.TranslateAsHtml(T, "api.templates.email_change_body.info",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName, "NewEmail": newEmail})
|
||||
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "NewEmail": newEmail})
|
||||
|
||||
if err := utils.SendMail(oldEmail, subject, bodyPage.Render()); err != nil {
|
||||
return model.NewAppError("SendEmailChangeEmail", "api.user.send_email_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -78,7 +78,7 @@ func SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.App
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError {
|
||||
func (a *App) SendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
link := fmt.Sprintf("%s/do_verify_email?token=%s&email=%s", siteURL, token, url.QueryEscape(userEmail))
|
||||
@@ -102,7 +102,7 @@ func SendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppError {
|
||||
func (a *App) SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.signin_change_email.subject",
|
||||
@@ -160,18 +160,18 @@ func (a *App) SendWelcomeEmail(userId string, email string, verified bool, local
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError {
|
||||
func (a *App) SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
subject := T("api.templates.password_change_subject",
|
||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"],
|
||||
"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
"TeamDisplayName": a.Config().TeamSettings.SiteName})
|
||||
|
||||
bodyPage := utils.NewHTMLTemplate("password_change_body", locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = T("api.templates.password_change_body.title")
|
||||
bodyPage.Html["Info"] = utils.TranslateAsHtml(T, "api.templates.password_change_body.info",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName, "TeamURL": siteURL, "Method": method})
|
||||
map[string]interface{}{"TeamDisplayName": a.Config().TeamSettings.SiteName, "TeamURL": siteURL, "Method": method})
|
||||
|
||||
if err := utils.SendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return model.NewAppError("SendPasswordChangeEmail", "api.user.send_password_change_email_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -248,7 +248,7 @@ func SendMfaChangeEmail(email string, activated bool, locale, siteURL string) *m
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendInviteEmails(team *model.Team, senderName string, invites []string, siteURL string) {
|
||||
func (a *App) SendInviteEmails(team *model.Team, senderName string, invites []string, siteURL string) {
|
||||
for _, invite := range invites {
|
||||
if len(invite) > 0 {
|
||||
senderRole := utils.T("api.team.invite_members.member")
|
||||
@@ -275,10 +275,10 @@ func SendInviteEmails(team *model.Team, senderName string, invites []string, sit
|
||||
props["name"] = team.Name
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
data := model.MapToJson(props)
|
||||
hash := utils.HashSha256(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
hash := utils.HashSha256(fmt.Sprintf("%v:%v", data, a.Config().EmailSettings.InviteSalt))
|
||||
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&h=%s", siteURL, url.QueryEscape(data), url.QueryEscape(hash))
|
||||
|
||||
if !utils.Cfg.EmailSettings.SendEmailNotifications {
|
||||
if !a.Config().EmailSettings.SendEmailNotifications {
|
||||
l4g.Info(utils.T("api.team.invite_members.sending.info"), invite, bodyPage.Props["Link"])
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapId, ldapPassword stri
|
||||
}
|
||||
|
||||
a.Go(func() {
|
||||
if err := SendSignInChangeEmail(user.Email, "AD/LDAP", user.Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendSignInChangeEmail(user.Email, "AD/LDAP", user.Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
@@ -103,7 +103,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
||||
T := utils.GetUserTranslations(user.Locale)
|
||||
|
||||
a.Go(func() {
|
||||
if err := SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -527,7 +527,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.ReadCloser, em
|
||||
}
|
||||
|
||||
a.Go(func() {
|
||||
if err := SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
@@ -760,7 +760,7 @@ func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *
|
||||
T := utils.GetUserTranslations(user.Locale)
|
||||
|
||||
a.Go(func() {
|
||||
if err := SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -109,7 +109,7 @@ func (a *App) RevokeAllSessions(userId string) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
RevokeWebrtcToken(session.Id)
|
||||
a.RevokeWebrtcToken(session.Id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
RevokeWebrtcToken(session.Id)
|
||||
a.RevokeWebrtcToken(session.Id)
|
||||
a.ClearSessionCacheForUser(session.UserId)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -675,7 +675,7 @@ func (a *App) InviteNewUsersToTeam(emailList []string, teamId, senderId string)
|
||||
}
|
||||
|
||||
nameFormat := *a.Config().TeamSettings.TeammateNameDisplay
|
||||
SendInviteEmails(team, user.GetDisplayName(nameFormat), emailList, utils.GetSiteURL())
|
||||
a.SendInviteEmails(team, user.GetDisplayName(nameFormat), emailList, utils.GetSiteURL())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
10
app/user.go
10
app/user.go
@@ -996,7 +996,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
if sendNotifications {
|
||||
if rusers[0].Email != rusers[1].Email {
|
||||
a.Go(func() {
|
||||
if err := SendEmailChangeEmail(rusers[1].Email, rusers[0].Email, rusers[0].Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendEmailChangeEmail(rusers[1].Email, rusers[0].Email, rusers[0].Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
@@ -1010,7 +1010,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
|
||||
if rusers[0].Username != rusers[1].Username {
|
||||
a.Go(func() {
|
||||
if err := SendChangeUsernameEmail(rusers[1].Username, rusers[0].Username, rusers[0].Email, rusers[0].Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendChangeUsernameEmail(rusers[1].Username, rusers[0].Username, rusers[0].Email, rusers[0].Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
@@ -1098,7 +1098,7 @@ func (a *App) UpdatePasswordSendEmail(user *model.User, newPassword, method stri
|
||||
}
|
||||
|
||||
a.Go(func() {
|
||||
if err := SendPasswordChangeEmail(user.Email, method, user.Locale, utils.GetSiteURL()); err != nil {
|
||||
if err := a.SendPasswordChangeEmail(user.Email, method, user.Locale, utils.GetSiteURL()); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
@@ -1304,9 +1304,9 @@ func (a *App) SendEmailVerification(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
if _, err := a.GetStatus(user.Id); err != nil {
|
||||
return SendVerifyEmail(user.Email, user.Locale, utils.GetSiteURL(), token.Token)
|
||||
return a.SendVerifyEmail(user.Email, user.Locale, utils.GetSiteURL(), token.Token)
|
||||
} else {
|
||||
return SendEmailChangeVerifyEmail(user.Email, user.Locale, utils.GetSiteURL(), token.Token)
|
||||
return a.SendEmailChangeVerifyEmail(user.Email, user.Locale, utils.GetSiteURL(), token.Token)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,58 +16,58 @@ import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func GetWebrtcInfoForSession(sessionId string) (*model.WebrtcInfoResponse, *model.AppError) {
|
||||
token, err := GetWebrtcToken(sessionId)
|
||||
func (a *App) GetWebrtcInfoForSession(sessionId string) (*model.WebrtcInfoResponse, *model.AppError) {
|
||||
token, err := a.GetWebrtcToken(sessionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &model.WebrtcInfoResponse{
|
||||
Token: token,
|
||||
GatewayUrl: *utils.Cfg.WebrtcSettings.GatewayWebsocketUrl,
|
||||
GatewayType: *utils.Cfg.WebrtcSettings.GatewayType,
|
||||
GatewayUrl: *a.Config().WebrtcSettings.GatewayWebsocketUrl,
|
||||
GatewayType: *a.Config().WebrtcSettings.GatewayType,
|
||||
}
|
||||
|
||||
if len(*utils.Cfg.WebrtcSettings.StunURI) > 0 {
|
||||
result.StunUri = *utils.Cfg.WebrtcSettings.StunURI
|
||||
if len(*a.Config().WebrtcSettings.StunURI) > 0 {
|
||||
result.StunUri = *a.Config().WebrtcSettings.StunURI
|
||||
}
|
||||
|
||||
if len(*utils.Cfg.WebrtcSettings.TurnURI) > 0 {
|
||||
if len(*a.Config().WebrtcSettings.TurnURI) > 0 {
|
||||
timestamp := strconv.FormatInt(utils.EndOfDay(time.Now().AddDate(0, 0, 1)).Unix(), 10)
|
||||
username := timestamp + ":" + *utils.Cfg.WebrtcSettings.TurnUsername
|
||||
username := timestamp + ":" + *a.Config().WebrtcSettings.TurnUsername
|
||||
|
||||
result.TurnUri = *utils.Cfg.WebrtcSettings.TurnURI
|
||||
result.TurnPassword = GenerateTurnPassword(username, *utils.Cfg.WebrtcSettings.TurnSharedKey)
|
||||
result.TurnUri = *a.Config().WebrtcSettings.TurnURI
|
||||
result.TurnPassword = GenerateTurnPassword(username, *a.Config().WebrtcSettings.TurnSharedKey)
|
||||
result.TurnUsername = username
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func GetWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
if !*utils.Cfg.WebrtcSettings.Enable {
|
||||
func (a *App) GetWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
if !*a.Config().WebrtcSettings.Enable {
|
||||
return "", model.NewAppError("WebRTC.getWebrtcToken", "api.webrtc.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
switch strings.ToLower(*utils.Cfg.WebrtcSettings.GatewayType) {
|
||||
switch strings.ToLower(*a.Config().WebrtcSettings.GatewayType) {
|
||||
case "kopano-webmeetings":
|
||||
return GetKopanoWebmeetingsWebrtcToken(sessionId)
|
||||
return a.GetKopanoWebmeetingsWebrtcToken(sessionId)
|
||||
default:
|
||||
// Default to Janus.
|
||||
return GetJanusWebrtcToken(sessionId)
|
||||
return a.GetJanusWebrtcToken(sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
func GetJanusWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
func (a *App) GetJanusWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
token := base64.StdEncoding.EncodeToString([]byte(sessionId))
|
||||
|
||||
data := make(map[string]string)
|
||||
data["janus"] = "add_token"
|
||||
data["token"] = token
|
||||
data["transaction"] = model.NewId()
|
||||
data["admin_secret"] = *utils.Cfg.WebrtcSettings.GatewayAdminSecret
|
||||
data["admin_secret"] = *a.Config().WebrtcSettings.GatewayAdminSecret
|
||||
|
||||
rq, _ := http.NewRequest("POST", *utils.Cfg.WebrtcSettings.GatewayAdminUrl, strings.NewReader(model.MapToJson(data)))
|
||||
rq, _ := http.NewRequest("POST", *a.Config().WebrtcSettings.GatewayAdminUrl, strings.NewReader(model.MapToJson(data)))
|
||||
rq.Header.Set("Content-Type", "application/json")
|
||||
|
||||
if rp, err := utils.HttpClient(true).Do(rq); err != nil {
|
||||
@@ -85,14 +85,14 @@ func GetJanusWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func GetKopanoWebmeetingsWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
func (a *App) GetKopanoWebmeetingsWebrtcToken(sessionId string) (string, *model.AppError) {
|
||||
data := make(map[string]string)
|
||||
data["type"] = "Token"
|
||||
data["id"] = sessionId
|
||||
|
||||
rq, _ := http.NewRequest("POST", *utils.Cfg.WebrtcSettings.GatewayAdminUrl+"/auth/tokens", strings.NewReader(model.MapToJson(data)))
|
||||
rq, _ := http.NewRequest("POST", *a.Config().WebrtcSettings.GatewayAdminUrl+"/auth/tokens", strings.NewReader(model.MapToJson(data)))
|
||||
rq.Header.Set("Content-Type", "application/json")
|
||||
rq.Header.Set("Authorization", "Bearer "+*utils.Cfg.WebrtcSettings.GatewayAdminSecret)
|
||||
rq.Header.Set("Authorization", "Bearer "+*a.Config().WebrtcSettings.GatewayAdminSecret)
|
||||
|
||||
if rp, err := utils.HttpClient(true).Do(rq); err != nil {
|
||||
return "", model.NewAppError("WebRTC.Token", "model.client.connecting.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -115,15 +115,15 @@ func GenerateTurnPassword(username string, secret string) string {
|
||||
return base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func RevokeWebrtcToken(sessionId string) {
|
||||
func (a *App) RevokeWebrtcToken(sessionId string) {
|
||||
token := base64.StdEncoding.EncodeToString([]byte(sessionId))
|
||||
data := make(map[string]string)
|
||||
data["janus"] = "remove_token"
|
||||
data["token"] = token
|
||||
data["transaction"] = model.NewId()
|
||||
data["admin_secret"] = *utils.Cfg.WebrtcSettings.GatewayAdminSecret
|
||||
data["admin_secret"] = *a.Config().WebrtcSettings.GatewayAdminSecret
|
||||
|
||||
rq, _ := http.NewRequest("POST", *utils.Cfg.WebrtcSettings.GatewayAdminUrl, strings.NewReader(model.MapToJson(data)))
|
||||
rq, _ := http.NewRequest("POST", *a.Config().WebrtcSettings.GatewayAdminUrl, strings.NewReader(model.MapToJson(data)))
|
||||
rq.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// we do not care about the response
|
||||
|
||||
@@ -273,7 +273,7 @@ func userInviteCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
teams := getTeamsFromTeamArgs(a, args[1:])
|
||||
for i, team := range teams {
|
||||
err := inviteUser(email, team, args[i+1])
|
||||
err := inviteUser(a, email, team, args[i+1])
|
||||
|
||||
if err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
@@ -283,13 +283,13 @@ func userInviteCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func inviteUser(email string, team *model.Team, teamArg string) error {
|
||||
func inviteUser(a *app.App, email string, team *model.Team, teamArg string) error {
|
||||
invites := []string{email}
|
||||
if team == nil {
|
||||
return fmt.Errorf("Can't find team '%v'", teamArg)
|
||||
}
|
||||
|
||||
app.SendInviteEmails(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL)
|
||||
a.SendInviteEmails(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL)
|
||||
CommandPrettyPrintln("Invites may or may not have been sent.")
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user