From 1ce2846c9520583fe523586ff19188a507ab9535 Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:49:36 -0600 Subject: [PATCH] AuditLogs page fixes (#3059) - Added support to endDate - Converted dates to UTC as required by AuditLogs API Signed-off-by: Benjamin Perez --- portal-ui/src/api/consoleApi.ts | 1 + .../Console/Logs/LogSearch/LogsSearchMain.tsx | 6 ++--- restapi/embedded_spec.go | 10 +++++++ .../logging/log_search_parameters.go | 27 +++++++++++++++++++ .../logging/log_search_urlbuilder.go | 9 +++++++ restapi/user_log_search.go | 6 +++++ swagger.yml | 3 +++ 7 files changed, 59 insertions(+), 3 deletions(-) diff --git a/portal-ui/src/api/consoleApi.ts b/portal-ui/src/api/consoleApi.ts index 5ce864e5a..2e453fe25 100644 --- a/portal-ui/src/api/consoleApi.ts +++ b/portal-ui/src/api/consoleApi.ts @@ -4567,6 +4567,7 @@ export class Api< /** @default "timeDesc" */ order?: "timeDesc" | "timeAsc"; timeStart?: string; + timeEnd?: string; }, params: RequestParams = {}, ) => diff --git a/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx b/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx index 7d5b65804..806aecd88 100644 --- a/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx +++ b/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx @@ -119,9 +119,9 @@ const LogsSearchMain = () => { queryParams !== "" ? `${queryParams}` : "" }&pageSize=100&pageNo=${nextPage}&order=${ sortOrder === "DESC" ? "timeDesc" : "timeAsc" - }${timeStart !== null ? `&timeStart=${timeStart.toISO()}` : ""}${ - timeEnd !== null ? `&timeEnd=${timeEnd.toISO()}` : "" - }`, + }${ + timeStart !== null ? `&timeStart=${timeStart.toUTC().toISO()}` : "" + }${timeEnd !== null ? `&timeEnd=${timeEnd.toUTC().toISO()}` : ""}`, ) .then((res: ISearchResponse) => { const fetchedResults = res.results || []; diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 0a2116a8a..fb4f0c901 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -3878,6 +3878,11 @@ func init() { "type": "string", "name": "timeStart", "in": "query" + }, + { + "type": "string", + "name": "timeEnd", + "in": "query" } ], "responses": { @@ -12920,6 +12925,11 @@ func init() { "type": "string", "name": "timeStart", "in": "query" + }, + { + "type": "string", + "name": "timeEnd", + "in": "query" } ], "responses": { diff --git a/restapi/operations/logging/log_search_parameters.go b/restapi/operations/logging/log_search_parameters.go index c80a78cd7..49adcd22e 100644 --- a/restapi/operations/logging/log_search_parameters.go +++ b/restapi/operations/logging/log_search_parameters.go @@ -86,6 +86,10 @@ type LogSearchParams struct { /* In: query */ + TimeEnd *string + /* + In: query + */ TimeStart *string } @@ -120,6 +124,11 @@ func (o *LogSearchParams) BindRequest(r *http.Request, route *middleware.Matched res = append(res, err) } + qTimeEnd, qhkTimeEnd, _ := qs.GetOK("timeEnd") + if err := o.bindTimeEnd(qTimeEnd, qhkTimeEnd, route.Formats); err != nil { + res = append(res, err) + } + qTimeStart, qhkTimeStart, _ := qs.GetOK("timeStart") if err := o.bindTimeStart(qTimeStart, qhkTimeStart, route.Formats); err != nil { res = append(res, err) @@ -233,6 +242,24 @@ func (o *LogSearchParams) bindPageSize(rawData []string, hasKey bool, formats st return nil } +// bindTimeEnd binds and validates parameter TimeEnd from query. +func (o *LogSearchParams) bindTimeEnd(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + o.TimeEnd = &raw + + return nil +} + // bindTimeStart binds and validates parameter TimeStart from query. func (o *LogSearchParams) bindTimeStart(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string diff --git a/restapi/operations/logging/log_search_urlbuilder.go b/restapi/operations/logging/log_search_urlbuilder.go index dec3944b9..f421ee458 100644 --- a/restapi/operations/logging/log_search_urlbuilder.go +++ b/restapi/operations/logging/log_search_urlbuilder.go @@ -36,6 +36,7 @@ type LogSearchURL struct { Order *string PageNo *int32 PageSize *int32 + TimeEnd *string TimeStart *string _basePath string @@ -110,6 +111,14 @@ func (o *LogSearchURL) Build() (*url.URL, error) { qs.Set("pageSize", pageSizeQ) } + var timeEndQ string + if o.TimeEnd != nil { + timeEndQ = *o.TimeEnd + } + if timeEndQ != "" { + qs.Set("timeEnd", timeEndQ) + } + var timeStartQ string if o.TimeStart != nil { timeStartQ = *o.TimeStart diff --git a/restapi/user_log_search.go b/restapi/user_log_search.go index 14a3b854c..af45e5422 100644 --- a/restapi/user_log_search.go +++ b/restapi/user_log_search.go @@ -80,6 +80,12 @@ func getLogSearchResponse(session *models.Principal, params logApi.LogSearchPara if params.TimeStart != nil && *params.TimeStart != "" { endpoint = fmt.Sprintf("%s&timeStart=%s", endpoint, *params.TimeStart) } + + // timeEnd + if params.TimeEnd != nil && *params.TimeEnd != "" { + endpoint = fmt.Sprintf("%s&timeEnd=%s", endpoint, *params.TimeEnd) + } + // page size and page number endpoint = fmt.Sprintf("%s&pageSize=%d", endpoint, *params.PageSize) endpoint = fmt.Sprintf("%s&pageNo=%d", endpoint, *params.PageNo) diff --git a/swagger.yml b/swagger.yml index 88ba0246f..719bdb072 100644 --- a/swagger.yml +++ b/swagger.yml @@ -2943,6 +2943,9 @@ paths: - name: timeStart in: query type: string + - name: timeEnd + in: query + type: string responses: 200: description: A successful response.