loggable_activity 0.1.49 → 0.1.52

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: e3a71b62ddccb997e31e0592a4069f3c1684043fe5dee77691801930ebd86a43
4
- data.tar.gz: 7b8cf906c1357bbc2e90172020de8ab712132ba43de3a53fc0d4058cfa391bd8
3
+ metadata.gz: 12ed0c5c4e119f98ff329b14e762fafbac54bae7ee34e0acb68809843d437a68
4
+ data.tar.gz: 6d7fc9dc56592551e9388ad2c3762cd94c76b46b1afcc33866e8014e2c4b802b
5
5
  SHA512:
6
- metadata.gz: a951d551a83e4cab2c58ec1b6a3b00c1814ecd099bdf38682d024a99298417912f6efcaf1c1d625f8ee4f877ac60f7ab851cc9a00b2c7201fb9fba2cf1e093b1
7
- data.tar.gz: 4821fd58720ad28bd77d7f958f0c1ce39de246503b93a4027097fa61c3b5f4b4e3ca3f673f37271205a121717905f3dbb12337ad3193e40fe12f6098f69667ec
6
+ metadata.gz: 94b66bb24424af6a4905c4d658f9d443bdc9fa35d56453aca917bc645106a3d53a7ac8013482e5307cdd01543795ee2f1a2d7476cb1d2957d29e6bce28ec5229
7
+ data.tar.gz: f501c925354af941eda9ed03855307981eb3efbcd9e97852f98bece717d030c7ff4beb35c13a0cf3e22b8a28c2781c0d075f592e1be0adc5068cef2126471520
data/.rubocop.yml CHANGED
@@ -1,13 +1,18 @@
1
1
  AllCops:
2
- # TargetRubyVersion: '3.0.1'
2
+ TargetRubyVersion: '3.2.0'
3
3
  NewCops: enable
4
4
  Exclude:
5
- - 'db/schema.rb'
6
- - 'vendor/**/*'
5
+ # - 'vendor/**/*'
6
+
7
+ Style/OpenStructUse:
8
+ Enabled: false
7
9
 
8
10
  Style/Documentation:
9
11
  Enabled: false
10
12
 
13
+ Gemspec/DevelopmentDependencies:
14
+ Enabled: false
15
+
11
16
  Layout/LineLength:
12
17
  Enabled: false
13
18
 
data/CHANGELOG.md CHANGED
@@ -1,7 +1,9 @@
1
- ## [Unreleased]
2
- - nothing so far
1
+ ## [0.1.51] - 2024-02-18
2
+ - Added RSpec test
3
+ - Added rubocop
4
+
3
5
  ## [0.1.49] - 2024-02-18
4
- - Metadata, pointing to hompage
6
+ - Metadata, pointing to homepage
5
7
 
6
8
  ## [0.1.48] - 2024-02-16
7
9
  ### Breaking change
data/GETTING-STARTED.md CHANGED
@@ -65,7 +65,7 @@ class ApplicationController < ActionController::Base
65
65
  ```
66
66
  This will give us access to the current_user.
67
67
 
68
- And then we have to add this to 'config/application.rb'
68
+ And then we have to add this to `config/application.rb`
69
69
  ```
70
70
  config.loggable_activity = ActiveSupport::OrderedOptions.new
71
71
  config.loggable_activity.actor_display_name = :full_name
@@ -77,59 +77,26 @@ current_user_model: This is the name of the model we use for current_user
77
77
  load_config_file: this is the configuration file from above.
78
78
 
79
79
 
80
- ## Configuration
81
-
82
- ```
83
- User:
84
- record_display_name: full_name
85
- loggable_attrs:
86
- - first_name
87
- - last_name
88
- auto_log:
89
- - create
90
- - update
91
- - destroy
92
- relations:
93
- - belongs_to: :demo_address
94
- model: Demo::Address
95
- loggable_attrs:
96
- - street
97
- - city
98
- Demo::Address:
99
- record_display_name: full_address
100
- actor_display_name: email
101
- loggable_attrs:
102
- - street
103
- - city
104
- - country
105
- - postal_code
106
- ```
107
80
  Then you HAVE TO to add `LogggableActivity::Hooks` to the `User Model` like this
