From 10ae28e320f547232361fe7dee6164b624bf855a Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Mon, 13 Mar 2023 12:20:27 -0400 Subject: [PATCH] Fix all occurances of checking for RemoteClusterServiceLicense (#22453) --- app/server.go | 2 +- model/license.go | 15 +++++++++++++++ web/context.go | 2 +- web/handlers.go | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/server.go b/app/server.go index 5f7e12d982..490b3ce870 100644 --- a/app/server.go +++ b/app/server.go @@ -579,7 +579,7 @@ func (s *Server) startInterClusterServices(license *model.License) error { // Remote Cluster service // License check (assume enabled if shared channels enabled) - if !*license.Features.RemoteClusterService && !license.HasSharedChannels() { + if !license.HasRemoteClusterService() && !license.HasSharedChannels() { mlog.Debug("License does not have Remote Cluster services enabled") return nil } diff --git a/model/license.go b/model/license.go index 7c875dad32..cf5421bf02 100644 --- a/model/license.go +++ b/model/license.go @@ -321,6 +321,21 @@ func (l *License) HasEnterpriseMarketplacePlugins() bool { l.SkuShortName == LicenseShortSkuEnterprise } +func (l *License) HasRemoteClusterService() bool { + if l == nil { + return false + } + + // If SharedChannels is enabled then RemoteClusterService must be enabled. + if l.HasSharedChannels() { + return true + } + + return (l.Features != nil && l.Features.RemoteClusterService != nil && *l.Features.RemoteClusterService) || + l.SkuShortName == LicenseShortSkuProfessional || + l.SkuShortName == LicenseShortSkuEnterprise +} + func (l *License) HasSharedChannels() bool { if l == nil { return false diff --git a/web/context.go b/web/context.go index 2286f806c6..6010bd12fa 100644 --- a/web/context.go +++ b/web/context.go @@ -145,7 +145,7 @@ func (c *Context) CloudKeyRequired() { } func (c *Context) RemoteClusterTokenRequired() { - if license := c.App.Channels().License(); license == nil || !*license.Features.RemoteClusterService || c.AppContext.Session().Props[model.SessionPropType] != model.SessionTypeRemoteclusterToken { + if license := c.App.Channels().License(); license == nil || !license.HasRemoteClusterService() || c.AppContext.Session().Props[model.SessionPropType] != model.SessionTypeRemoteclusterToken { c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "TokenRequired", http.StatusUnauthorized) return } diff --git a/web/handlers.go b/web/handlers.go index b2d49742ab..028005aab6 100644 --- a/web/handlers.go +++ b/web/handlers.go @@ -302,7 +302,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } else { c.AppContext.SetSession(session) } - } else if token != "" && c.App.Channels().License() != nil && *c.App.Channels().License().Features.RemoteClusterService && tokenLocation == app.TokenLocationRemoteClusterHeader { + } else if token != "" && c.App.Channels().License() != nil && c.App.Channels().License().HasRemoteClusterService() && tokenLocation == app.TokenLocationRemoteClusterHeader { // Get the remote cluster if remoteId := c.GetRemoteID(r); remoteId == "" { c.Logger.Warn("Missing remote cluster id") //