Skip to content

Commit

Permalink
Fixed actived users and added mau in true up report (mattermost#24921)
Browse files Browse the repository at this point in the history
* Fixed actived users and added mau in true up report

* Temp disable of true up calendar checks for testing

* Revert "Temp disable of true up calendar checks for testing"

This reverts commit 73055bd.

* Added unit test

* Linting

* Typo

* Forgot the pain of linting

* Added dau

* Create imports.go

* Fix merge error

* Fixed test

---------

Co-authored-by: Mattermost Build <[email protected]>
  • Loading branch information
marianunez and mattermost-build authored Jan 12, 2024
1 parent 3047700 commit f857af6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
22 changes: 19 additions & 3 deletions server/channels/app/true_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@ func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) {
}

// Customer Info & Usage Analytics
activeUserCount, err := a.Srv().Store().Status().GetTotalActiveUsersCount()

// active registered users
activatedUsers, err := a.Srv().Store().User().Count(model.UserCountOptions{})
if err != nil {
return nil, model.NewAppError("requestTrueUpReview", "api.license.true_up_review.user_count_fail", nil, "Could not get the total activated users count", http.StatusInternalServerError).Wrap(err)
}

// daily active users
dau, err := a.Srv().Store().User().AnalyticsActiveCount(DayMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
if err != nil {
return nil, model.NewAppError("requestTrueUpReview", "api.license.true_up_review.user_count_fail", nil, "Could not get the total daily active users count", http.StatusInternalServerError)
}

// monthly active users
mau, err := a.Srv().Store().User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
if err != nil {
return nil, model.NewAppError("requestTrueUpReview", "api.license.true_up_review.user_count_fail", nil, "Could not get the total active users count", http.StatusInternalServerError)
return nil, model.NewAppError("requestTrueUpReview", "api.license.true_up_review.user_count_fail", nil, "Could not get the total monthly active users count", http.StatusInternalServerError).Wrap(err)
}

// Webhook, calls, boards, and playbook counts
Expand Down Expand Up @@ -108,7 +122,9 @@ func (a *App) getTrueUpProfile() (*model.TrueUpReviewProfile, error) {
LicensedSeats: *license.Features.Users,
LicensePlan: license.SkuName,
CustomerName: license.Customer.Name,
ActiveUsers: activeUserCount,
ActivatedUsers: activatedUsers,
DailyActiveUsers: dau,
MonthlyActiveUsers: mau,
TotalIncomingWebhooks: incomingWebhookCount,
TotalOutgoingWebhooks: outgoingWebhookCount,
Plugins: trueUpReviewPlugins,
Expand Down
55 changes: 55 additions & 0 deletions server/channels/app/true_up_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package app

import (
"strings"
"testing"

"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestGetTrueUpProfile(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()

mockStore := th.App.Srv().Store().(*mocks.Store)
mockUserStore := mocks.UserStore{}
//Activated userss set to 10
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
//Mau set to 5
mockUserStore.On("AnalyticsActiveCount", int64(MonthMilliseconds), model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}).Return(int64(5), nil)
//dau set to 2
mockUserStore.On("AnalyticsActiveCount", int64(DayMilliseconds), model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}).Return(int64(2), nil)
mockStore.On("User").Return(&mockUserStore)

mockWebhookStore := mocks.WebhookStore{}
mockWebhookStore.On("AnalyticsIncomingCount", mock.Anything).Return(int64(1), nil)
mockWebhookStore.On("AnalyticsOutgoingCount", mock.Anything).Return(int64(1), nil)
mockStore.On("Webhook").Return(&mockWebhookStore)

t.Run("missing license", func(t *testing.T) {
_, err := th.App.GetTrueUpProfile()
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "True up review requires a license"))
})

t.Run("happy path - returns correct mau and activated users", func(t *testing.T) {
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))

profile, err := th.App.GetTrueUpProfile()
assert.NoError(t, err, "Unexpected error")

require.NotNil(t, profile)
assert.Equal(t, float64(5), profile["monthly_active_users"])
assert.Equal(t, float64(2), profile["daily_active_users"])
assert.Equal(t, float64(10), profile["total_activated_users"])
assert.Equal(t, float64(1), profile["incoming_webhooks_count"])
assert.Equal(t, float64(1), profile["outgoing_webhooks_count"])
})
}
4 changes: 3 additions & 1 deletion server/public/model/true_up_review_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type TrueUpReviewProfile struct {
LicensedSeats int `json:"licensed_seats"`
LicensePlan string `json:"license_plan"`
CustomerName string `json:"customer_name"`
ActiveUsers int64 `json:"active_users"`
ActivatedUsers int64 `json:"total_activated_users"`
DailyActiveUsers int64 `json:"daily_active_users"`
MonthlyActiveUsers int64 `json:"monthly_active_users"`
AuthenticationFeatures []string `json:"authentication_features"`
Plugins TrueUpReviewPlugins `json:"plugins"`
TotalIncomingWebhooks int64 `json:"incoming_webhooks_count"`
Expand Down

0 comments on commit f857af6

Please sign in to comment.