108
81
 
109
82
  ```
110
83
  class User < ApplicationRecord
111
84
  include LoggableActivity::Hooks
112
85
  ...
113
- ```
86
+ resto of your code here.
114
87
 
115
- And finally you have to add this to the `ApplicationController`
116
- ```
117
- class ApplicationController < ActionController::Base
118
- include LoggableActivity::CurrentUser
119
88
  ```
120
89
 
121
- Now if you create a model like this:
122
- ```
123
- $ rails c
124
- $ User.create(first_name: 'John', last_name: 'Doe')
125
- ```
126
90
 
127
- Then an `LoggableActivity::Activity` is created. You can inspect it from the terminal like this.
91
+ ### Log the show action
92
+ If you want to log the show action you can add this to your controllers show method
128
93
  ```
129
- puts activity = Loggable::Activity.last
130
- puts activity.attrs
94
+ def show
95
+ @user.log(:show)
131
96
  ```
132
97
 
98
+
99
+
133
100
  ## For developers
134
101
  If you want to contribute to the development and try it out in the process
135
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.
@@ -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.
@@ -66,6 +66,8 @@ module LoggableActivity
66
66
  build_payload(relation_config, 'belongs_to')
67
67
  when 'has_one'
68
68
  build_payload(relation_config, 'has_one')
69
+ when 'has_many'
70
+ build_has_many_payloads(relation_config, 'has_many')
69
71
  end
70
72
  end
71
73
  end
@@ -78,10 +80,39 @@ module LoggableActivity
78
80
  associated_record = send(relation_config[relation_type])
79
81
  return nil if associated_record.nil?
80
82
 
81
- associated_loggable_attrs = relation_config['loggable_attrs']
83
+ build_associated_payload(associated_record, relation_config)
82
84
 
83
- encryption_key = associated_record_encryption_key(associated_record, relation_config['data_owner'])
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
+ end
84
103
 
104
+ def build_has_many_payloads(relation_config, relation_type)
105
+ associated_records = send(relation_config[relation_type])
106
+ return nil if associated_records.empty?
107
+
108
+ associated_records.each do |associated_record|
109
+ build_associated_payload(associated_record, relation_config)
110
+ end
111
+ end
112
+
113
+ def build_associated_payload(associated_record, relation_config)
114
+ associated_loggable_attrs = relation_config['loggable_attrs']
115
+ encryption_key = associated_record_encryption_key(associated_record, relation_config['data_owner'])
85
116
  encrypted_attrs =
86
117
  encrypt_attrs(
87
118
  associated_record.attributes,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoggableActivity
4
- VERSION = '0.1.49'
4
+ VERSION = '0.1.52'
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.49
4
+ version: 0.1.52
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-18 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,108 @@ 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: 7.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 7.1.2
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: '6.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 6.1.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '6.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 6.1.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: generator_spec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.10.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.10.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 1.4.2
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.4.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: factory_bot
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '6.4'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 6.4.6
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '6.4'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 6.4.6
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.60'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 1.60.2
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.60'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 1.60.2
27
129
  description: |2
28
130
  LoggableActivity is a powerful gem for Ruby on Rails that provides seamless user activity logging
29
131
  prepared for GDPR compliance and supporting record relations. It allows you to effortlessly
@@ -147,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
249
  requirements:
148
250
  - - ">="
149
251
  - !ruby/object:Gem::Version
150
- version: '3.2'
252
+ version: 3.2.0
151
253
  required_rubygems_version: !ruby/object:Gem::Requirement
152
254
  requirements:
153
255
  - - ">="