diff --git a/server/channels/api4/hosted_customer.go b/server/channels/api4/hosted_customer.go index ba73dc0e25..792c4a8df6 100644 --- a/server/channels/api4/hosted_customer.go +++ b/server/channels/api4/hosted_customer.go @@ -251,7 +251,7 @@ func selfHostedInvoices(c *Context, w http.ResponseWriter, r *http.Request) { return } - invoices, err := c.App.Cloud().GetSelfHostedInvoices() + invoices, err := c.App.Cloud().GetSelfHostedInvoices(c.AppContext) if err != nil { if err.Error() == "404" { diff --git a/server/channels/api4/ldap.go b/server/channels/api4/ldap.go index fe98c7eb37..b613b4b4f3 100644 --- a/server/channels/api4/ldap.go +++ b/server/channels/api4/ldap.go @@ -83,7 +83,7 @@ func testLdap(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := c.App.TestLdap(); err != nil { + if err := c.App.TestLdap(c.AppContext); err != nil { c.Err = err return } @@ -112,7 +112,7 @@ func getLdapGroups(c *Context, w http.ResponseWriter, r *http.Request) { opts.IsConfigured = c.Params.IsConfigured } - groups, total, appErr := c.App.GetAllLdapGroupsPage(c.Params.Page, c.Params.PerPage, opts) + groups, total, appErr := c.App.GetAllLdapGroupsPage(c.AppContext, c.Params.Page, c.Params.PerPage, opts) if appErr != nil { c.Err = appErr return @@ -163,7 +163,7 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) { return } - ldapGroup, appErr := c.App.GetLdapGroup(c.Params.RemoteId) + ldapGroup, appErr := c.App.GetLdapGroup(c.AppContext, c.Params.RemoteId) if appErr != nil { c.Err = appErr return diff --git a/server/channels/app/app_iface.go b/server/channels/app/app_iface.go index 3a8dfd2573..e1991a00c3 100644 --- a/server/channels/app/app_iface.go +++ b/server/channels/app/app_iface.go @@ -165,7 +165,7 @@ type AppIface interface { FilterNonGroupTeamMembers(userIDs []string, team *model.Team) ([]string, error) // GetAllLdapGroupsPage retrieves all LDAP groups under the configured base DN using the default or configured group // filter. - GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) + GetAllLdapGroupsPage(rctx request.CTX, page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) // GetBot returns the given bot. GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) // GetBots returns the requested page of bots. @@ -199,7 +199,7 @@ type AppIface interface { // GetLastAccessiblePostTime returns CreateAt time(from cache) of the last accessible post as per the cloud limit GetLastAccessiblePostTime() (int64, *model.AppError) // GetLdapGroup retrieves a single LDAP group by the given LDAP group id. - GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) + GetLdapGroup(rctx request.CTX, ldapGroupID string) (*model.Group, *model.AppError) // GetMarketplacePlugins returns a list of plugins from the marketplace-server, // and plugins that are installed locally. GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*model.MarketplacePlugin, *model.AppError) @@ -1100,7 +1100,7 @@ type AppIface interface { TestEmail(userID string, cfg *model.Config) *model.AppError TestFileStoreConnection() *model.AppError TestFileStoreConnectionWithConfig(cfg *model.FileSettings) *model.AppError - TestLdap() *model.AppError + TestLdap(rctx request.CTX) *model.AppError TestSiteURL(siteURL string) *model.AppError Timezones() *timezones.Timezones ToggleMuteChannel(c request.CTX, channelID, userID string) (*model.ChannelMember, *model.AppError) diff --git a/server/channels/app/ldap.go b/server/channels/app/ldap.go index 6e11115d7c..ed197053f0 100644 --- a/server/channels/app/ldap.go +++ b/server/channels/app/ldap.go @@ -35,10 +35,10 @@ func (a *App) SyncLdap(c request.CTX, includeRemovedMembers bool) { }) } -func (a *App) TestLdap() *model.AppError { +func (a *App) TestLdap(rctx request.CTX) *model.AppError { license := a.Srv().License() if ldapI := a.Ldap(); ldapI != nil && license != nil && *license.Features.LDAP && (*a.Config().LdapSettings.Enable || *a.Config().LdapSettings.EnableSync) { - if err := ldapI.RunTest(); err != nil { + if err := ldapI.RunTest(rctx); err != nil { err.StatusCode = 500 return err } @@ -51,12 +51,12 @@ func (a *App) TestLdap() *model.AppError { } // GetLdapGroup retrieves a single LDAP group by the given LDAP group id. -func (a *App) GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) { +func (a *App) GetLdapGroup(rctx request.CTX, ldapGroupID string) (*model.Group, *model.AppError) { var group *model.Group if a.Ldap() != nil { var err *model.AppError - group, err = a.Ldap().GetGroup(ldapGroupID) + group, err = a.Ldap().GetGroup(rctx, ldapGroupID) if err != nil { return nil, err } @@ -70,13 +70,13 @@ func (a *App) GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) { // GetAllLdapGroupsPage retrieves all LDAP groups under the configured base DN using the default or configured group // filter. -func (a *App) GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { +func (a *App) GetAllLdapGroupsPage(rctx request.CTX, page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { var groups []*model.Group var total int if a.Ldap() != nil { var err *model.AppError - groups, total, err = a.Ldap().GetAllGroupsPage(page, perPage, opts) + groups, total, err = a.Ldap().GetAllGroupsPage(rctx, page, perPage, opts) if err != nil { return nil, 0, err } diff --git a/server/channels/app/opentracing/opentracing_layer.go b/server/channels/app/opentracing/opentracing_layer.go index cf9e8090db..fbc5a75bc1 100644 --- a/server/channels/app/opentracing/opentracing_layer.go +++ b/server/channels/app/opentracing/opentracing_layer.go @@ -4771,7 +4771,7 @@ func (a *OpenTracingAppLayer) GetAllChannelsCount(c request.CTX, opts model.Chan return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { +func (a *OpenTracingAppLayer) GetAllLdapGroupsPage(rctx request.CTX, page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetAllLdapGroupsPage") @@ -4783,7 +4783,7 @@ func (a *OpenTracingAppLayer) GetAllLdapGroupsPage(page int, perPage int, opts m }() defer span.Finish() - resultVar0, resultVar1, resultVar2 := a.app.GetAllLdapGroupsPage(page, perPage, opts) + resultVar0, resultVar1, resultVar2 := a.app.GetAllLdapGroupsPage(rctx, page, perPage, opts) if resultVar2 != nil { span.LogFields(spanlog.Error(resultVar2)) @@ -7232,7 +7232,7 @@ func (a *OpenTracingAppLayer) GetLatestVersion(latestVersionUrl string) (*model. return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) { +func (a *OpenTracingAppLayer) GetLdapGroup(rctx request.CTX, ldapGroupID string) (*model.Group, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetLdapGroup") @@ -7244,7 +7244,7 @@ func (a *OpenTracingAppLayer) GetLdapGroup(ldapGroupID string) (*model.Group, *m }() defer span.Finish() - resultVar0, resultVar1 := a.app.GetLdapGroup(ldapGroupID) + resultVar0, resultVar1 := a.app.GetLdapGroup(rctx, ldapGroupID) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -16919,7 +16919,7 @@ func (a *OpenTracingAppLayer) TestFileStoreConnectionWithConfig(cfg *model.FileS return resultVar0 } -func (a *OpenTracingAppLayer) TestLdap() *model.AppError { +func (a *OpenTracingAppLayer) TestLdap(rctx request.CTX) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.TestLdap") @@ -16931,7 +16931,7 @@ func (a *OpenTracingAppLayer) TestLdap() *model.AppError { }() defer span.Finish() - resultVar0 := a.app.TestLdap() + resultVar0 := a.app.TestLdap(rctx) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) diff --git a/server/channels/app/plugin_api.go b/server/channels/app/plugin_api.go index 498527f655..4b723aac7d 100644 --- a/server/channels/app/plugin_api.go +++ b/server/channels/app/plugin_api.go @@ -409,7 +409,7 @@ func (api *PluginAPI) GetLDAPUserAttributes(userID string, attributes []string) // Only bother running the query if the user's auth service is LDAP or it's SAML and sync is enabled. if user.AuthService == model.UserAuthServiceLdap || (user.AuthService == model.UserAuthServiceSaml && *api.app.Config().SamlSettings.EnableSyncWithLdap) { - return api.app.Ldap().GetUserAttributes(*user.AuthData, attributes) + return api.app.Ldap().GetUserAttributes(api.ctx, *user.AuthData, attributes) } return map[string]string{}, nil diff --git a/server/channels/app/support_packet.go b/server/channels/app/support_packet.go index 0d81ae85d8..43ad969d79 100644 --- a/server/channels/app/support_packet.go +++ b/server/channels/app/support_packet.go @@ -96,7 +96,7 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error) var vendorName, vendorVersion string if ldapInterface := a.ch.Ldap; a.ch.Ldap != nil { - vendorName, vendorVersion = ldapInterface.GetVendorNameAndVendorVersion() + vendorName, vendorVersion = ldapInterface.GetVendorNameAndVendorVersion(c) } /* Elastic Search */ diff --git a/server/einterfaces/cloud.go b/server/einterfaces/cloud.go index edc897c39d..9b56dc413e 100644 --- a/server/einterfaces/cloud.go +++ b/server/einterfaces/cloud.go @@ -5,6 +5,7 @@ package einterfaces import ( "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/public/shared/request" ) type CloudInterface interface { @@ -39,7 +40,7 @@ type CloudInterface interface { ConfirmSelfHostedSignup(req model.SelfHostedConfirmPaymentMethodRequest, requesterEmail string) (*model.SelfHostedSignupConfirmResponse, error) ConfirmSelfHostedExpansion(req model.SelfHostedConfirmPaymentMethodRequest, requesterEmail string) (*model.SelfHostedSignupConfirmResponse, error) ConfirmSelfHostedSignupLicenseApplication() error - GetSelfHostedInvoices() ([]*model.Invoice, error) + GetSelfHostedInvoices(rctx request.CTX) ([]*model.Invoice, error) GetSelfHostedInvoicePDF(invoiceID string) ([]byte, string, error) CreateOrUpdateSubscriptionHistoryEvent(userID string, userCount int) (*model.SubscriptionHistory, error) diff --git a/server/einterfaces/ldap.go b/server/einterfaces/ldap.go index ae937ebcc7..a736988263 100644 --- a/server/einterfaces/ldap.go +++ b/server/einterfaces/ldap.go @@ -11,20 +11,20 @@ import ( type LdapInterface interface { DoLogin(c request.CTX, id string, password string) (*model.User, *model.AppError) GetUser(c request.CTX, id string) (*model.User, *model.AppError) - GetUserAttributes(id string, attributes []string) (map[string]string, *model.AppError) + GetUserAttributes(rctx request.CTX, id string, attributes []string) (map[string]string, *model.AppError) CheckPassword(c request.CTX, id string, password string) *model.AppError CheckPasswordAuthData(c request.CTX, authData string, password string) *model.AppError CheckProviderAttributes(c request.CTX, LS *model.LdapSettings, ouser *model.User, patch *model.UserPatch) string SwitchToLdap(c request.CTX, userID, ldapID, ldapPassword string) *model.AppError StartSynchronizeJob(c request.CTX, waitForJobToFinish bool, includeRemovedMembers bool) (*model.Job, *model.AppError) - RunTest() *model.AppError + RunTest(rctx request.CTX) *model.AppError GetAllLdapUsers(c request.CTX) ([]*model.User, *model.AppError) MigrateIDAttribute(c request.CTX, toAttribute string) error - GetGroup(groupUID string) (*model.Group, *model.AppError) - GetAllGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) + GetGroup(rctx request.CTX, groupUID string) (*model.Group, *model.AppError) + GetAllGroupsPage(rctx request.CTX, page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) FirstLoginSync(c request.CTX, user *model.User, userAuthService, userAuthData, email string) *model.AppError UpdateProfilePictureIfNecessary(request.CTX, model.User, model.Session) GetADLdapIdFromSAMLId(c request.CTX, authData string) string GetSAMLIdFromADLdapId(c request.CTX, authData string) string - GetVendorNameAndVendorVersion() (string, string) + GetVendorNameAndVendorVersion(rctx request.CTX) (string, string) } diff --git a/server/einterfaces/mocks/CloudInterface.go b/server/einterfaces/mocks/CloudInterface.go index 74541356ae..5fb6f19646 100644 --- a/server/einterfaces/mocks/CloudInterface.go +++ b/server/einterfaces/mocks/CloudInterface.go @@ -6,6 +6,7 @@ package mocks import ( model "github.com/mattermost/mattermost/server/public/model" + request "github.com/mattermost/mattermost/server/public/shared/request" mock "github.com/stretchr/testify/mock" ) @@ -460,25 +461,25 @@ func (_m *CloudInterface) GetSelfHostedInvoicePDF(invoiceID string) ([]byte, str return r0, r1, r2 } -// GetSelfHostedInvoices provides a mock function with given fields: -func (_m *CloudInterface) GetSelfHostedInvoices() ([]*model.Invoice, error) { - ret := _m.Called() +// GetSelfHostedInvoices provides a mock function with given fields: rctx +func (_m *CloudInterface) GetSelfHostedInvoices(rctx request.CTX) ([]*model.Invoice, error) { + ret := _m.Called(rctx) var r0 []*model.Invoice var r1 error - if rf, ok := ret.Get(0).(func() ([]*model.Invoice, error)); ok { - return rf() + if rf, ok := ret.Get(0).(func(request.CTX) ([]*model.Invoice, error)); ok { + return rf(rctx) } - if rf, ok := ret.Get(0).(func() []*model.Invoice); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(request.CTX) []*model.Invoice); ok { + r0 = rf(rctx) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*model.Invoice) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(request.CTX) error); ok { + r1 = rf(rctx) } else { r1 = ret.Error(1) } diff --git a/server/einterfaces/mocks/LdapInterface.go b/server/einterfaces/mocks/LdapInterface.go index 085f6a99f4..665f65451a 100644 --- a/server/einterfaces/mocks/LdapInterface.go +++ b/server/einterfaces/mocks/LdapInterface.go @@ -119,32 +119,32 @@ func (_m *LdapInterface) GetADLdapIdFromSAMLId(c request.CTX, authData string) s return r0 } -// GetAllGroupsPage provides a mock function with given fields: page, perPage, opts -func (_m *LdapInterface) GetAllGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { - ret := _m.Called(page, perPage, opts) +// GetAllGroupsPage provides a mock function with given fields: rctx, page, perPage, opts +func (_m *LdapInterface) GetAllGroupsPage(rctx request.CTX, page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) { + ret := _m.Called(rctx, page, perPage, opts) var r0 []*model.Group var r1 int var r2 *model.AppError - if rf, ok := ret.Get(0).(func(int, int, model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError)); ok { - return rf(page, perPage, opts) + if rf, ok := ret.Get(0).(func(request.CTX, int, int, model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError)); ok { + return rf(rctx, page, perPage, opts) } - if rf, ok := ret.Get(0).(func(int, int, model.LdapGroupSearchOpts) []*model.Group); ok { - r0 = rf(page, perPage, opts) + if rf, ok := ret.Get(0).(func(request.CTX, int, int, model.LdapGroupSearchOpts) []*model.Group); ok { + r0 = rf(rctx, page, perPage, opts) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*model.Group) } } - if rf, ok := ret.Get(1).(func(int, int, model.LdapGroupSearchOpts) int); ok { - r1 = rf(page, perPage, opts) + if rf, ok := ret.Get(1).(func(request.CTX, int, int, model.LdapGroupSearchOpts) int); ok { + r1 = rf(rctx, page, perPage, opts) } else { r1 = ret.Get(1).(int) } - if rf, ok := ret.Get(2).(func(int, int, model.LdapGroupSearchOpts) *model.AppError); ok { - r2 = rf(page, perPage, opts) + if rf, ok := ret.Get(2).(func(request.CTX, int, int, model.LdapGroupSearchOpts) *model.AppError); ok { + r2 = rf(rctx, page, perPage, opts) } else { if ret.Get(2) != nil { r2 = ret.Get(2).(*model.AppError) @@ -182,25 +182,25 @@ func (_m *LdapInterface) GetAllLdapUsers(c request.CTX) ([]*model.User, *model.A return r0, r1 } -// GetGroup provides a mock function with given fields: groupUID -func (_m *LdapInterface) GetGroup(groupUID string) (*model.Group, *model.AppError) { - ret := _m.Called(groupUID) +// GetGroup provides a mock function with given fields: rctx, groupUID +func (_m *LdapInterface) GetGroup(rctx request.CTX, groupUID string) (*model.Group, *model.AppError) { + ret := _m.Called(rctx, groupUID) var r0 *model.Group var r1 *model.AppError - if rf, ok := ret.Get(0).(func(string) (*model.Group, *model.AppError)); ok { - return rf(groupUID) + if rf, ok := ret.Get(0).(func(request.CTX, string) (*model.Group, *model.AppError)); ok { + return rf(rctx, groupUID) } - if rf, ok := ret.Get(0).(func(string) *model.Group); ok { - r0 = rf(groupUID) + if rf, ok := ret.Get(0).(func(request.CTX, string) *model.Group); ok { + r0 = rf(rctx, groupUID) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*model.Group) } } - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { - r1 = rf(groupUID) + if rf, ok := ret.Get(1).(func(request.CTX, string) *model.AppError); ok { + r1 = rf(rctx, groupUID) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*model.AppError) @@ -252,25 +252,25 @@ func (_m *LdapInterface) GetUser(c request.CTX, id string) (*model.User, *model. return r0, r1 } -// GetUserAttributes provides a mock function with given fields: id, attributes -func (_m *LdapInterface) GetUserAttributes(id string, attributes []string) (map[string]string, *model.AppError) { - ret := _m.Called(id, attributes) +// GetUserAttributes provides a mock function with given fields: rctx, id, attributes +func (_m *LdapInterface) GetUserAttributes(rctx request.CTX, id string, attributes []string) (map[string]string, *model.AppError) { + ret := _m.Called(rctx, id, attributes) var r0 map[string]string var r1 *model.AppError - if rf, ok := ret.Get(0).(func(string, []string) (map[string]string, *model.AppError)); ok { - return rf(id, attributes) + if rf, ok := ret.Get(0).(func(request.CTX, string, []string) (map[string]string, *model.AppError)); ok { + return rf(rctx, id, attributes) } - if rf, ok := ret.Get(0).(func(string, []string) map[string]string); ok { - r0 = rf(id, attributes) + if rf, ok := ret.Get(0).(func(request.CTX, string, []string) map[string]string); ok { + r0 = rf(rctx, id, attributes) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(map[string]string) } } - if rf, ok := ret.Get(1).(func(string, []string) *model.AppError); ok { - r1 = rf(id, attributes) + if rf, ok := ret.Get(1).(func(request.CTX, string, []string) *model.AppError); ok { + r1 = rf(rctx, id, attributes) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*model.AppError) @@ -280,23 +280,23 @@ func (_m *LdapInterface) GetUserAttributes(id string, attributes []string) (map[ return r0, r1 } -// GetVendorNameAndVendorVersion provides a mock function with given fields: -func (_m *LdapInterface) GetVendorNameAndVendorVersion() (string, string) { - ret := _m.Called() +// GetVendorNameAndVendorVersion provides a mock function with given fields: rctx +func (_m *LdapInterface) GetVendorNameAndVendorVersion(rctx request.CTX) (string, string) { + ret := _m.Called(rctx) var r0 string var r1 string - if rf, ok := ret.Get(0).(func() (string, string)); ok { - return rf() + if rf, ok := ret.Get(0).(func(request.CTX) (string, string)); ok { + return rf(rctx) } - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(request.CTX) string); ok { + r0 = rf(rctx) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func() string); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(request.CTX) string); ok { + r1 = rf(rctx) } else { r1 = ret.Get(1).(string) } @@ -318,13 +318,13 @@ func (_m *LdapInterface) MigrateIDAttribute(c request.CTX, toAttribute string) e return r0 } -// RunTest provides a mock function with given fields: -func (_m *LdapInterface) RunTest() *model.AppError { - ret := _m.Called() +// RunTest provides a mock function with given fields: rctx +func (_m *LdapInterface) RunTest(rctx request.CTX) *model.AppError { + ret := _m.Called(rctx) var r0 *model.AppError - if rf, ok := ret.Get(0).(func() *model.AppError); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(request.CTX) *model.AppError); ok { + r0 = rf(rctx) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*model.AppError) diff --git a/server/public/model/config.go b/server/public/model/config.go index 9d40e04d42..60378dfe3d 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -2310,6 +2310,7 @@ type LdapSettings struct { LoginButtonBorderColor *string `access:"experimental_features"` LoginButtonTextColor *string `access:"experimental_features"` + // Deprecated: Use LogSettings.AdvancedLoggingJSON with the LDAPTrace level instead. Trace *bool `access:"authentication_ldap"` // telemetry: none }