Class: Kaui::AuditLogsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::AuditLogsController
- Defined in:
- app/controllers/kaui/audit_logs_controller.rb
Constant Summary collapse
- OBJECT_WITH_HISTORY =
%w[ACCOUNT ACCOUNT_EMAIL BLOCKING_STATES BUNDLE CUSTOM_FIELD INVOICE INVOICE_ITEM PAYMENT_ATTEMPT PAYMENT PAYMENT_METHOD SUBSCRIPTION SUBSCRIPTION_EVENT TRANSACTION TAG TAG_DEFINITION]
Constants included from EngineControllerUtil
EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary collapse
Methods inherited from EngineController
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user
Instance Method Details
#history ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/kaui/audit_logs_controller.rb', line 43 def history json_response do account_id = params.require(:account_id) object_id = params.require(:object_id) object_type = params.require(:object_type) = audit_logs_with_history = [] error = nil begin if object_type == 'ACCOUNT' account = Kaui::Account::find_by_id_or_key(object_id, false, false, ) audit_logs_with_history = account.audit_logs_with_history() elsif object_type == 'ACCOUNT_EMAIL' account = Kaui::Account::find_by_id_or_key(account_id, false, false, ) audit_logs_with_history = account.email_audit_logs_with_history(object_id, ) elsif object_type == 'BLOCKING_STATES' audit_logs_with_history = Kaui::Account::blocking_state_audit_logs_with_history(object_id, ) elsif object_type == 'BUNDLE' bundle = Kaui::Bundle::find_by_id(object_id, ) audit_logs_with_history = bundle.audit_logs_with_history() elsif object_type == 'CUSTOM_FIELD' audit_logs_with_history = Kaui::CustomField.new({:custom_field_id => object_id}).audit_logs_with_history() elsif object_type == 'INVOICE' invoice = Kaui::Invoice::find_by_id(object_id, false, "NONE", ) audit_logs_with_history = invoice.audit_logs_with_history() elsif object_type == 'INVOICE_ITEM' invoice_item = Kaui::InvoiceItem.new invoice_item.invoice_item_id = object_id audit_logs_with_history = invoice_item.audit_logs_with_history() =begin See https://github.com/killbill/killbill/issues/1104 elsif object_type == 'INVOICE_PAYMENT' invoice_payment = Kaui::InvoicePayment::find_by_id(object_id, false, false, cached_options_for_klient) =end audit_logs_with_history = invoice_payment.audit_logs_with_history() elsif object_type == 'PAYMENT_ATTEMPT' audit_logs_with_history = Kaui::Payment::attempt_audit_logs_with_history(object_id, ) elsif object_type == 'PAYMENT' payment = Kaui::Payment::find_by_id(object_id, false, false, ) audit_logs_with_history = payment.audit_logs_with_history() elsif object_type == 'PAYMENT_METHOD' payment_method = Kaui::PaymentMethod::find_by_id(object_id, false, ) audit_logs_with_history = payment_method.audit_logs_with_history() elsif object_type == 'SUBSCRIPTION' subscription = Kaui::Subscription::find_by_id(object_id, ) audit_logs_with_history = subscription.audit_logs_with_history() elsif object_type == 'SUBSCRIPTION_EVENT' audit_logs_with_history = Kaui::Subscription::event_audit_logs_with_history(object_id, ) elsif object_type == 'TRANSACTION' audit_logs_with_history = Kaui::Transaction::new({:transaction_id => object_id}).audit_logs_with_history() elsif object_type == 'TAG' audit_logs_with_history = Kaui::Tag.new({:tag_id => object_id}).audit_logs_with_history() elsif object_type == 'TAG_DEFINITION' audit_logs_with_history = Kaui::TagDefinition.new({:id => object_id}).audit_logs_with_history() else error = "Object [#{object_type}] history is not supported." end rescue Exception => e error = e. end { audits: audit_logs_with_history, error: error } end end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/kaui/audit_logs_controller.rb', line 4 def index = @account = Kaui::Account::find_by_id_or_key(params.require(:account_id), false, false, ) audit_logs = @account.audit() formatter = lambda do |log| object_id_text = view_context.object_id_popover(log.object_id) if object_with_history?(log.object_type) object_id_text = view_context.link_to(object_id_text, '#showHistoryModal', data: { toggle: 'modal', object_id: log.object_id, object_type: log.object_type, change_date: log.change_date, change_type: log.change_type, account_id: @account.account_id }) end [ log.change_date, object_id_text, log.object_type, log.change_type, log.changed_by, log.reason_code, log.comments, view_context.object_id_popover(log.user_token, 'left') ] end @audit_logs_json = [] audit_logs.each { |page| @audit_logs_json << formatter.call(page) } @audit_logs_json = @audit_logs_json.to_json end |