1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-27 08:31:20 +02:00

make my insights available in free tier

This commit is contained in:
Benjamin Cooke 2022-11-23 17:21:25 -05:00
parent 4051e1eb05
commit f89168762d

View File

@ -8,7 +8,7 @@ import (
func (a *App) GetTeamBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) { 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 // 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 { if err != nil {
return nil, err 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) { 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 // 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 { if err != nil {
return nil, err 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) 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") licenseError := errors.New("invalid license/authorization to use insights API")
guestError := errors.New("guests aren't authorized to use insights API") guestError := errors.New("guests aren't authorized to use insights API")
lic := a.store.GetLicense() 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) user, err := a.store.GetUserByID(userID)
if err != nil { if err != nil {
return false, err return false, err
} }
if lic.SkuShortName != mmModel.LicenseShortSkuProfessional && lic.SkuShortName != mmModel.LicenseShortSkuEnterprise {
return false, licenseError
}
if user.IsGuest { if user.IsGuest {
return false, guestError 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 return true, nil
} }