loggable_activity 0.1.48 → 0.1.51

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee3e20a374ac054a343ce5ff1c35c5fcce765fb631788fb6d9b738e52161a16a
4
- data.tar.gz: 042cc1db90cf6b99eeb2c8d5ab3f16a5473178c00085f42400c4eec344a99731
3
+ metadata.gz: 562b5492910176c8bc5816b7f5691ae386c015d1a969b71a33c45f708383c185
4
+ data.tar.gz: 577534f63904b76ac414d1dba76aac35725892b127a3f268de650eeb4ed4629e
5
5
  SHA512:
6
- metadata.gz: 1f4063eb4cd98a16061d151759735e0b5cc98e7747151dc2c56856f2010f23936c2c338991c5cc85dfd3c72af4f60133a4e39271f29ec76e5ee04383ad6dd073
7
- data.tar.gz: 8be57a52cfd948825e273648ffaec5809975dc14863f49206ee8f364f07b58a193758d80d867155f21760522a24bc2cf49d183ba757c503af1fdf51317b78202
6
+ metadata.gz: 631979df293ae2f1e03125b0a900c7eb432a59f163b0ab1c3a2c7e559d5e9e75f33e7fb0f686fece6f80888264f5b703719bfe7c2d6069a2a49512424414d913
7
+ data.tar.gz: 749dd6e36b9017f5c6b92572b1a9bf47e4c0e8fbe418d0d38e6ab0cd51553ccd64fa92f286ed45bc9e39d7a4dab2e5d74517093da6772578b82044379f53048d
data/.rubocop.yml CHANGED
@@ -1,13 +1,16 @@
1
1
  AllCops:
2
- # TargetRubyVersion: '3.0.1'
2
+ TargetRubyVersion: '3.2.0'
3
3
  NewCops: enable
4
4
  Exclude:
5
5
  - 'db/schema.rb'
6
- - 'vendor/**/*'
6
+ # - 'vendor/**/*'
7
7
 
8
8
  Style/Documentation:
9
9
  Enabled: false
10
10
 
11
+ Gemspec/DevelopmentDependencies:
12
+ Enabled: false
13
+
11
14
  Layout/LineLength:
12
15
  Enabled: false
13
16
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
- ## [Unreleased]
2
- - nothing so far
1
+ ## [0.1.51] - 2024-02-18
2
+ - Added RSpec test
3
+ - Added rubocop
4
+
5
+ ## [0.1.49] - 2024-02-18
6
+ - Metadata, pointing to homepage
3
7
 
4
8
  ## [0.1.48] - 2024-02-16
5
9
  ### Breaking change
@@ -7,14 +11,19 @@
7
11
  - Updated README.md
8
12
  - Updated GETTING_STARTED.md
9
13
  - Added PULL_REQUEST_TEMPLATE.md
14
+
10
15
  ## [0.1.46] - 2024-02-16
11
16
  - Fixed spelling error in EncryptionKey
17
+
12
18
  ## [0.1.43] - 2024-02-15
13
19
  - Updated README.md and GETTING-STARTED.md
20
+
14
21
  ## [0.1.39] - 2024-02-12
15
22
  - Updated README.md and GETTING-STARTED.md
23
+
16
24
  ## [0.1.38] - 2024-02-12
17
25
  - Removed dependency on awesome print
26
+
18
27
  ## [0.1.35] - 2024-02-11
19
28
  - Initial release
20
29
 
data/GETTING-STARTED.md CHANGED
@@ -8,77 +8,95 @@ This document should you getting started with `LoggableActivity`
8
8
  ## Demo Application
9
9
  You can download a demo application from<br/>
