loggable_activity 0.1.53 → 0.1.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 780e8614a8e5b1c9e97a70a9cb432e8a277d3617dd845fc38b7c41a235b282a9
4
- data.tar.gz: fea7bb11d9abcbeeb0423381c4a462df03c07e4ea4487d8e958e9ffe3479ff1f
3
+ metadata.gz: 4e3c72b18d402ce0870b6882beeb7438e46f4955e38ca9182c02bbe8b945ea23
4
+ data.tar.gz: e2484e4bec3907cff1d3974b9c58cde65e9c5b48dfd91cc0ab9302ced561d6b7
5
5
  SHA512:
6
- metadata.gz: 262803990c60f23a9edcd0484105e0ecac141350d8d4710c5344db7dbe5836587b3959fea74be0890f9abb0e4b0c3a5324f8725d02e3fdd493cbdb3dbcbb53c2
7
- data.tar.gz: 1ee1f8eb1850e8150665d9fc65b075c2eac86d7054f6921dee10fd35329e0643e3aa101d416b60278a5695eb8e1b4ef64e3a0ff76e0a13611f31868c31d7d0e2
6
+ metadata.gz: c39842b15b3fe0ea14970a381ba4b17222549884d90c4b96236d3bffd5a23ed97803011bef1aea4da1586fae6cdba7ab010a6ebe0e4f229b666fe174a49a4748
7
+ data.tar.gz: d44d7c04e0b5fcde4f7c8609da270ad7989bae25e84b5d6adaa2428ba5226284fb6e4187320eaa8fb8cbbe697c7804b3ec5b4fd4c9a78afc22d09084582fc305
data/.rubocop.yml CHANGED
@@ -38,3 +38,5 @@ Metrics/AbcSize:
38
38
  Exclude:
39
39
  - lib/loggable_activity/encryption.rb
40
40
  - lib/loggable_activity/update_payloads_builder.rb
41
+ - lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb
42
+ - lib/generators/loggable_activity/templates/create_loggable_activities.rb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.1.54] - 2024-02-24
2
+ - Support for BinaryID's
3
+ - Updated README.md
4
+ - Quick start guid in terminal after installations
5
+ - Support for slim
6
+
1
7
  ## [0.1.53] - 2024-02-22
2
8
  - Generator for presentation layer
3
9
  - GETTING-STARTED.md guide
data/GETTING-STARTED.md CHANGED
@@ -26,17 +26,9 @@ This will install the following files
26
26
  - config/loggable_activity.yml
27
27
  - config/locales/loggable_activity.en.yml
28
28
  - db/migrate/xxxxxxxxxxxxxx_create_loggable_activities
29
- - db/migrate/xxxxxxxxxxxxxx_create_loggable_payloads
30
- - db/migrate/xxxxxxxxxxxxxx_create_loggable_encryption_keys
31
29
 
32
- Then we have to run
33
- ```
34
- $ bundle install
35
- ```
36
-
37
- ## Add hoks to models you want to be logged
38
- Include hooks to the model we want to log.
39
30
 
31
+ ## Add hoks to models to be logged
40
32
  ```
41
33
  class User < ApplicationRecord
42
34
  include LoggableActivity::Hooks
@@ -67,8 +59,9 @@ This file defines:
67
59
  *Here is an example of content for the config/loggable_activity.yaml file*
68
60
  ```
69
61
  Demo::Club:
70
- record_display_name: name
62
+ record_display_name: email
71
63
  loggable_attrs:
64
+ - email
72
65
  - name
73
66
  auto_log:
74
67
  - create
data/README.md CHANGED
@@ -4,6 +4,8 @@ Secure protect data and log how it is handled
4
4
  - Protect and secure the privacy of data stored in Activity Logs
5
5
  - Prepare for General Data Protection Regulation (GDPR) compliance.
6
6
  - Handles activities that involves more than one table in the DB.
7
+ - Encrypt data stored in the activity log
8
+ - Support binary_ids
7
9
 
8
10
  ### Important!
9
11
  This project is under development and not ready for production. There might be breaking changes, so please consult the CHANGELOG.md
