diff --git a/server/channels/api4/ip_filtering.go b/server/channels/api4/ip_filtering.go index a130cf443c..477e938d9e 100644 --- a/server/channels/api4/ip_filtering.go +++ b/server/channels/api4/ip_filtering.go @@ -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) diff --git a/server/channels/app/app_iface.go b/server/channels/app/app_iface.go index c9608c4e37..d39a8a06cf 100644 --- a/server/channels/app/app_iface.go +++ b/server/channels/app/app_iface.go @@ -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) diff --git a/server/channels/app/ip_filtering.go b/server/channels/app/ip_filtering.go new file mode 100644 index 0000000000..a56204c2f1 --- /dev/null +++ b/server/channels/app/ip_filtering.go @@ -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 +} diff --git a/server/channels/app/opentracing/opentracing_layer.go b/server/channels/app/opentracing/opentracing_layer.go index aa7d0188e3..05f0773837 100644 --- a/server/channels/app/opentracing/opentracing_layer.go +++ b/server/channels/app/opentracing/opentracing_layer.go @@ -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")