feat: add pagination support for audit logs API (#6843)

Add pagination support for audit logs API
This commit is contained in:
Vishnu Narayanan
2023-04-10 21:07:01 +05:30
committed by GitHub
parent d49989ace1
commit ad75a79135
3 changed files with 15 additions and 7 deletions

2
.gitignore vendored
View File

@@ -62,7 +62,5 @@ test/cypress/videos/*
/config/*.enc
.vscode/settings.json
# yalc for local testing
.yalc
yalc.lock

View File

@@ -3,8 +3,16 @@ class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController
before_action :check_admin_authorization?
before_action :fetch_audit
RESULTS_PER_PAGE = 15
def show
render json: @audit_logs
@audit_logs = @audit_logs.page(params[:page]).per(RESULTS_PER_PAGE)
render json: {
audit_logs: @audit_logs,
current_page: @audit_logs.current_page,
per_page: RESULTS_PER_PAGE,
total_entries: @audit_logs.total_count
}
end
private

View File

@@ -34,10 +34,12 @@ RSpec.describe 'Enterprise Audit API', type: :request do
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response[0]['auditable_type']).to eql('Inbox')
expect(json_response[0]['action']).to eql('create')
expect(json_response[0]['audited_changes']['name']).to eql(inbox.name)
expect(json_response[0]['associated_id']).to eql(account.id)
expect(json_response['audit_logs'][0]['auditable_type']).to eql('Inbox')
expect(json_response['audit_logs'][0]['action']).to eql('create')
expect(json_response['audit_logs'][0]['audited_changes']['name']).to eql(inbox.name)
expect(json_response['audit_logs'][0]['associated_id']).to eql(account.id)
expect(json_response['current_page']).to be(1)
expect(json_response['total_entries']).to be(1)
end
end
end