10
10
  [https://github.com/maxgronlund/LoggableActivityDemoApp](https://github.com/maxgronlund/LoggableActivityDemoApp)
11
+ <br/>
12
+ You can try a demo here<br/>
13
+ [https://loggableactivity-efe7b931c886.herokuapp.com/](https://loggableactivity-efe7b931c886.herokuapp.com/)
14
+
15
+ ## Getting started
16
+ First we add the loggable_activity gem to the Gemfile `gem 'loggable_activity', '~> x.x.xx'` and then `$ bundle install`<br/>
17
+ Then we have to generate some migrations and additionals files<br/>
18
+ `rails generate loggable_activity:install Activity`<br/>
11
19
 
12
20
  ## Configuration
13
- First you have to create a configuration file named `loggable_activity.yml` and locate it in the config folder.<br/>
14
- It has the following tags
15
- - `User` (example)<br>
16
- This is the name of the model you are configuring, as you can see there is alos a `Demo::Address` in the configuration file below, So if you have a model named `Demo::Club` you have to create at tag for that and fill in the other tags under that.
17
- - record_display_name: <br>
18
- Used to display something human to identify a given log entry, in this example the **User** model has a method named `full_name`
19
-
20
- - loggable_attrs:<br/>
21
- This are the attributes on a model and reflect the fields in the database you HAS to define, what fields to log.
22
-
23
- - auto_log:<br/>
24
- This are the actions that will be logged automatically, although you can log manually at any time.
25
- Note there is no hook for `Show` in Rails so you would have to log that manually like this `log(:show)`, more about that later.
26
-
27
- - relations:<br/>
28
- If a model has `belongs_to` and `has_one` relations you can log them automatically as well<br>
29
- <br/>
30
- *Example confuguration for logging of the user model*
21
+ You need a configuration file inside the `config/loggable_activity.yaml`
22
+ This file defines:
23
+ - What tables to log
24
+ - What fields in a table to log
25
+ - How data is aggregated.
26
+ - What should happen to the aggregation if a record is deleted.
27
+ - What actions to log.
28
+
29
+ *Here is an example*
31
30
  ```
32
- User:
33
- record_display_name: full_name
31
+ Demo::Club:
32
+ record_display_name: name
34
33
  loggable_attrs:
35
- - first_name
36
- - last_name
34
+ - name
37
35
  auto_log:
38
36
  - create
39
37
  - update
40
38
  - destroy
41
39
  relations:
42
- - belongs_to: :demo_address
40
+ - belongs_to: :address
43
41
  model: Demo::Address
44
42
  loggable_attrs:
45
43
  - street
46
44
  - city
47
- Demo::Address:
48
- record_display_name: full_address
49
- actor_display_name: email
50
- loggable_attrs:
51
- - street
52
- - city
53
- - country
54
- - postal_code
55
45
  ```
56
- Then you HAVE TO to add `LogggableActivity::Hooks` to the `User Model` like this
46
+
47
+ Lets break this down.
48
+ - First we can se that we are logging a model named Demo::Club.
49
+ - `record_display_name:` is the field/method on the on the model we want to display as a headline in the log
50
+ - Then we can se that we are logging the **name** of the club, in this example that's all there is to log.
51
+ - Then we can se that we are **logging create, update, and destroy** automatically.
52
+ - Then there are some relations: that we want to collect and add to the log, in this example we are logging the address as well.
53
+
54
+ Next we have to include some hooks to the model we want to log.
57
55
 
58
56
  ```
59
57
  class User < ApplicationRecord
60
58
  include LoggableActivity::Hooks
61
- ...
62
59
  ```
63
60
 
64
- And finally you have to add this to the `ApplicationController`
61
+ And then we have to add a this to the application_controller.rb
65
62
  ```
66
63
  class ApplicationController < ActionController::Base
67
64
  include LoggableActivity::CurrentUser
68
65
  ```
66
+ This will give us access to the current_user.
69
67
 
70
- Now if you create a model like this:
68
+ And then we have to add this to `config/application.rb`
71
69
  ```
72
- $ rails c
73
- $ User.create(first_name: 'John', last_name: 'Doe')
70
+ config.loggable_activity = ActiveSupport::OrderedOptions.new
71
+ config.loggable_activity.actor_display_name = :full_name
72
+ config.loggable_activity.current_user_model_name = 'User'
73
+ LoggableActivity::Configuration.load_config_file('config/loggable_activity.yaml')
74
74
  ```
75
+ actor_display_name: this is a method on the User model we want to use when presenting the actor.
76
+ current_user_model: This is the name of the model we use for current_user
77
+ load_config_file: this is the configuration file from above.
78
+
79
+
80
+ Then you HAVE TO to add `LogggableActivity::Hooks` to the `User Model` like this
75
81
 
76
- Then an `LoggableActivity::Activity` is created. You can inspect it from the terminal like this.
77
82
  ```
78
- puts activity = Loggable::Activity.last
79
- puts activity.attrs
83
+ class User < ApplicationRecord
84
+ include LoggableActivity::Hooks
85
+ ...
86
+ resto of your code here.
87
+
88
+ ```
89
+
90
+
91
+ ### Log the show action
92
+ If you want to log the show action you can add this to your controllers show method
93
+ ```
94
+ def show
95
+ @user.log(:show)
80
96
  ```
81
97
 
98
+
99
+
82
100
  ## For developers
83
101
  If you want to contribute to the development and try it out in the process
84
102
  - 1 Down the demo project from [demo project on github](https://github.com/maxgronlund/LoggableActivityDemoApp)
data/README.md CHANGED
@@ -20,14 +20,14 @@ Most organizations needs to keep a log of how users interact with data stored in
20
20
 
21
21
  *Super simplified example from the healthcare.*
22
22
  - Each patient has a journal, that is updated on a regular basis.
23
- - Supervisor needs to follow the journal, how was it updated, who read it.
23
+ - Supervisor needs to follow the journal, how was it updated, who read it, did it get deleted.
24
24
  - Security personnel needs to know how the journal is handled, who did what when.
25
- - Patients has the right to know how their journal is handled and that the log is deleted.
25
+ - Patients has the right to know how their journal is handled and that their data will be removed when required.
26
26
 
27
27
  Beside the journal in the db, an activity log is kept so it is possible to track how the journal is used.<br/>
28
28
  At some point in time the patients data from the DB and the activity log has to be removed according to GDPR.<br/>
29
29
 
30
-
30
+ ### Contribute
31
31
  👉 Join the Slack channel here: [LoggableActivity Slack Workspace](https://join.slack.com/t/loggableactivity/shared_invite/zt-2a3tvgv37-mGwjHJTrBXBH2srXFRRSXQ)
32
32
  <br/>
33
33
  👉 Want to play around with an online version: [Show Demo](https://loggableactivity-efe7b931c886.herokuapp.com/)
@@ -35,3 +35,6 @@ At some point in time the patients data from the DB and the activity log has to
35
35
  We value each contribution and believe in the power of community. Looking forward to seeing you there!
36
36
 
37
37
 
38
+ ### Test
39
+ We embrace the philosophy of black-box testing, where we focus on the input and output of the public interface without worrying about internal implementation details.<br/>
40
+ This approach aligns with the principle of testing behavior rather than implementation.
@@ -25,6 +25,7 @@ module LoggableActivity
25
25
  template 'loggable_activity.en.yml', 'config/locales/loggable_activity.en.yml'
26
26
  template 'loggable_activity.yml', 'config/loggable_activity.yml'
27
27
  template 'current_user.rb', 'app/controllers/concerns/loggable_activity/current_user.rb'
28
+ # template 'loggable_activity_helper.rb', 'app/helpers/loggable_activity_helper.rb'
28
29
  end
29
30
  end
30
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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record'
4
+
3
5
  module LoggableActivity
4
6
  # Represents one action in the activity log.
5
7
  class Activity < ActiveRecord::Base
@@ -224,6 +226,13 @@ module LoggableActivity
224
226
  .limit(limit)
225
227
  end
226
228
 
229
+ # Returns the last activity.
230
+ def self.last(limit = 1)
231
+ return latest(1).first if limit == 1
232
+
233
+ latest(limit)
234
+ end
235
+
227
236
  private
228
237
 
229
238
  def update_attrs
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record'
4
+
3
5
  module LoggableActivity
4
6
  # This class represents the encryption key used to unlock the data for one payload.
5
7
  # When deleted, only the encryption_key field is deleted.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/concern'
4
+
3
5
  # This is the main module for loggable.
4
6
  # When included to a model, it provides the features for creating the activities.
5
7
  require 'loggable_activity/payloads_builder'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record'
4
+
3
5
  module LoggableActivity
4
6
  # This class represents a payload in the log, containing encrypted data of one record in the database.
5
7
  # When the record is deleted, the encryption key for the payload is also deleted.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoggableActivity
4
- VERSION = '0.1.48'
4
+ VERSION = '0.1.51'
5
5
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require 'rails'
4
-
3
+ require_relative 'loggable_activity/version'
5
4
  require_relative 'loggable_activity/activity'
6
5
  require_relative 'loggable_activity/configuration'
7
6
  require_relative 'loggable_activity/encryption'
@@ -10,7 +9,6 @@ require_relative 'loggable_activity/hooks'
10
9
  require_relative 'loggable_activity/payload'
11
10
  require_relative 'loggable_activity/payloads_builder'
12
11
  require_relative 'loggable_activity/update_payloads_builder'
13
- require_relative 'loggable_activity/version'
14
12
 
15
13
  module LoggableActivity
16
14
  class Error < StandardError; 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.48
4
+ version: 0.1.51
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-16 00:00:00.000000000 Z
11
+ date: 2024-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,102 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: generator_spec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.4.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '6.4'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 6.4.6
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '6.4'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 6.4.6
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.60'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.60.2
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.60'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.60.2
27
123
  description: |2
28
124
  LoggableActivity is a powerful gem for Ruby on Rails that provides seamless user activity logging
29
125
  prepared for GDPR compliance and supporting record relations. It allows you to effortlessly
@@ -116,6 +212,7 @@ files:
116
212
  - lib/generators/loggable_activity/templates/current_user.rb
117
213
  - lib/generators/loggable_activity/templates/loggable_activity.en.yml
118
214
  - lib/generators/loggable_activity/templates/loggable_activity.yml
215
+ - lib/generators/loggable_activity/templates/loggable_activity_helper.rb
119
216
  - lib/loggable_activity.rb
120
217
  - lib/loggable_activity/.DS_Store
121
218
  - lib/loggable_activity/activity.rb
@@ -133,6 +230,9 @@ homepage: https://loggableactivity-efe7b931c886.herokuapp.com/
133
230
  licenses:
134
231
  - MIT
135
232
  metadata:
233
+ homepage_uri: https://loggableactivity-efe7b931c886.herokuapp.com/
234
+ source_code_uri: https://github.com/maxgronlund/LoggableActivity
235
+ changelog_uri: https://github.com/maxgronlund/LoggableActivity/CHANGELOG.md
136
236
  documentation_uri: https://maxgronlund.github.io/LoggableActivity/
137
237
  rubygems_mfa_required: 'true'
138
238
  post_install_message:
@@ -143,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
243
  requirements:
144
244
  - - ">="
145
245
  - !ruby/object:Gem::Version
146
- version: '3.2'
246
+ version: 3.2.0
147
247
  required_rubygems_version: !ruby/object:Gem::Requirement
148
248
  requirements:
149
249
  - - ">="