1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00

MM-43781: boards insights - cherry pick PR suggestions (#3596)

* Uncomment team insights test

* Add checks to make sure insights endpoints work only in plugin mode

* adding constant for my insights

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
This commit is contained in:
Shivashis Padhi 2022-08-08 19:04:03 +05:30 committed by GitHub
parent f00b5c9e61
commit d50846ed42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 14 deletions

View File

@ -37,6 +37,7 @@ import '../../../webapp/src/styles/focalboard-variables.scss'
import '../../../webapp/src/styles/main.scss'
import '../../../webapp/src/styles/labels.scss'
import octoClient from '../../../webapp/src/octoClient'
import {Constants} from '../../../webapp/src/constants'
import BoardsUnfurl from './components/boardsUnfurl/boardsUnfurl'
import RHSChannelBoards from './components/rhsChannelBoards'
@ -323,7 +324,7 @@ export default class Plugin {
// Insights handler
if (this.registry?.registerInsightsHandler) {
this.registry?.registerInsightsHandler(async (timeRange: string, page: number, perPage: number, teamId: string, insightType: string) => {
if (insightType === 'MY') {
if (insightType === Constants.myInsights) {
const data = await octoClient.getMyTopBoards(timeRange, page, perPage, teamId)
return data

View File

@ -2226,6 +2226,11 @@ func (a *API) handleTeamBoardsInsights(w http.ResponseWriter, r *http.Request) {
// schema:
// "$ref": "#/definitions/ErrorResponse"
if !a.MattermostAuth {
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
return
}
vars := mux.Vars(r)
teamID := vars["teamID"]
userID := getUserID(r)
@ -2333,6 +2338,12 @@ func (a *API) handleUserBoardsInsights(w http.ResponseWriter, r *http.Request) {
// description: internal error
// schema:
// "$ref": "#/definitions/ErrorResponse"
if !a.MattermostAuth {
a.errorResponse(w, r.URL.Path, http.StatusNotImplemented, "not permitted in standalone mode", nil)
return
}
userID := getUserID(r)
query := r.URL.Query()
teamID := query.Get("team_id")

View File

@ -1,6 +1,7 @@
package storetests
import (
"strconv"
"testing"
"github.com/mattermost/focalboard/server/model"
@ -69,19 +70,18 @@ func getBoardsInsightsTest(t *testing.T, store store.Store) {
boardsUser1, _ := store.GetBoardsForUserAndTeam(testUserID, testTeamID)
boardsUser2, _ := store.GetBoardsForUserAndTeam(testInsightsUserID1, testTeamID)
// t.Run("team insights", func(t *testing.T) {
// boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}
// topTeamBoards, err := store.GetTeamBoardsInsights(testTeamID, testUserID,
// 0, 0, 10, boardIDs)
// require.NoError(t, err)
// require.Len(t, topTeamBoards.Items, 3)
// // validate board insight content
// require.Equal(t, topTeamBoards.Items[0].ActivityCount, strconv.Itoa(8))
// require.Equal(t, topTeamBoards.Items[0].Icon, "💬")
// require.Equal(t, topTeamBoards.Items[1].ActivityCount, strconv.Itoa(5))
// require.Equal(t, topTeamBoards.Items[2].ActivityCount, strconv.Itoa(4))
// })
t.Run("team insights", func(t *testing.T) {
boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}
topTeamBoards, err := store.GetTeamBoardsInsights(testTeamID, testUserID,
0, 0, 10, boardIDs)
require.NoError(t, err)
require.Len(t, topTeamBoards.Items, 3)
// validate board insight content
require.Equal(t, topTeamBoards.Items[0].ActivityCount, strconv.Itoa(8))
require.Equal(t, topTeamBoards.Items[0].Icon, "💬")
require.Equal(t, topTeamBoards.Items[1].ActivityCount, strconv.Itoa(5))
require.Equal(t, topTeamBoards.Items[2].ActivityCount, strconv.Itoa(4))
})
t.Run("user insights", func(t *testing.T) {
boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}

View File

@ -194,6 +194,8 @@ class Constants {
}
static readonly globalTeamId = '0'
static readonly myInsights = 'MY'
}
export {Constants, Permission}