loggable_activity 0.1.52 → 0.1.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +14 -1
- data/GETTING-STARTED.md +96 -42
- data/README.md +5 -0
- data/docs/LoggableActivity/Activity.html +44 -16
- data/docs/LoggableActivity/Encryption.html +31 -24
- data/docs/LoggableActivity/EncryptionKey.html +10 -7
- data/docs/LoggableActivity/Hooks.html +19 -19
- data/docs/LoggableActivity/Payload.html +7 -7
- data/docs/LoggableActivity/PayloadsBuilder.html +75 -22
- data/docs/LoggableActivity/UpdatePayloadsBuilder.html +66 -67
- data/docs/created.rid +10 -10
- data/docs/js/search_index.js +1 -1
- data/docs/js/search_index.js.gz +0 -0
- data/docs/table_of_contents.html +25 -0
- data/help/loggable_activity_help.txt +19 -0
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/loggable_activity/.DS_Store +0 -0
- data/lib/generators/loggable_activity/install_generator.rb +104 -11
- data/lib/generators/loggable_activity/install_templates_generator.rb +103 -0
- data/lib/generators/loggable_activity/templates/.DS_Store +0 -0
- data/lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb +31 -0
- data/lib/generators/loggable_activity/templates/create_loggable_activities.rb +16 -0
- data/lib/generators/loggable_activity/templates/helpers/loggable_activity_helper.rb +49 -0
- data/lib/generators/loggable_activity/templates/loggable_activity.en.yaml +36 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.erb +23 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.slim +18 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_destroy.html.erb +18 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_destroy.html.slim +17 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_show.html.erb +18 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_show.html.slim +17 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_update.html.erb +18 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_update.html.slim +12 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_activity_info.html.erb +12 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_activity_info.html.slim +11 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_list_attrs.html.erb +8 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_list_attrs.html.slim +6 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_update_attrs.html.erb +17 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_update_attrs.html.slim +14 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_updated_relations.html.erb +23 -0
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_updated_relations.html.slim +21 -0
- data/lib/loggable_activity/payloads_builder.rb +3 -19
- data/lib/loggable_activity/update_payloads_builder.rb +18 -60
- data/lib/loggable_activity/version.rb +1 -1
- metadata +37 -18
- data/lib/generators/loggable_activity/templates/create_loggable_encryption_keys.rb +0 -11
- data/lib/generators/loggable_activity/templates/create_loggable_payloads.rb +0 -15
- /data/lib/generators/loggable_activity/templates/{loggable_activity.en.yml → config/locales/loggable_activity.en.yml} +0 -0
- /data/lib/generators/loggable_activity/templates/{loggable_activity.yml → config/loggable_activity.yaml} +0 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module LoggableActivity
|
6
|
+
module Generators
|
7
|
+
class InstallTemplatesGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
class_option :template, type: :string, default: 'erb'
|
11
|
+
|
12
|
+
def create_helper
|
13
|
+
copy_file 'helpers/loggable_activity_helper.rb', 'app/helpers/loggable_activity_helper.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_views
|
17
|
+
template_type = options['template']
|
18
|
+
|
19
|
+
case template_type
|
20
|
+
when 'slim'
|
21
|
+
# Copy slim files
|
22
|
+
copy_files('slim')
|
23
|
+
else
|
24
|
+
# Copy erb files
|
25
|
+
copy_files('erb')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def completion_message
|
30
|
+
message = <<~MESSAGE
|
31
|
+
------------------------------------------------
|
32
|
+
___ _ _ _ _#{' '}
|
33
|
+
|_ _| _ __ ___| |_ __ _| | __ _| |_(_) ___ _ __#{' '}
|
34
|
+
| | | '_ \\/ __| __/ _` | |/ _` | __| |/ _ \\| '_ \\#{' '}
|
35
|
+
| | | | | \\__ \\ || (_| | | (_| | |_| | (_) | | | |
|
36
|
+
|___| |_| |_|___/\\__\\__,_|_|\\__,_|\\__|_|\\___/|_| |_|
|
37
|
+
____ _ _ _#{' '}
|
38
|
+
/ ___| ___ _ __ ___ _ __ | | ___| |_ ___ __| |
|
39
|
+
| | / _ \\| '_ ` _ \\| '_ \\| |/ _ \\ __/ _ \\/ _` |
|
40
|
+
| |___ | (_) | | | | | | |_) | | __/ || __/ (_| |
|
41
|
+
\\____| \\___/|_| |_| |_| .__/|_|\\___|\\__\\___|\\__,_|
|
42
|
+
|_|#{' '}
|
43
|
+
|
44
|
+
LoggableActivity templates installed successfully!
|
45
|
+
|
46
|
+
Quick Start:
|
47
|
+
|
48
|
+
1. Create a new controller to show the list of activities.
|
49
|
+
$ rails generate controller LoggableActivities index
|
50
|
+
|
51
|
+
2 Add the following to the loggable_activities_controller.rb
|
52
|
+
def index
|
53
|
+
@loggable_activities = LoggableActivity::Activity.latest(50)
|
54
|
+
end
|
55
|
+
|
56
|
+
3. Update routes.rb
|
57
|
+
resources :loggable_activities, only: [:index]
|
58
|
+
|
59
|
+
4. update the index view in app/views/loggable_activities/index.html.TEMPLATE_TYPE
|
60
|
+
h1 Activities#{' '}
|
61
|
+
table.table#{' '}
|
62
|
+
thead
|
63
|
+
tr
|
64
|
+
th Info#{' '}
|
65
|
+
th Attributes
|
66
|
+
th Actions
|
67
|
+
tbody
|
68
|
+
- @loggable_activities.each do |activity|
|
69
|
+
= render_activity(activity)
|
70
|
+
|
71
|
+
5. Visit
|
72
|
+
http://localhost:3000/loggable_activities
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
For more information, please visit:
|
77
|
+
https://github.com/maxgronlund/LoggableActivity/blob/main/GETTING-STARTED.md
|
78
|
+
|
79
|
+
Install templates
|
80
|
+
$ rails generate loggable_activity:install_templates
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
------------------------------------------------
|
85
|
+
MESSAGE
|
86
|
+
|
87
|
+
puts message
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def copy_files(type)
|
93
|
+
file_extension = type == 'slim' ? 'html.slim' : 'html.erb'
|
94
|
+
%w[create destroy show update].each do |action|
|
95
|
+
copy_file "views/loggable_activity/templates/default/_#{action}.#{file_extension}", "app/views/loggable_activity/templates/default/_#{action}.#{file_extension}"
|
96
|
+
end
|
97
|
+
%w[activity_info list_attrs update_attrs updated_relations].each do |shared|
|
98
|
+
copy_file "views/loggable_activity/templates/shared/_#{shared}.#{file_extension}", "app/views/loggable_activity/templates/shared/_#{shared}.#{file_extension}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateLoggableActivities < ActiveRecord::Migration[7.1]
|
4
|
+
def change
|
5
|
+
create_table :loggable_activities, id: :uuid, default: 'gen_random_uuid()' do |t|
|
6
|
+
t.string :action
|
7
|
+
t.references :actor, polymorphic: true, null: true, type: :uuid
|
8
|
+
t.string :encrypted_actor_display_name
|
9
|
+
t.string :encrypted_record_display_name
|
10
|
+
t.references :record, polymorphic: true, null: true, type: :uuid
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :loggable_payloads, id: :uuid, default: 'gen_random_uuid()' do |t|
|
16
|
+
t.references :record, polymorphic: true, null: true, type: :uuid
|
17
|
+
t.json :encrypted_attrs
|
18
|
+
t.integer :payload_type, default: 0
|
19
|
+
t.boolean :data_owner, default: false
|
20
|
+
t.references :activity, type: :uuid, foreign_key: { to_table: 'loggable_activities', class_name: 'LoggableActivity::Activity' }
|
21
|
+
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :loggable_encryption_keys, id: :uuid, default: 'gen_random_uuid()' do |t|
|
26
|
+
t.string :key
|
27
|
+
t.references :parent_key, type: :uuid, foreign_key: { to_table: 'loggable_encryption_keys', on_delete: :nullify }
|
28
|
+
t.references :record, polymorphic: true, type: :uuid
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -11,5 +11,21 @@ class CreateLoggableActivities < ActiveRecord::Migration[6.1]
|
|
11
11
|
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
|
+
|
15
|
+
create_table :loggable_payloads do |t|
|
16
|
+
t.references :record, polymorphic: true, null: true
|
17
|
+
t.json :encrypted_attrs
|
18
|
+
t.integer :payload_type, default: 0
|
19
|
+
t.boolean :data_owner, default: false
|
20
|
+
t.references :activity, foreign_key: { to_table: 'loggable_activities', class_name: 'LoggableActivity::Activity' }
|
21
|
+
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :loggable_encryption_keys do |t|
|
26
|
+
t.references :parent_key, foreign_key: { to_table: 'loggable_encryption_keys', on_delete: :nullify }
|
27
|
+
t.string :key
|
28
|
+
t.references :record, polymorphic: true, on_delete: :nullify
|
29
|
+
end
|
14
30
|
end
|
15
31
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LoggableActivityHelper
|
4
|
+
include ApplicationHelper
|
5
|
+
|
6
|
+
def render_activity(activity)
|
7
|
+
render partial: template_path(activity), locals: { activity: }
|
8
|
+
end
|
9
|
+
|
10
|
+
def primary_type(activity)
|
11
|
+
I18n.t("loggable.activity.models.#{activity.record_type}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def relation_type(relation_attrs)
|
15
|
+
I18n.t("loggable.activity.models.#{relation_attrs[:record_class]}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_relation_class(update_attrs)
|
19
|
+
I18n.t("loggable.activity.models.#{update_attrs[:record_class]}")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def action_template_path(activity)
|
25
|
+
"loggable_activity/templates/#{activity.action.gsub('.', '/')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def template_path(activity)
|
29
|
+
template_path = action_template_path(activity)
|
30
|
+
if lookup_context.template_exists?(template_path, [], true)
|
31
|
+
template_path
|
32
|
+
else
|
33
|
+
action = activity.action.split('.').last || 'default'
|
34
|
+
"loggable_activity/templates/default/#{action}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def activity_payload(activity)
|
39
|
+
@activity_payload ||= build_payload(activity)
|
40
|
+
end
|
41
|
+
|
42
|
+
def activity_attrs(activity)
|
43
|
+
@activity_attrs ||= activity_payload(activity).fetch(:activity, {})
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_payload(activity)
|
47
|
+
Loggable::JsonPayloadFactory.new(activity).build_payload
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
en:
|
2
|
+
loggable:
|
3
|
+
activity:
|
4
|
+
deleted: "***** DELETED *****"
|
5
|
+
demo/address:
|
6
|
+
update: An address was updated
|
7
|
+
create: An address was created
|
8
|
+
show: An address was shown
|
9
|
+
destroy: An address was deleted
|
10
|
+
demo/club:
|
11
|
+
update: A club was updated
|
12
|
+
create: A club was created
|
13
|
+
show: A club was shown
|
14
|
+
destroy: A club was deleted
|
15
|
+
demo/journal:
|
16
|
+
update: A journal was updated
|
17
|
+
create: A journal was created
|
18
|
+
show: A journal was shown
|
19
|
+
destroy: A journal was deleted
|
20
|
+
demo/product:
|
21
|
+
update: A product was updated
|
22
|
+
create: A product was created
|
23
|
+
show: A product was shown
|
24
|
+
destroy: A product was deleted
|
25
|
+
user:
|
26
|
+
update: A user was updated
|
27
|
+
create: A user was created
|
28
|
+
show: "A user was shown"
|
29
|
+
destroy: A user was deleted
|
30
|
+
models:
|
31
|
+
Demo::Address: Address
|
32
|
+
Demo::UserProfile: Profile
|
33
|
+
Demo::Club: Club
|
34
|
+
Demo::Journal: Journal
|
35
|
+
Demo/Product: Product
|
36
|
+
User: User
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<tr>
|
2
|
+
<td>
|
3
|
+
<%= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity } %>
|
4
|
+
</td>
|
5
|
+
<td>
|
6
|
+
<b class="text-secondary"><%= primary_type(activity) %></b>
|
7
|
+
<br>
|
8
|
+
<% activity.primary_payload_attrs.each do |k, v| %>
|
9
|
+
<%= "<i>#{k}:</i> #{v.blank? ? t('loggable.activity.deleted') : v}".html_safe %>
|
10
|
+
<br>
|
11
|
+
<% end %>
|
12
|
+
<br>
|
13
|
+
<% activity.relations_attrs.each do |relation_attrs| %>
|
14
|
+
<b class="text-secondary"><%= relation_type(relation_attrs) %></b>
|
15
|
+
<br>
|
16
|
+
<%= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation_attrs[:attrs] } %>
|
17
|
+
<br>
|
18
|
+
<% end %>
|
19
|
+
</td>
|
20
|
+
<td>
|
21
|
+
<%= link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
|
22
|
+
</td>
|
23
|
+
</tr>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
tr
|
2
|
+
td
|
3
|
+
= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity }
|
4
|
+
td
|
5
|
+
b.text-secondary = primary_type(activity)
|
6
|
+
br
|
7
|
+
- activity.primary_payload_attrs.each do |k, v|
|
8
|
+
= "<i>#{k}:</i> #{v.blank? ? t('loggable.activity.deleted') : v}".html_safe
|
9
|
+
br/
|
10
|
+
br
|
11
|
+
- activity.relations_attrs.each do |relation_attrs|
|
12
|
+
b.text-secondary = relation_type(relation_attrs)
|
13
|
+
br/
|
14
|
+
=
|
15
|
+
= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation_attrs[:attrs] }
|
16
|
+
br/
|
17
|
+
td
|
18
|
+
=< link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<tr>
|
2
|
+
<td>
|
3
|
+
<%= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity } %>
|
4
|
+
</td>
|
5
|
+
<td>
|
6
|
+
<% update_activity_attrs = activity.update_activity_attrs %>
|
7
|
+
<% if update_attrs = update_activity_attrs[:update_attrs] %>
|
8
|
+
<%= render partial: 'loggable_activity/templates/shared/update_attrs', locals: { update_attrs: update_attrs } %>
|
9
|
+
<% end %>
|
10
|
+
<% if updated_relations = update_activity_attrs[:updated_relations_attrs] %>
|
11
|
+
<br>
|
12
|
+
<%= render partial: 'loggable_activity/templates/shared/updated_relations', locals: { updated_relations: updated_relations } %>
|
13
|
+
<% end %>
|
14
|
+
</td>
|
15
|
+
<td>
|
16
|
+
<%= link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
|
17
|
+
</td>
|
18
|
+
</tr>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
tr
|
2
|
+
td
|
3
|
+
= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity }
|
4
|
+
td
|
5
|
+
b.text-secondary = primary_type(activity)
|
6
|
+
br/
|
7
|
+
- activity.primary_payload_attrs.each do |k, v|
|
8
|
+
= "<i>#{k}:</i> #{v.blank? ? t('loggable.activity.deleted') : v}".html_safe
|
9
|
+
br/
|
10
|
+
br/
|
11
|
+
- activity.relations_attrs.each do |relation_attrs|
|
12
|
+
b.text-secondary = relation_type(relation_attrs)
|
13
|
+
br/
|
14
|
+
= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation_attrs[:attrs] }
|
15
|
+
br/
|
16
|
+
td
|
17
|
+
=< link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<tr>
|
2
|
+
<td>
|
3
|
+
<%= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity } %>
|
4
|
+
</td>
|
5
|
+
<td>
|
6
|
+
<b class="text-secondary"><%= primary_type(activity) %></b><br/>
|
7
|
+
<% activity.primary_payload_attrs.each do |k, v| %>
|
8
|
+
<%= "<i>#{k}:</i> #{v.blank? ? t('loggable.activity.deleted') : v}".html_safe %><br/>
|
9
|
+
<% end %><br/>
|
10
|
+
<% activity.relations_attrs.each do |relation_attrs| %>
|
11
|
+
<b class="text-secondary"><%= relation_type(relation_attrs) %></b><br/>
|
12
|
+
<%= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation_attrs[:attrs] } %><br/>
|
13
|
+
<% end %>
|
14
|
+
</td>
|
15
|
+
<td>
|
16
|
+
<%= link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
|
17
|
+
</td>
|
18
|
+
</tr>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
tr
|
2
|
+
td
|
3
|
+
= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity }
|
4
|
+
td
|
5
|
+
b.text-secondary = primary_type(activity)
|
6
|
+
br/
|
7
|
+
- activity.primary_payload_attrs.each do |k, v|
|
8
|
+
= "<i>#{k}:</i> #{v.blank? ? t('loggable.activity.deleted') : v}".html_safe
|
9
|
+
br/
|
10
|
+
br/
|
11
|
+
- activity.relations_attrs.each do |relation_attrs|
|
12
|
+
b.text-secondary = relation_type(relation_attrs)
|
13
|
+
br/
|
14
|
+
= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation_attrs[:attrs] }
|
15
|
+
br/
|
16
|
+
td
|
17
|
+
=< link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<tr>
|
2
|
+
<td>
|
3
|
+
<%= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity } %>
|
4
|
+
</td>
|
5
|
+
<td>
|
6
|
+
<% update_activity_attrs = activity.update_activity_attrs %>
|
7
|
+
<% if update_attrs = update_activity_attrs[:update_attrs] %>
|
8
|
+
<%= render partial: 'loggable_activity/templates/shared/update_attrs', locals: { update_attrs: update_attrs } %>
|
9
|
+
<% end %>
|
10
|
+
<% if updated_relations = update_activity_attrs[:updated_relations_attrs] %>
|
11
|
+
<br>
|
12
|
+
<%= render partial: 'loggable_activity/templates/shared/updated_relations', locals: { updated_relations: updated_relations } %>
|
13
|
+
<% end %>
|
14
|
+
</td>
|
15
|
+
<td>
|
16
|
+
<%= link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
|
17
|
+
</td>
|
18
|
+
</tr>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
tr
|
2
|
+
td
|
3
|
+
= render partial: 'loggable_activity/templates/shared/activity_info', locals: { activity: activity }
|
4
|
+
td
|
5
|
+
- update_activity_attrs = activity.update_activity_attrs
|
6
|
+
- if update_attrs = update_activity_attrs[:update_attrs]
|
7
|
+
= render partial: 'loggable_activity/templates/shared/update_attrs', locals: { update_attrs: update_attrs }
|
8
|
+
- if updated_relations = update_activity_attrs[:updated_relations_attrs]
|
9
|
+
br/
|
10
|
+
= render partial: 'loggable_activity/templates/shared/updated_relations', locals: { updated_relations: updated_relations }
|
11
|
+
td
|
12
|
+
=< link_to 'Delete', demo_activity_log_path(activity), data: { turbo_method: :delete, confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class="px-4">
|
2
|
+
<h5><%= t("loggable.activity.#{activity.action}", name: "") %></h5>
|
3
|
+
<b><%= activity.record_display_name %></b>
|
4
|
+
<br>
|
5
|
+
<i>Actor: </i>
|
6
|
+
<br>
|
7
|
+
<%= activity.actor_display_name %>
|
8
|
+
<br>
|
9
|
+
<i>When: </i>
|
10
|
+
<br>
|
11
|
+
<%= I18n.l(activity.created_at, format: :long) %>
|
12
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<b class="text-secondary"><%= update_relation_class(update_attrs) %></b>
|
2
|
+
<br>
|
3
|
+
<% if update_attrs[:attrs] == :deleted %>
|
4
|
+
<%= t('loggable.activity.deleted') %>
|
5
|
+
<% else %>
|
6
|
+
<% update_attrs[:attrs].each do |attr| %>
|
7
|
+
<% attr.each do |key, from_to| %>
|
8
|
+
<% next if from_to.nil? %>
|
9
|
+
<i><%= key %></i>
|
10
|
+
<br>
|
11
|
+
<%= "from: #{from_to[:from].nil? ? 'Empty' : from_to[:from]}" %>
|
12
|
+
<br>
|
13
|
+
<%= "to: #{from_to[:to].nil? ? 'Empty' : from_to[:to]}" %>
|
14
|
+
<br>
|
15
|
+
<% end %>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
b.text-secondary = update_relation_class(update_attrs)
|
2
|
+
br/
|
3
|
+
- if update_attrs[:attrs] == :deleted
|
4
|
+
= t('loggable.activity.deleted')
|
5
|
+
- else
|
6
|
+
- update_attrs[:attrs].each do |attr|
|
7
|
+
- attr.each do |key, from_to|
|
8
|
+
- next if from_to.nil?
|
9
|
+
i = key
|
10
|
+
br/
|
11
|
+
= "from: #{from_to[:from].nil? ? "Empty" : from_to[:from]}"
|
12
|
+
br/
|
13
|
+
= "to: #{from_to[:to].nil? ? "Empty" : from_to[:to]}"
|
14
|
+
br/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% updated_relations.each do |relation| %>
|
2
|
+
<b class="text-secondary"><%= update_relation_class(relation) %></b>
|
3
|
+
<br>
|
4
|
+
<% if relation[:previous_attrs].present? %>
|
5
|
+
<i>From:</i>
|
6
|
+
<br>
|
7
|
+
<%= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation[:previous_attrs][:attrs] } %>
|
8
|
+
<% else %>
|
9
|
+
<i>From:</i>
|
10
|
+
<br>
|
11
|
+
Empty
|
12
|
+
<br>
|
13
|
+
<% end %>
|
14
|
+
<% if relation[:current_attrs].present? %>
|
15
|
+
<i>To:</i>
|
16
|
+
<br>
|
17
|
+
<%= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation[:current_attrs][:attrs] } %>
|
18
|
+
<% else %>
|
19
|
+
<i>To:</i>
|
20
|
+
<br>
|
21
|
+
Empty
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
- updated_relations.each do |relation|
|
2
|
+
b.text-secondary = update_relation_class(relation)
|
3
|
+
br/
|
4
|
+
- if relation[:previous_attrs].present?
|
5
|
+
i From:
|
6
|
+
br/
|
7
|
+
= render partial:'loggable_activity/templates/shared/list_attrs', locals: {attrs: relation[:previous_attrs][:attrs] }
|
8
|
+
- else
|
9
|
+
i From:
|
10
|
+
br/
|
11
|
+
|Empty
|
12
|
+
br
|
13
|
+
- if relation[:current_attrs].present?
|
14
|
+
i To:
|
15
|
+
br/
|
16
|
+
= render partial: 'loggable_activity/templates/shared/list_attrs', locals: { attrs: relation[:current_attrs][:attrs] }
|
17
|
+
- else
|
18
|
+
i To:
|
19
|
+
br/
|
20
|
+
|Empty
|
21
|
+
|
@@ -56,7 +56,7 @@ module LoggableActivity
|
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|
59
|
-
# Builds payloads for
|
59
|
+
# Builds payloads for relations
|
60
60
|
#
|
61
61
|
# @param relation_config [Hash] The configuration of the relation.
|
62
62
|
def build_relation_payload(relation_config)
|
@@ -81,26 +81,9 @@ module LoggableActivity
|
|
81
81
|
return nil if associated_record.nil?
|
82
82
|
|
83
83
|
build_associated_payload(associated_record, relation_config)
|
84
|
-
|
85
|
-
# associated_loggable_attrs = relation_config['loggable_attrs']
|
86
|
-
|
87
|
-
# encryption_key = associated_record_encryption_key(associated_record, relation_config['data_owner'])
|
88
|
-
|
89
|
-
# encrypted_attrs =
|
90
|
-
# encrypt_attrs(
|
91
|
-
# associated_record.attributes,
|
92
|
-
# associated_loggable_attrs,
|
93
|
-
# encryption_key.key
|
94
|
-
# )
|
95
|
-
|
96
|
-
# @payloads << LoggableActivity::Payload.new(
|
97
|
-
# record: associated_record,
|
98
|
-
# encrypted_attrs:,
|
99
|
-
# payload_type: 'current_association',
|
100
|
-
# data_owner: relation_config['data_owner']
|
101
|
-
# )
|
102
84
|
end
|
103
85
|
|
86
|
+
# Builds payloads for has_many relations.
|
104
87
|
def build_has_many_payloads(relation_config, relation_type)
|
105
88
|
associated_records = send(relation_config[relation_type])
|
106
89
|
return nil if associated_records.empty?
|
@@ -110,6 +93,7 @@ module LoggableActivity
|
|
110
93
|
end
|
111
94
|
end
|
112
95
|
|
96
|
+
# Builds the payload for an associated record.
|
113
97
|
def build_associated_payload(associated_record, relation_config)
|
114
98
|
associated_loggable_attrs = relation_config['loggable_attrs']
|
115
99
|
encryption_key = associated_record_encryption_key(associated_record, relation_config['data_owner'])
|
@@ -4,66 +4,6 @@ module LoggableActivity
|
|
4
4
|
# This module is responsible for building update payloads used in loggable activities.
|
5
5
|
module UpdatePayloadsBuilder
|
6
6
|
# Builds payloads for an activity update event.
|
7
|
-
#
|
8
|
-
# Example:
|
9
|
-
# build_update_payloads
|
10
|
-
#
|
11
|
-
# Returns:
|
12
|
-
# [
|
13
|
-
# [0] #<LoggableActivity::Payload:0x00000001047d31d8> {
|
14
|
-
# :id => nil,
|
15
|
-
# :record_type => "Demo::Club",
|
16
|
-
# :record_id => 7,
|
17
|
-
# :encrypted_attrs => {
|
18
|
-
# "changes" => [
|
19
|
-
# [0] {
|
20
|
-
# "name" => {
|
21
|
-
# "from" => "+aQznZK64KLQ8wsyZlSOGQbqm+J8gDX93rNFeF+wY68=\n",
|
22
|
-
# "to" => "OdS834ZDS06+AYxmz4cUjhtgk7Jc8NoOVAAqR81Is7w=\n"
|
23
|
-
# }
|
24
|
-
# }
|
25
|
-
# ]
|
26
|
-
# },
|
27
|
-
# :payload_type => "update_payload",
|
28
|
-
# :data_owner => false,
|
29
|
-
# :activity_id => nil,
|
30
|
-
# :created_at => nil,
|
31
|
-
# :updated_at => nil
|
32
|
-
# },
|
33
|
-
# [1] #<LoggableActivity::Payload:0x0000000107847f80> {
|
34
|
-
# :id => nil,
|
35
|
-
# :record_type => "Demo::Address",
|
36
|
-
# :record_id => 7,
|
37
|
-
# :encrypted_attrs => {
|
38
|
-
# "street" => "W7cmT22Bb5TKVmtxTYJt1w==\n",
|
39
|
-
# "city" => "AAwdTI7Xo86cMbFBAMsMIw==\n",
|
40
|
-
# "country" => "7gu5wdu6O9tD7Q7+EDOqAg==\n",
|
41
|
-
# "postal_code" => "ljjfT6MXGNK33/PUyi6Nmw==\n"
|
42
|
-
# },
|
43
|
-
# :payload_type => "previous_association",
|
44
|
-
# :data_owner => false,
|
45
|
-
# :activity_id => nil,
|
46
|
-
# :created_at => nil,
|
47
|
-
# :updated_at => nil
|
48
|
-
# },
|
49
|
-
# [2] #<LoggableActivity::Payload:0x0000000107802a98> {
|
50
|
-
# :id => nil,
|
51
|
-
# :record_type => "Demo::Address",
|
52
|
-
# :record_id => 8,
|
53
|
-
# :encrypted_attrs => {
|
54
|
-
# "street" => "CuULVgIEgrOcWBxegKEvSg==\n",
|
55
|
-
# "city" => "QbvodOYMvNFpkvsCprqGqg==\n",
|
56
|
-
# "country" => "/N03d1OL3TY+aaiPUQ5N1A==\n",
|
57
|
-
# "postal_code" => "ZZu3S5tnaTeq+wBu0dPKBw==\n"
|
58
|
-
# },
|
59
|
-
# :payload_type => "current_association",
|
60
|
-
# :data_owner => false,
|
61
|
-
# :activity_id => nil,
|
62
|
-
# :created_at => nil,
|
63
|
-
# :updated_at => nil
|
64
|
-
# }
|
65
|
-
# ]
|
66
|
-
#
|
67
7
|
def build_update_payloads
|
68
8
|
@update_payloads = []
|
69
9
|
|
@@ -113,10 +53,28 @@ module LoggableActivity
|
|
113
53
|
case key
|
114
54
|
when 'belongs_to'
|
115
55
|
build_relation_update_for_belongs_to(relation_config)
|
56
|
+
when 'has_one'
|
57
|
+
build_relation_update_for_has_one(relation_config)
|
58
|
+
when 'has_many'
|
59
|
+
build_relation_update_for_has_many(relation_config)
|
116
60
|
end
|
117
61
|
end
|
118
62
|
end
|
119
63
|
|
64
|
+
def build_relation_update_for_has_many(relation_config)
|
65
|
+
# NOTE: This method is not implemented yet.
|
66
|
+
# It requires that there is a form where it is possible to change
|
67
|
+
# the related records. This is not implemented yet. in the Demo app
|
68
|
+
# puts relation_config['has_many']
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_relation_update_for_has_one(relation_config)
|
72
|
+
# NOTE: This method is not implemented yet.
|
73
|
+
# It requires that there is a form where it is possible to change
|
74
|
+
# the related records. This is not implemented yet. in the Demo app
|
75
|
+
# puts relation_config['has_many']
|
76
|
+
end
|
77
|
+
|
120
78
|
def build_relation_update_for_belongs_to(relation_config)
|
121
79
|
relation_id = "#{relation_config['belongs_to']}_id"
|
122
80
|
model_class_name = relation_config['model']
|