From f89168762d7fc65160ffec36535a3836012ef094 Mon Sep 17 00:00:00 2001 From: Benjamin Cooke Date: Wed, 23 Nov 2022 17:21:25 -0500 Subject: [PATCH] make my insights available in free tier --- server/app/insights.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server/app/insights.go b/server/app/insights.go index 80ba8c005..28027d54d 100644 --- a/server/app/insights.go +++ b/server/app/insights.go @@ -8,7 +8,7 @@ import ( func (a *App) GetTeamBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) { // check if server is properly licensed, and user is not a guest - userPermitted, err := insightPermissionGate(a, userID) + userPermitted, err := insightPermissionGate(a, userID, false) if err != nil { return nil, err } @@ -24,7 +24,7 @@ func (a *App) GetTeamBoardsInsights(userID string, teamID string, opts *mmModel. func (a *App) GetUserBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) { // check if server is properly licensed, and user is not a guest - userPermitted, err := insightPermissionGate(a, userID) + userPermitted, err := insightPermissionGate(a, userID, true) if err != nil { return nil, err } @@ -38,24 +38,29 @@ func (a *App) GetUserBoardsInsights(userID string, teamID string, opts *mmModel. return a.store.GetUserBoardsInsights(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage, boardIDs) } -func insightPermissionGate(a *App, userID string) (bool, error) { +func insightPermissionGate(a *App, userID string, isMyInsights bool) (bool, error) { licenseError := errors.New("invalid license/authorization to use insights API") guestError := errors.New("guests aren't authorized to use insights API") lic := a.store.GetLicense() - if lic == nil { - a.logger.Debug("Deployment doesn't have a license") - return false, licenseError - } + user, err := a.store.GetUserByID(userID) if err != nil { return false, err } - if lic.SkuShortName != mmModel.LicenseShortSkuProfessional && lic.SkuShortName != mmModel.LicenseShortSkuEnterprise { - return false, licenseError - } + if user.IsGuest { return false, guestError } + + if lic == nil && !isMyInsights { + a.logger.Debug("Deployment doesn't have a license") + return false, licenseError + } + + if !isMyInsights && (lic.SkuShortName != mmModel.LicenseShortSkuProfessional && lic.SkuShortName != mmModel.LicenseShortSkuEnterprise) { + return false, licenseError + } + return true, nil }