feat: auditlog for team and inbox member updates (#7516)

- adds an audit log when an agent is added or removed from a team
- adds an audit log when an agent is added or removed from an inbox

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Vishnu Narayanan
2023-08-16 08:25:19 +05:30
committed by GitHub
parent 2df83276e0
commit 7b8a3fcae0
9 changed files with 248 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
module Enterprise::Audit::InboxMember
extend ActiveSupport::Concern
included do
after_commit :create_audit_log_entry_on_create, on: :create
after_commit :create_audit_log_entry_on_delete, on: :destroy
end
private
def create_audit_log_entry_on_create
create_audit_log_entry('create')
end
def create_audit_log_entry_on_delete
create_audit_log_entry('destroy')
end
def create_audit_log_entry(action)
return if inbox.blank?
Enterprise::AuditLog.create(
auditable_id: id,
auditable_type: 'InboxMember',
action: action,
associated_id: inbox&.account_id,
audited_changes: attributes.except('updated_at', 'created_at'),
associated_type: 'Account'
)
end
end

View File

@@ -0,0 +1,31 @@
module Enterprise::Audit::TeamMember
extend ActiveSupport::Concern
included do
after_commit :create_audit_log_entry_on_create, on: :create
after_commit :create_audit_log_entry_on_delete, on: :destroy
end
private
def create_audit_log_entry_on_create
create_audit_log_entry('create')
end
def create_audit_log_entry_on_delete
create_audit_log_entry('destroy')
end
def create_audit_log_entry(action)
return if team.blank?
Enterprise::AuditLog.create(
auditable_id: id,
auditable_type: 'TeamMember',
action: action,
associated_id: team&.account_id,
audited_changes: attributes.except('updated_at', 'created_at'),
associated_type: 'Account'
)
end
end