@@ -230,7 +230,7 @@
230
230
  <div class="method-source-code" id="build_relation_update_for_has_many-source">
231
231
  <pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 64</span>
232
232
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_for_has_many</span>(<span class="ruby-identifier">relation_config</span>)
233
- <span class="ruby-comment"># Note: This method is not implemented yet.</span>
233
+ <span class="ruby-comment"># NOTE: This method is not implemented yet.</span>
234
234
  <span class="ruby-comment"># It requires that there is a form where it is possible to change</span>
235
235
  <span class="ruby-comment"># the related records. This is not implemented yet. in the Demo app</span>
236
236
  <span class="ruby-comment"># puts relation_config[&#39;has_many&#39;]</span>
@@ -256,7 +256,7 @@
256
256
  <div class="method-source-code" id="build_relation_update_for_has_one-source">
257
257
  <pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 71</span>
258
258
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_for_has_one</span>(<span class="ruby-identifier">relation_config</span>)
259
- <span class="ruby-comment"># Note: This method is not implemented yet.</span>
259
+ <span class="ruby-comment"># NOTE: This method is not implemented yet.</span>
260
260
  <span class="ruby-comment"># It requires that there is a form where it is possible to change</span>
261
261
  <span class="ruby-comment"># the related records. This is not implemented yet. in the Demo app</span>
262
262
  <span class="ruby-comment"># puts relation_config[&#39;has_many&#39;]</span>
data/docs/created.rid CHANGED
@@ -1,10 +1,10 @@
1
- Wed, 21 Feb 2024 21:47:04 +0100
1
+ Sat, 24 Feb 2024 15:48:31 +0100
2
2
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/activity.rb Wed, 21 Feb 2024 12:58:24 +0100
3
3
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/configuration.rb Mon, 19 Feb 2024 15:59:34 +0100
4
4
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/encryption.rb Fri, 16 Feb 2024 15:03:24 +0100
5
5
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/encryption_key.rb Wed, 21 Feb 2024 12:58:24 +0100
6
6
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/hooks.rb Wed, 21 Feb 2024 12:58:24 +0100
7
7
  /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/payload.rb Wed, 21 Feb 2024 12:58:24 +0100
8
- /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/payloads_builder.rb Wed, 21 Feb 2024 21:46:26 +0100
9
- /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/update_payloads_builder.rb Wed, 21 Feb 2024 21:46:26 +0100
10
- /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/version.rb Wed, 21 Feb 2024 21:46:16 +0100
8
+ /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/payloads_builder.rb Thu, 22 Feb 2024 17:26:16 +0100
9
+ /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/update_payloads_builder.rb Thu, 22 Feb 2024 17:26:16 +0100
10
+ /Users/maxgronlund/Documents/Max/open-source/LoggableActivity/lib/loggable_activity/version.rb Thu, 22 Feb 2024 17:26:42 +0100
Binary file
@@ -0,0 +1,19 @@
1
+ Loggable Activity Generator Help
2
+ --------------------------------
3
+
4
+ Description:
5
+ This generator creates files and configurations for integrating the Loggable Activity gem into your Rails application.
6
+
7
+ Usage:
8
+ rails generate loggable_activity [options]
9
+
10
+ Options:
11
+ -h, [--help], [--no-help] # Display usage instructions (this message)
12
+ -m, [--uuid] # Use uuids for primary_keys
13
+
14
+ Examples:
15
+ rails generate loggable_activity --uuid # Generate loggable activity migration files with uuids for primary_keys
16
+
17
+ Note:
18
+ - This generator assumes that you have already installed the Loggable Activity gem.
19
+ - Ensure that your database schema supports UUIDs if using them as primary keys.
@@ -6,17 +6,27 @@ require 'rails/generators/named_base'
6
6
  module LoggableActivity
7
7
  module Generators
8
8
  class InstallGenerator < Rails::Generators::Base
9
+ def self.banner
10
+ 'rails generate loggable_activity:install [options]'
11
+ end
12
+
13
+ desc 'This generator configures LoggableActivity by creating migration files and initializing necessary configuration files.'
14
+
9
15
  source_root File.expand_path('templates', __dir__)
