mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[CLD-6630] Cleanup: Refactor IP Filters email notification logic into app layer (#26072)
* Refactor IP Filters email notification logic into app layer * Forgot to git add
This commit is contained in:
parent
7d8a56019b
commit
287962a309
@ -4,12 +4,10 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
@ -83,34 +81,7 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
cloudWorkspaceOwnerEmailAddress := ""
|
||||
if c.App.License().IsCloud() {
|
||||
portalUserCustomer, cErr := c.App.Cloud().GetCloudCustomer(c.AppContext.Session().UserId)
|
||||
if cErr != nil {
|
||||
c.Logger.Error("Failed to get portal user customer", mlog.Err(cErr))
|
||||
}
|
||||
if cErr == nil && portalUserCustomer != nil {
|
||||
cloudWorkspaceOwnerEmailAddress = portalUserCustomer.Email
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
initiatingUser, err := c.App.Srv().Store().User().GetProfileByIds(context.Background(), []string{c.AppContext.Session().UserId}, nil, true)
|
||||
if err != nil {
|
||||
c.Logger.Error("Failed to get initiating user", mlog.Err(err))
|
||||
}
|
||||
|
||||
users, err := c.App.Srv().Store().User().GetSystemAdminProfiles()
|
||||
if err != nil {
|
||||
c.Logger.Error("Failed to get system admins", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
if err = c.App.Srv().EmailService.SendIPFiltersChangedEmail(user.Email, initiatingUser[0], *c.App.Config().ServiceSettings.SiteURL, *c.App.Config().CloudSettings.CWSURL, user.Locale, cloudWorkspaceOwnerEmailAddress == user.Email); err != nil {
|
||||
c.Logger.Error("Error while sending IP filters changed email", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}()
|
||||
go c.App.SendIPFiltersChangedEmail(c.AppContext, c.AppContext.Session().UserId)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(updatedAllowedRanges); err != nil {
|
||||
c.Err = model.NewAppError("getIPFilters", "api.context.ip_filtering.get_ip_filters.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -1076,6 +1076,7 @@ type AppIface interface {
|
||||
SendDelinquencyEmail(emailToSend model.DelinquencyEmail) *model.AppError
|
||||
SendEmailVerification(user *model.User, newEmail, redirect string) *model.AppError
|
||||
SendEphemeralPost(c request.CTX, userID string, post *model.Post) *model.Post
|
||||
SendIPFiltersChangedEmail(c request.CTX, userID string) error
|
||||
SendNotifications(c request.CTX, post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error)
|
||||
SendNotifyAdminPosts(c request.CTX, workspaceName string, currentSKU string, trial bool) *model.AppError
|
||||
SendPasswordReset(email string, siteURL string) (bool, *model.AppError)
|
||||
|
42
server/channels/app/ip_filtering.go
Normal file
42
server/channels/app/ip_filtering.go
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func (a *App) SendIPFiltersChangedEmail(c request.CTX, userID string) error {
|
||||
cloudWorkspaceOwnerEmailAddress := ""
|
||||
if a.License().IsCloud() {
|
||||
portalUserCustomer, cErr := a.Cloud().GetCloudCustomer(userID)
|
||||
if cErr != nil {
|
||||
c.Logger().Error("Failed to get portal user customer", mlog.Err(cErr))
|
||||
}
|
||||
if cErr == nil && portalUserCustomer != nil {
|
||||
cloudWorkspaceOwnerEmailAddress = portalUserCustomer.Email
|
||||
}
|
||||
}
|
||||
|
||||
initiatingUser, err := a.Srv().Store().User().GetProfileByIds(context.Background(), []string{userID}, nil, true)
|
||||
if err != nil {
|
||||
c.Logger().Error("Failed to get initiating user", mlog.Err(err))
|
||||
}
|
||||
|
||||
users, err := a.Srv().Store().User().GetSystemAdminProfiles()
|
||||
if err != nil {
|
||||
c.Logger().Error("Failed to get system admins", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
if err = a.Srv().EmailService.SendIPFiltersChangedEmail(user.Email, initiatingUser[0], *a.Config().ServiceSettings.SiteURL, *a.Config().CloudSettings.CWSURL, user.Locale, cloudWorkspaceOwnerEmailAddress == user.Email); err != nil {
|
||||
c.Logger().Error("Error while sending IP filters changed email", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -15850,6 +15850,28 @@ func (a *OpenTracingAppLayer) SendEphemeralPost(c request.CTX, userID string, po
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SendIPFiltersChangedEmail(c request.CTX, userID string) error {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendIPFiltersChangedEmail")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SendIPFiltersChangedEmail(c, userID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SendNoCardPaymentFailedEmail() *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SendNoCardPaymentFailedEmail")
|
||||
|
Loading…
Reference in New Issue
Block a user