[GH-26715] Added Pagination Support for IncomingWebHooks (#27502)
* Added Pagination Support for IncomingWebHooks * Incorporated feedback from reviews * Removed trailing spaces * Restored deleted server en.json entries, fixed order in webapp en.json --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -12908,7 +12908,7 @@ func (s *OpenTracingLayerUserTermsOfServiceStore) Save(userTermsOfService *model
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerWebhookStore) AnalyticsIncomingCount(teamID string) (int64, error) {
|
||||
func (s *OpenTracingLayerWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "WebhookStore.AnalyticsIncomingCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -12917,7 +12917,7 @@ func (s *OpenTracingLayerWebhookStore) AnalyticsIncomingCount(teamID string) (in
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID)
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID, userID)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -14744,11 +14744,11 @@ func (s *RetryLayerUserTermsOfServiceStore) Save(userTermsOfService *model.UserT
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerWebhookStore) AnalyticsIncomingCount(teamID string) (int64, error) {
|
||||
func (s *RetryLayerWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID)
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID, userID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -352,15 +352,19 @@ func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) (*model.Out
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsIncomingCount(teamId string) (int64, error) {
|
||||
func (s SqlWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
queryBuilder :=
|
||||
s.getQueryBuilder().
|
||||
Select("COUNT(*)").
|
||||
From("IncomingWebhooks").
|
||||
Where("DeleteAt = 0")
|
||||
|
||||
if teamId != "" {
|
||||
queryBuilder = queryBuilder.Where("TeamId", teamId)
|
||||
if teamID != "" {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"TeamId": teamID})
|
||||
}
|
||||
|
||||
if userID != "" {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"UserId": userID})
|
||||
}
|
||||
|
||||
queryString, args, err := queryBuilder.ToSql()
|
||||
|
||||
@@ -615,7 +615,7 @@ type WebhookStore interface {
|
||||
PermanentDeleteOutgoingByUser(userID string) error
|
||||
UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, error)
|
||||
|
||||
AnalyticsIncomingCount(teamID string) (int64, error)
|
||||
AnalyticsIncomingCount(teamID string, userID string) (int64, error)
|
||||
AnalyticsOutgoingCount(teamID string) (int64, error)
|
||||
InvalidateWebhookCache(webhook string)
|
||||
ClearCaches()
|
||||
|
||||
@@ -14,9 +14,9 @@ type WebhookStore struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// AnalyticsIncomingCount provides a mock function with given fields: teamID
|
||||
func (_m *WebhookStore) AnalyticsIncomingCount(teamID string) (int64, error) {
|
||||
ret := _m.Called(teamID)
|
||||
// AnalyticsIncomingCount provides a mock function with given fields: teamID, userID
|
||||
func (_m *WebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
ret := _m.Called(teamID, userID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for AnalyticsIncomingCount")
|
||||
@@ -24,17 +24,17 @@ func (_m *WebhookStore) AnalyticsIncomingCount(teamID string) (int64, error) {
|
||||
|
||||
var r0 int64
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string) (int64, error)); ok {
|
||||
return rf(teamID)
|
||||
if rf, ok := ret.Get(0).(func(string, string) (int64, error)); ok {
|
||||
return rf(teamID, userID)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(teamID)
|
||||
if rf, ok := ret.Get(0).(func(string, string) int64); ok {
|
||||
r0 = rf(teamID, userID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(teamID)
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(teamID, userID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -577,10 +577,28 @@ func testWebhookStoreCountIncoming(t *testing.T, rctx request.CTX, ss store.Stor
|
||||
|
||||
_, _ = ss.Webhook().SaveIncoming(o1)
|
||||
|
||||
c, err := ss.Webhook().AnalyticsIncomingCount("")
|
||||
c, err := ss.Webhook().AnalyticsIncomingCount("", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, 0, c, "should have at least 1 incoming hook")
|
||||
|
||||
o2 := &model.IncomingWebhook{}
|
||||
o2.ChannelId = model.NewId()
|
||||
o2.UserId = model.NewId()
|
||||
o2.TeamId = model.NewId()
|
||||
|
||||
_, _ = ss.Webhook().SaveIncoming(o2)
|
||||
|
||||
c, err = ss.Webhook().AnalyticsIncomingCount("", "")
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 1, c, "should have at least 2 incoming hooks")
|
||||
|
||||
c, err = ss.Webhook().AnalyticsIncomingCount(o1.TeamId, "")
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, c, "should have at least 1 incoming hook when filtering by TeamID")
|
||||
|
||||
c, err = ss.Webhook().AnalyticsIncomingCount("", o2.UserId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, c, "should have at least 1 incoming hook when filtering by UserID")
|
||||
}
|
||||
|
||||
func testWebhookStoreCountOutgoing(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
@@ -11618,10 +11618,10 @@ func (s *TimerLayerUserTermsOfServiceStore) Save(userTermsOfService *model.UserT
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerWebhookStore) AnalyticsIncomingCount(teamID string) (int64, error) {
|
||||
func (s *TimerLayerWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID)
|
||||
result, err := s.WebhookStore.AnalyticsIncomingCount(teamID, userID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user