16
+ class_option :uuid, type: :boolean, desc: 'use UUID for primary keys'
10
17
 
11
18
  FILE_NAMES = %w[activity payload encryption_key].freeze
12
19
  TIME = Time.now
13
20
 
14
- def create_migration
21
+ def install
22
+ binary_ids = options['uuid'] ? true : false
15
23
  time = Time.now.utc
16
- FILE_NAMES.each_with_index do |file_name, index|
17
- timestamp = (time + index.minutes).strftime('%Y%m%d%H%M%S')
18
- migration_file_name = "create_loggable_#{file_name.pluralize}.rb"
19
- destination = File.join('db', 'migrate', "#{timestamp}_#{migration_file_name}")
24
+ timestamp = time.strftime('%Y%m%d%H%M%S')
25
+ migration_file_name = 'create_loggable_activities.rb'
26
+ destination = File.join('db', 'migrate', "#{timestamp}_#{migration_file_name}")
27
+ if binary_ids
28
+ template "binary_ids/#{migration_file_name}", destination
29
+ else
20
30
  template migration_file_name, destination
21
31
  end
22
32
  end
@@ -26,12 +36,90 @@ module LoggableActivity
26
36
  end
27
37
 
28
38
  def create_config_file
29
- copy_file 'config/loggable_activity.yml', 'config/loggable_activity.yml'
39
+ copy_file 'config/loggable_activity.yaml', 'config/loggable_activity.yaml'
30
40
  end
31
41
 
32
42
  def create_current_user_concern
33
43
  copy_file 'current_user.rb', 'app/controllers/concerns/loggable_activity/current_user.rb'
34
44
  end
