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
81
server/channels/api4/report.go
Обычный файл
81
server/channels/api4/report.go
Обычный файл
@@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
)
|
||||
|
||||
func (api *API) InitReports() {
|
||||
api.BaseRoutes.Reports.Handle("/users", api.APISessionRequired(getUsersForReporting)).Methods("GET")
|
||||
}
|
||||
|
||||
func getUsersForReporting(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !(c.IsSystemAdmin() && c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionSysconsoleReadUserManagementUsers)) {
|
||||
c.SetPermissionError(model.PermissionSysconsoleReadUserManagementUsers)
|
||||
return
|
||||
}
|
||||
|
||||
sortColumn := "Username"
|
||||
if r.URL.Query().Get("sort_column") != "" {
|
||||
sortColumn = r.URL.Query().Get("sort_column")
|
||||
}
|
||||
|
||||
pageSize := 50
|
||||
if pageSizeStr, err := strconv.ParseInt(r.URL.Query().Get("page_size"), 10, 64); err == nil {
|
||||
pageSize = int(pageSizeStr)
|
||||
}
|
||||
|
||||
teamFilter := r.URL.Query().Get("team_filter")
|
||||
if !(teamFilter == "" || model.IsValidId(teamFilter)) {
|
||||
c.Err = model.NewAppError("getUsersForReporting", "api.getUsersForReporting.invalid_team_filter", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
hideActive := r.URL.Query().Get("hide_active") == "true"
|
||||
hideInactive := r.URL.Query().Get("hide_inactive") == "true"
|
||||
if hideActive && hideInactive {
|
||||
c.Err = model.NewAppError("getUsersForReporting", "api.getUsersForReporting.invalid_active_filter", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
options := &model.UserReportOptions{
|
||||
ReportingBaseOptions: model.ReportingBaseOptions{
|
||||
SortColumn: sortColumn,
|
||||
SortDesc: r.URL.Query().Get("sort_direction") == "desc",
|
||||
PageSize: pageSize,
|
||||
LastSortColumnValue: r.URL.Query().Get("last_column_value"),
|
||||
DateRange: r.URL.Query().Get("date_range"),
|
||||
},
|
||||
Team: teamFilter,
|
||||
LastUserId: r.URL.Query().Get("last_id"),
|
||||
Role: r.URL.Query().Get("role_filter"),
|
||||
HasNoTeam: r.URL.Query().Get("has_no_team") == "true",
|
||||
HideActive: hideActive,
|
||||
HideInactive: hideInactive,
|
||||
}
|
||||
options.PopulateDateRange(time.Now())
|
||||
|
||||
// Don't allow fetching more than 100 users at a time from the normal query endpoint
|
||||
if options.PageSize <= 0 || options.PageSize > model.ReportingMaxPageSize {
|
||||
c.Err = model.NewAppError("getUsersForReporting", "api.getUsersForReporting.invalid_page_size", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
userReports, err := c.App.GetUsersForReporting(options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if jsonErr := json.NewEncoder(w).Encode(userReports); jsonErr != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(jsonErr))
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user