From 56cf4b4ee75376c01c9680d1a38d47f402661669 Mon Sep 17 00:00:00 2001 From: Shivashis Padhi Date: Tue, 21 Jun 2022 15:12:13 +0530 Subject: [PATCH] Clean license, and guest user check for top threads --- api4/insights.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/api4/insights.go b/api4/insights.go index 39493a97f3..817dec6ce0 100644 --- a/api4/insights.go +++ b/api4/insights.go @@ -21,8 +21,8 @@ func (api *API) InitInsights() { api.BaseRoutes.InsightsForUser.Handle("/channels", api.APISessionRequired(minimumProfessionalLicense(rejectGuests(getTopChannelsForUserSince)))).Methods("GET") // Threads - api.BaseRoutes.InsightsForTeam.Handle("/threads", api.APISessionRequired(requireLicense(getTopThreadsForTeamSince))).Methods("GET") - api.BaseRoutes.InsightsForUser.Handle("/threads", api.APISessionRequired(requireLicense(getTopThreadsForUserSince))).Methods("GET") + api.BaseRoutes.InsightsForTeam.Handle("/threads", api.APISessionRequired(minimumProfessionalLicense(rejectGuests(getTopThreadsForTeamSince)))).Methods("GET") + api.BaseRoutes.InsightsForUser.Handle("/threads", api.APISessionRequired(minimumProfessionalLicense(rejectGuests(getTopThreadsForUserSince)))).Methods("GET") } // Top Reactions @@ -243,21 +243,14 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques return } - // license check - lic := c.App.Srv().License() - if lic.SkuShortName != model.LicenseShortSkuProfessional && lic.SkuShortName != model.LicenseShortSkuEnterprise { - c.Err = model.NewAppError("", "api.insights.license_error", nil, "", http.StatusNotImplemented) - return - } - - // restrict guests and users with no access to team + // restrict users with no access to team user, err := c.App.GetUser(c.AppContext.Session().UserId) if err != nil { c.Err = err return } - if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), team.Id, model.PermissionViewTeam) || user.IsGuest() { + if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), team.Id, model.PermissionViewTeam) { c.SetPermissionError(model.PermissionViewTeam) return } @@ -286,7 +279,7 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { c.Params.TeamId = r.URL.Query().Get("team_id") - // restrict guests and users with no access to team + // restrict users with no access to team user, err := c.App.GetUser(c.AppContext.Session().UserId) if err != nil { c.Err = err @@ -305,14 +298,7 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques return } - // license check - lic := c.App.Srv().License() - if lic.SkuShortName != model.LicenseShortSkuProfessional && lic.SkuShortName != model.LicenseShortSkuEnterprise { - c.Err = model.NewAppError("", "api.insights.license_error", nil, "", http.StatusNotImplemented) - return - } - - if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), team.Id, model.PermissionViewTeam) || user.IsGuest() { + if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), team.Id, model.PermissionViewTeam) { c.SetPermissionError(model.PermissionViewTeam) return }