45
+
46
+ def completion_message
47
+ message = <<~MESSAGE
48
+ ------------------------------------------------
49
+ ___ _ _ _ _#{' '}
50
+ |_ _| _ __ ___| |_ __ _| | __ _| |_(_) ___ _ __#{' '}
51
+ | | | '_ \\/ __| __/ _` | |/ _` | __| |/ _ \\| '_ \\#{' '}
52
+ | | | | | \\__ \\ || (_| | | (_| | |_| | (_) | | | |
53
+ |___| |_| |_|___/\\__\\__,_|_|\\__,_|\\__|_|\\___/|_| |_|
54
+ ____ _ _ _#{' '}
55
+ / ___| ___ _ __ ___ _ __ | | ___| |_ ___ __| |
56
+ | | / _ \\| '_ ` _ \\| '_ \\| |/ _ \\ __/ _ \\/ _` |
57
+ | |___ | (_) | | | | | | |_) | | __/ || __/ (_| |
58
+ \\____| \\___/|_| |_| |_| .__/|_|\\___|\\__\\___|\\__,_|
59
+ |_|#{' '}
60
+
61
+ LoggableActivity installation completed successfully!
62
+
63
+ Quick Start:
64
+
65
+ 1. include hooks to the model we want to log.
66
+ class MY_MODEL < ApplicationRecord
67
+ include LoggableActivity::Hooks
68
+
69
+ 2. Update `config/application.rb
70
+ config.loggable_activity = ActiveSupport::OrderedOptions.new
71
+ config.loggable_activity.actor_display_name = :email
72
+ config.loggable_activity.current_user_model_name = 'User'
73
+ LoggableActivity::Configuration.load_config_file('config/loggable_activity.yaml')
74
+
75
+ 3. Include current_user ApplicationController
76
+ class ApplicationController < ActionController::Base
77
+ include LoggableActivity::CurrentUser
78
+
79
+ 4. Update the 'config/loggable_activity.yaml' file with the necessary configuration.
80
+
81
+ 5. Run the migration to create the necessary tables.
82
+
83
+
84
+ For more information, please visit:
85
+ https://github.com/maxgronlund/LoggableActivity/blob/main/GETTING-STARTED.md
86
+
87
+ Install templates
88
+ $ rails generate loggable_activity:install_templates
89
+
90
+
91
+
92
+ ------------------------------------------------
93
+ MESSAGE
94
+
95
+ puts message
96
+ end
97
+
98
+ private
99
+
100
+ def create_migration_files
101
+ binary_ids = options['uuid'] ? true : false
102
+ time = Time.now.utc
103
+ timestamp = time.strftime('%Y%m%d%H%M%S')
104
+ migration_file_name = 'create_loggable_activities.rb'
105
+ destination = File.join('db', 'migrate', "#{timestamp}_#{migration_file_name}")
106
+ if binary_ids
107
+ # Copy binary_id migration file
108
+ template "binary_ids/#{migration_file_name}", destination
109
+ else
110
+ # Copy integer migration file
111
+ template migration_file_name, destination
112
+ end
113
+ end
114
+
115
+ # def display_help
116
+ # help_path = File.expand_path('../../../help/loggable_activity_help.txt', __dir__)
117
+ # puts '-----------------------------'
118
+ # puts help_path
119
+ # puts File.read(help_path)
120
+ # exit
121
+ # end
122
+ # Define a method to display a message after generation
35
123
  end
36
124
  end
37
125
  end
@@ -26,6 +26,67 @@ module LoggableActivity
26
26
  end
27
27
  end
28
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
+
29
90
  private
30
91
 
31
92
  def copy_files(type)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoggableActivity
4
- VERSION = '0.1.53'
4
+ VERSION = '0.1.54'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggable_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.53
4
+ version: 0.1.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Max \nGroenlund"
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-22 00:00:00.000000000 Z
11
+ date: 2024-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -207,20 +207,20 @@ files:
207
207
  - docs/js/searcher.js
208
208
  - docs/js/searcher.js.gz
209
209
  - docs/table_of_contents.html
210
+ - help/loggable_activity_help.txt
210
211
  - lib/.DS_Store
211
212
  - lib/generators/.DS_Store
212
213
  - lib/generators/loggable_activity/.DS_Store
213
214
  - lib/generators/loggable_activity/install_generator.rb
214
215
  - lib/generators/loggable_activity/install_templates_generator.rb
215
216
  - lib/generators/loggable_activity/templates/.DS_Store
217
+ - lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb
216
218
  - lib/generators/loggable_activity/templates/config/locales/loggable_activity.en.yml
217
- - lib/generators/loggable_activity/templates/config/loggable_activity.yml
219
+ - lib/generators/loggable_activity/templates/config/loggable_activity.yaml
218
220
  - lib/generators/loggable_activity/templates/create_loggable_activities.rb
219
- - lib/generators/loggable_activity/templates/create_loggable_encryption_keys.rb
220
- - lib/generators/loggable_activity/templates/create_loggable_payloads.rb
221
221
  - lib/generators/loggable_activity/templates/current_user.rb
222
222
  - lib/generators/loggable_activity/templates/helpers/loggable_activity_helper.rb
223
- - lib/generators/loggable_activity/templates/loggable_activity.en.yml
223
+ - lib/generators/loggable_activity/templates/loggable_activity.en.yaml
224
224
  - lib/generators/loggable_activity/templates/loggable_activity_helper.rb
225
225
  - lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.erb
226
226
  - lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.slim
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CreateLoggableEncryptionKeys < ActiveRecord::Migration[6.1]
4
- def change
5
- create_table :loggable_encryption_keys do |t|
6
- t.references :parent_key, foreign_key: { to_table: 'loggable_encryption_keys', on_delete: :nullify }
7
- t.string :key
8
- t.references :record, polymorphic: true, on_delete: :nullify
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CreateLoggablePayloads < ActiveRecord::Migration[6.1]
4
- def change
5
- create_table :loggable_payloads do |t|
6
- t.references :record, polymorphic: true, null: true
7
- t.json :encrypted_attrs
8
- t.integer :payload_type, default: 0
9
- t.boolean :data_owner, default: false
10
- t.references :activity, foreign_key: { to_table: 'loggable_activities', class_name: 'LoggableActivity::Activity' }
11
-
12
- t.timestamps
13
- end
14
- end
15
- end