[MM-55017] Add API method to get users for Admin Reporting (#25499)

* Add store method to get reporting data

* Some store changes

* Added app layer

* Added API call, some miscellaneous fixes

* Fix lint

* Fix serialized check

* Add API docs

* Fix user store tests leaking users

* Fix test

* PR feedback

* Add filtering for role/team/activated user, filter out bot users

* Fix mock

* Fix test

* Oops

* Switch to using struct filter

* More PR feedback

* Fix gen

* Fix test

* Fix API docs

* Fix test

* Fix possible SQL injection, some query optimization

* Fix migrations

* Oops

* Add role to API

* Fix check

* Add Client4 API call for load testing

* Fix test

* Update server/channels/store/storetest/user_store.go

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

* PR feedback

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
Devin Binnie
2023-12-08 10:30:08 -05:00
коммит произвёл GitHub
родитель 7afc14de36
Коммит 109f4643c6
26 изменённых файлов: 2399 добавлений и 1 удалений

Просмотреть файл

@@ -1918,6 +1918,54 @@ 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) {
values := url.Values{}
if options.SortColumn != "" {
values.Set("sort_column", options.SortColumn)
}
if options.PageSize > 0 {
values.Set("page_size", strconv.Itoa(options.PageSize))
}
if options.Team != "" {
values.Set("team_filter", options.Team)
}
if options.HideActive {
values.Set("hide_active", "true")
}
if options.HideInactive {
values.Set("hide_inactive", "true")
}
if options.SortDesc {
values.Set("sort_direction", "desc")
}
if options.LastSortColumnValue != "" {
values.Set("last_column_value", options.LastSortColumnValue)
}
if options.LastUserId != "" {
values.Set("last_id", options.LastUserId)
}
if options.Role != "" {
values.Set("role_filter", options.Role)
}
if options.HasNoTeam {
values.Set("has_no_team", "true")
}
if options.DateRange != "" {
values.Set("date_range", options.DateRange)
}
r, err := c.DoAPIGet(ctx, c.usersRoute()+"/report?"+values.Encode(), "")
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var list []*UserReport
if err := json.NewDecoder(r.Body).Decode(&list); err != nil {
return nil, nil, NewAppError("GetUsersForReporting", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return list, BuildResponse(r), nil
}
// Bots section
// CreateBot creates a bot in the system based on the provided bot struct.