Skip to content

Commit

Permalink
feat: add pagination support for audit logs API (chatwoot#6843)
Browse files Browse the repository at this point in the history
Add pagination support for audit logs API
  • Loading branch information
vishnu-narayanan authored Apr 10, 2023
1 parent d49989a commit ad75a79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,5 @@ test/cypress/videos/*
/config/*.enc

.vscode/settings.json

# yalc for local testing
.yalc
yalc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@

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
Expand Down

0 comments on commit ad75a79

Please sign in to comment.