New report router and user reporting refactoring (#25713)
* Added materialized view migration * Renamed mat view * Added channel membership mat view and indexes * Added channel membership mat view and indexes * Added new index * WIP * Simplifying user reporting code * Created app and API layer for cahnnel reporting, reporting refactoring in general * New router * Remobved channel reporting meanwhile * Upodated autogenerated stuff * Lint fix * Fixed typo * api vet * i18n fix * Fixed API vetting and removed channel reporting constants * yaml * removed app pagination tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
32880efa25
Коммит
97a23d791e
@@ -166,6 +166,10 @@ func (c *Client4) usersRoute() string {
|
||||
return "/users"
|
||||
}
|
||||
|
||||
func (c *Client4) reportsRoute() string {
|
||||
return "/reports"
|
||||
}
|
||||
|
||||
func (c *Client4) userRoute(userId string) string {
|
||||
return fmt.Sprintf(c.usersRoute()+"/%v", userId)
|
||||
}
|
||||
@@ -1918,7 +1922,7 @@ func (c *Client4) EnableUserAccessToken(ctx context.Context, tokenId string) (*R
|
||||
return BuildResponse(r), nil
|
||||
}
|
||||
|
||||
func (c *Client4) GetUsersForReporting(ctx context.Context, options *UserReportOptionsAPI) ([]*UserReport, *Response, error) {
|
||||
func (c *Client4) GetUsersForReporting(ctx context.Context, options *UserReportOptions) ([]*UserReport, *Response, error) {
|
||||
values := url.Values{}
|
||||
if options.SortColumn != "" {
|
||||
values.Set("sort_column", options.SortColumn)
|
||||
@@ -1954,7 +1958,7 @@ func (c *Client4) GetUsersForReporting(ctx context.Context, options *UserReportO
|
||||
values.Set("date_range", options.DateRange)
|
||||
}
|
||||
|
||||
r, err := c.DoAPIGet(ctx, c.usersRoute()+"/report?"+values.Encode(), "")
|
||||
r, err := c.DoAPIGet(ctx, c.reportsRoute()+"/users?"+values.Encode(), "")
|
||||
if err != nil {
|
||||
return nil, BuildResponse(r), err
|
||||
}
|
||||
|
||||
109
server/public/model/report.go
Обычный файл
109
server/public/model/report.go
Обычный файл
@@ -0,0 +1,109 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
ReportDurationLast30Days = "last_30_days"
|
||||
ReportDurationPreviousMonth = "previous_month"
|
||||
ReportDurationLast6Months = "last_6_months"
|
||||
|
||||
ReportingMaxPageSize = 100
|
||||
)
|
||||
|
||||
var (
|
||||
UserReportSortColumns = []string{"CreateAt", "Username", "FirstName", "LastName", "Nickname", "Email", "Roles"}
|
||||
)
|
||||
|
||||
type ReportingBaseOptions struct {
|
||||
SortDesc bool
|
||||
PageSize int
|
||||
SortColumn string
|
||||
LastSortColumnValue string
|
||||
DateRange string
|
||||
StartAt int64
|
||||
EndAt int64
|
||||
}
|
||||
|
||||
func (options *ReportingBaseOptions) PopulateDateRange(now time.Time) {
|
||||
startAt := int64(0)
|
||||
endAt := int64(0)
|
||||
|
||||
if options.DateRange == ReportDurationLast30Days {
|
||||
startAt = now.AddDate(0, 0, -30).UnixMilli()
|
||||
} else if options.DateRange == ReportDurationPreviousMonth {
|
||||
startOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
startAt = startOfMonth.AddDate(0, -1, 0).UnixMilli()
|
||||
endAt = startOfMonth.UnixMilli()
|
||||
} else if options.DateRange == ReportDurationLast6Months {
|
||||
startAt = now.AddDate(0, -6, -0).UnixMilli()
|
||||
}
|
||||
|
||||
options.StartAt = startAt
|
||||
options.EndAt = endAt
|
||||
}
|
||||
|
||||
func (options *ReportingBaseOptions) IsValid() *AppError {
|
||||
if options.EndAt > 0 && options.StartAt > options.EndAt {
|
||||
return NewAppError("ReportingBaseOptions.IsValid", "model.reporting_base_options.is_valid.bad_date_range", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type UserReportQuery struct {
|
||||
User
|
||||
UserPostStats
|
||||
}
|
||||
|
||||
type UserReport struct {
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
CreateAt int64 `json:"create_at,omitempty"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Roles string `json:"roles"`
|
||||
UserPostStats
|
||||
}
|
||||
|
||||
type UserReportOptions struct {
|
||||
ReportingBaseOptions
|
||||
LastUserId string
|
||||
Role string
|
||||
Team string
|
||||
HasNoTeam bool
|
||||
HideActive bool
|
||||
HideInactive bool
|
||||
}
|
||||
|
||||
func (u *UserReportOptions) IsValid() *AppError {
|
||||
if appErr := u.ReportingBaseOptions.IsValid(); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
// Validate against the columns we allow sorting for
|
||||
if !pUtils.Contains(UserReportSortColumns, u.SortColumn) {
|
||||
return NewAppError("UserReportOptions.IsValid", "model.user_report_options.is_valid.invalid_sort_column", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserReportQuery) ToReport() *UserReport {
|
||||
return &UserReport{
|
||||
Id: u.Id,
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
CreateAt: u.CreateAt,
|
||||
DisplayName: u.GetDisplayName(ShowNicknameFullName),
|
||||
Roles: u.Roles,
|
||||
UserPostStats: u.UserPostStats,
|
||||
}
|
||||
}
|
||||
@@ -48,10 +48,6 @@ const (
|
||||
PushThreadsNotifyProp = "push_threads"
|
||||
EmailThreadsNotifyProp = "email_threads"
|
||||
|
||||
ReportDurationLast30Days = "last_30_days"
|
||||
ReportDurationPreviousMonth = "previous_month"
|
||||
ReportDurationLast6Months = "last_6_months"
|
||||
|
||||
DefaultLocale = "en"
|
||||
UserAuthServiceEmail = "email"
|
||||
|
||||
@@ -71,10 +67,6 @@ const (
|
||||
DesktopTokenTTL = time.Minute * 3
|
||||
)
|
||||
|
||||
var (
|
||||
UserReportSortColumns = []string{"CreateAt", "Username", "FirstName", "LastName", "Nickname", "Email", "Roles"}
|
||||
)
|
||||
|
||||
//msgp:tuple User
|
||||
|
||||
// User contains the details about the user.
|
||||
@@ -1029,74 +1021,3 @@ type UserPostStats struct {
|
||||
DaysActive *int `json:"days_active,omitempty"`
|
||||
TotalPosts *int `json:"total_posts,omitempty"`
|
||||
}
|
||||
|
||||
type UserReportQuery struct {
|
||||
User
|
||||
UserPostStats
|
||||
}
|
||||
|
||||
type UserReport struct {
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
CreateAt int64 `json:"create_at,omitempty"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Roles string `json:"roles"`
|
||||
UserPostStats
|
||||
}
|
||||
|
||||
type UserReportOptionsWithoutDateRange struct {
|
||||
SortColumn string
|
||||
SortDesc bool
|
||||
PageSize int
|
||||
LastSortColumnValue string
|
||||
LastUserId string
|
||||
Role string
|
||||
Team string
|
||||
HasNoTeam bool
|
||||
HideActive bool
|
||||
HideInactive bool
|
||||
}
|
||||
|
||||
type UserReportOptions struct {
|
||||
UserReportOptionsWithoutDateRange
|
||||
StartAt int64
|
||||
EndAt int64
|
||||
}
|
||||
|
||||
type UserReportOptionsAPI struct {
|
||||
UserReportOptionsWithoutDateRange
|
||||
DateRange string
|
||||
}
|
||||
|
||||
func (u *UserReportOptionsAPI) ToBaseOptions(now time.Time) *UserReportOptions {
|
||||
startAt := int64(0)
|
||||
endAt := int64(0)
|
||||
if u.DateRange == ReportDurationLast30Days {
|
||||
startAt = now.AddDate(0, 0, -30).UnixMilli()
|
||||
} else if u.DateRange == ReportDurationPreviousMonth {
|
||||
startOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
startAt = startOfMonth.AddDate(0, -1, 0).UnixMilli()
|
||||
endAt = startOfMonth.UnixMilli()
|
||||
} else if u.DateRange == ReportDurationLast6Months {
|
||||
startAt = now.AddDate(0, -6, -0).UnixMilli()
|
||||
}
|
||||
|
||||
return &UserReportOptions{
|
||||
UserReportOptionsWithoutDateRange: u.UserReportOptionsWithoutDateRange,
|
||||
StartAt: startAt,
|
||||
EndAt: endAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UserReportQuery) ToReport() *UserReport {
|
||||
return &UserReport{
|
||||
Id: u.Id,
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
CreateAt: u.CreateAt,
|
||||
DisplayName: u.GetDisplayName(ShowNicknameFullName),
|
||||
Roles: u.Roles,
|
||||
UserPostStats: u.UserPostStats,
|
||||
}
|
||||
}
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Ссылка в новой задаче
Block a user