feat: add pagination support for audit logs API (#6843)
Add pagination support for audit logs API
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -62,7 +62,5 @@ test/cypress/videos/*
|
|||||||
/config/*.enc
|
/config/*.enc
|
||||||
|
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
|
||||||
# yalc for local testing
|
# yalc for local testing
|
||||||
.yalc
|
.yalc
|
||||||
yalc.lock
|
|
||||||
@@ -3,8 +3,16 @@ class Api::V1::Accounts::AuditLogsController < Api::V1::Accounts::BaseController
|
|||||||
before_action :check_admin_authorization?
|
before_action :check_admin_authorization?
|
||||||
before_action :fetch_audit
|
before_action :fetch_audit
|
||||||
|
|
||||||
|
RESULTS_PER_PAGE = 15
|
||||||
|
|
||||||
def show
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ RSpec.describe 'Enterprise Audit API', type: :request do
|
|||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
json_response = JSON.parse(response.body)
|
json_response = JSON.parse(response.body)
|
||||||
expect(json_response[0]['auditable_type']).to eql('Inbox')
|
expect(json_response['audit_logs'][0]['auditable_type']).to eql('Inbox')
|
||||||
expect(json_response[0]['action']).to eql('create')
|
expect(json_response['audit_logs'][0]['action']).to eql('create')
|
||||||
expect(json_response[0]['audited_changes']['name']).to eql(inbox.name)
|
expect(json_response['audit_logs'][0]['audited_changes']['name']).to eql(inbox.name)
|
||||||
expect(json_response[0]['associated_id']).to eql(account.id)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user