mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
parent
6343e0e89f
commit
fee6606606
@ -83,7 +83,18 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
c.App.Srv().Go(func() {
|
||||
cloudWorkspaceOwnerEmailAddress := ""
|
||||
if c.App.License().IsCloud() {
|
||||
portalUserCustomer, cErr := c.App.Cloud().GetCloudCustomer(c.AppContext.Session().UserId)
|
||||
if cErr != nil {
|
||||
mlog.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 {
|
||||
mlog.Error("Failed to get initiating user", mlog.Err(err))
|
||||
@ -94,23 +105,12 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
mlog.Error("Failed to get system admins", mlog.Err(err))
|
||||
}
|
||||
|
||||
cloudWorkspaceOwnerEmailAddress := ""
|
||||
if c.App.License().IsCloud() {
|
||||
portalUserCustomer, cErr := c.App.Cloud().GetCloudCustomer(c.AppContext.Session().UserId)
|
||||
if cErr != nil {
|
||||
mlog.Error("Failed to get portal user customer", mlog.Err(cErr))
|
||||
}
|
||||
if cErr == nil && portalUserCustomer != nil {
|
||||
cloudWorkspaceOwnerEmailAddress = portalUserCustomer.Email
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
mlog.Error("Error while sending IP filters changed email", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
})
|
||||
}()
|
||||
|
||||
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)
|
||||
|
@ -136,20 +136,9 @@ func Test_applyIPFilters(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
lic := &model.License{
|
||||
Features: &model.Features{
|
||||
CustomPermissionsSchemes: model.NewBool(false),
|
||||
Cloud: model.NewBool(true),
|
||||
},
|
||||
Customer: &model.Customer{
|
||||
Name: "TestName",
|
||||
Email: "test@example.com",
|
||||
},
|
||||
SkuName: "SKU NAME",
|
||||
SkuShortName: model.LicenseShortSkuEnterprise,
|
||||
StartsAt: model.GetMillis() - 1000,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
}
|
||||
lic := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise, "cloud")
|
||||
lic.Id = "testlicenseid"
|
||||
|
||||
// Initialize the allowedRanges variable
|
||||
t.Run("No license returns 501", func(t *testing.T) {
|
||||
os.Setenv("MM_FEATUREFLAGS_CLOUDIPFILTERING", "true")
|
||||
@ -224,6 +213,8 @@ func Test_applyIPFilters(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv().SetLicense(lic)
|
||||
|
||||
ipFiltering := &mocks.IPFilteringInterface{}
|
||||
ipFiltering.Mock.On("ApplyIPFilters", mock.Anything).Return(&model.AllowedIPRanges{
|
||||
model.AllowedIPRange{
|
||||
@ -237,7 +228,16 @@ func Test_applyIPFilters(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().IPFiltering = ipFiltering
|
||||
|
||||
th.App.Srv().SetLicense(lic)
|
||||
cloud := &mocks.CloudInterface{}
|
||||
cloud.Mock.On("GetCloudCustomer", mock.Anything).Return(&model.CloudCustomer{
|
||||
CloudCustomerInfo: model.CloudCustomerInfo{Email: "test@localhost"},
|
||||
}, nil)
|
||||
|
||||
cloudImpl := th.App.Srv().Cloud
|
||||
defer func() {
|
||||
th.App.Srv().Cloud = cloudImpl
|
||||
}()
|
||||
th.App.Srv().Cloud = cloud
|
||||
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user