This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
Complete Activity Log System #560
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d822f73
Audit for AccountUser
a367001
Add Auditable to all schemas
dc0e60a
Merge branch 'master' into 463-complete-audit-system
7195f33
Move utils modules from EWalletConfig to Utils sub app
b303f0c
Implement ActivityLogger sub application
4d33658
Integrate ActivityLogger in EWalletDB
884d659
Add missing dependency to local ledger sub app
fb46496
Integrate ActivityLogger in EWallet sub app
dc2fc57
Integrate ActivityLogger in EWalletAPI sub app
944846a
Integrate ActivityLogger in AdminAPI
2e19f73
Add ActivityLogger logic to EWalletConfig
af80f74
Updated seeds to work with ActivityLogger
6bc3a57
Remove unneeded originator from EWalletDB schemas
05142e9
Merge branch 'master' into 463-complete-audit-system
88630ae
Add account test and handle encrypted_data properly
6465951
Add proper encryption and prevent_save fields to activity logs
43e244d
Add activity logs tests for accounts, users and invites
5e6e77d
Merge master
534348c
Add tests for log generation in controllers
a535a8f
Fix PR comments
41676d5
Merge branch 'master' into 463-complete-audit-system
cb87f6a
Remove EWalletConfig module dependency from ActivityLogger
b075b1e
Fix wrong table name in migration
219bae5
Merge remote-tracking branch 'origin/master' into 463-complete-audit-…
c967f15
Rename indexes and pkey in migration
6f597bc
Add more tests for ActivityLog.insert/3
1d2d7c9
Add a test with both encrypted and prevent_saving
8b899f7
Merge remote-tracking branch 'origin/master' into 463-complete-audit-…
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
apps/activity_logger/test/support/activity_logger_test_helper.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
defmodule ActivityLogger.ActivityLoggerTestHelper do | ||
@moduledoc """ | ||
Contains helper methods to make testing activity logging easier | ||
""" | ||
use ExUnit.CaseTemplate | ||
import Ecto.Query | ||
alias ActivityLogger.{ActivityLog, System, Repo} | ||
alias EWalletConfig.{Setting, StoredSetting} | ||
|
||
def assert_activity_log( | ||
log, | ||
action: action, | ||
originator: originator, | ||
target: %Setting{} = target, | ||
changes: changes, | ||
encrypted_changes: encrypted_changes | ||
) do | ||
assert_activity_log( | ||
log, | ||
action: action, | ||
originator: originator, | ||
target: %StoredSetting{uuid: target.uuid}, | ||
changes: changes, | ||
encrypted_changes: encrypted_changes | ||
) | ||
end | ||
|
||
def assert_activity_log( | ||
log, | ||
action: action, | ||
originator: :system, | ||
target: target, | ||
changes: changes, | ||
encrypted_changes: encrypted_changes | ||
) do | ||
assert_activity_log( | ||
log, | ||
action: action, | ||
originator: %System{}, | ||
target: target, | ||
changes: changes, | ||
encrypted_changes: encrypted_changes | ||
) | ||
end | ||
|
||
def assert_activity_log( | ||
log, | ||
action: action, | ||
originator: originator, | ||
target: target, | ||
changes: changes, | ||
encrypted_changes: encrypted_changes | ||
) do | ||
assert log.action == action | ||
assert log.inserted_at != nil | ||
assert log.originator_type == ActivityLog.get_type(originator.__struct__) | ||
assert log.originator_uuid == originator.uuid | ||
assert log.target_type == ActivityLog.get_type(target.__struct__) | ||
assert log.target_uuid == target.uuid | ||
assert log.target_changes == changes | ||
assert log.target_encrypted_changes == encrypted_changes | ||
end | ||
|
||
def assert_simple_activity_log( | ||
log, | ||
action: action, | ||
originator_type: o_type, | ||
target_type: t_type | ||
) do | ||
assert log.action == action | ||
assert log.inserted_at != nil | ||
assert log.originator_type == o_type | ||
assert log.target_type == t_type | ||
end | ||
|
||
def get_all_activity_logs(schema) do | ||
type = ActivityLog.get_type(schema.__struct__) | ||
|
||
ActivityLog | ||
|> order_by(asc: :inserted_at) | ||
|> where(target_type: ^type) | ||
|> Repo.all() | ||
end | ||
|
||
def get_all_activity_logs_since(since) do | ||
ActivityLog | ||
|> order_by(asc: :inserted_at) | ||
|> where([a], a.inserted_at > ^since) | ||
|> Repo.all() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:mindblown: