loggable_activity 0.1.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rspec +3 -0
- data/.rspec_status +0 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONSIDERTIONS.md +129 -0
- data/GETTING-STARTED.md +80 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/ROADMAP.md +19 -0
- data/Rakefile +8 -0
- data/lib/.DS_Store +0 -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 +30 -0
- data/lib/generators/loggable_activity/templates/.DS_Store +0 -0
- data/lib/generators/loggable_activity/templates/create_loggable_activities.rb +15 -0
- data/lib/generators/loggable_activity/templates/create_loggable_encryption_keys.rb +11 -0
- data/lib/generators/loggable_activity/templates/create_loggable_payloads.rb +15 -0
- data/lib/generators/loggable_activity/templates/current_user.rb +26 -0
- data/lib/generators/loggable_activity/templates/loggable_activity.en.yml +36 -0
- data/lib/loggable_activity/.DS_Store +0 -0
- data/lib/loggable_activity/activity.rb +124 -0
- data/lib/loggable_activity/configuration.rb +13 -0
- data/lib/loggable_activity/encryption.rb +43 -0
- data/lib/loggable_activity/encryption_key.rb +46 -0
- data/lib/loggable_activity/hooks.rb +152 -0
- data/lib/loggable_activity/payload.rb +71 -0
- data/lib/loggable_activity/payloads_builder.rb +89 -0
- data/lib/loggable_activity/update_payloads_builder.rb +99 -0
- data/lib/loggable_activity/version.rb +5 -0
- data/lib/loggable_activity.rb +18 -0
- data/loggable_activity-0.1.32.gem +0 -0
- data/loggable_activity-0.1.33.gem +0 -0
- data/loggable_activity-0.1.34.gem +0 -0
- data/pkg/loggable_activity-0.1.35.gem +0 -0
- data/sig/loggable_activity.rbs +4 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9e732145f0c4b463a0db97b8551841222d966031d54a067dad138bf98c8c816
|
4
|
+
data.tar.gz: 566d8116f055d33d2215aee961680fe0b6d40180bb017cb9a30ae34b283cd6c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c510effb9e4655f7225d4b8b22dec05ccd0caa9eb94668ca3d31f371feab7ddd2594b1a2106585e9e915e7fe03b08d8e856183502765d236f73f51a94f2fa77
|
7
|
+
data.tar.gz: 8e798121e6f6c1813e7cbdad45ea1f6bf71893140449eb4599aa200a8117768eb1fa03ef89a1f2400bd9f43c9d45e254c648144ce6e6cfb4d2b3ecefedeeb2ee
|
data/.DS_Store
ADDED
Binary file
|
data/.rspec
ADDED
data/.rspec_status
ADDED
File without changes
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
# TargetRubyVersion: '3.0.1'
|
3
|
+
NewCops: enable
|
4
|
+
Exclude:
|
5
|
+
- 'db/schema.rb'
|
6
|
+
- 'vendor/**/*'
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Layout/LineLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/CyclomaticComplexity:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/IfUnlessModifier:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/PerceivedComplexity:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Metrics/ModuleLength:
|
30
|
+
Exclude:
|
31
|
+
# - lib/loggable_activity/hooks.rb
|
32
|
+
Metrics/AbcSize:
|
33
|
+
Exclude:
|
34
|
+
- lib/loggable_activity/encryption.rb
|
35
|
+
- lib/loggable_activity/update_payloads_builder.rb
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at max@synthmax.dk. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/CONSIDERTIONS.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Considerations, Work in progress.
|
2
|
+
This document is stored here and might deleted<br/>
|
3
|
+
<br/>
|
4
|
+
It should be easy to configure and use the *LoggablActivity* without having to collect and format data all over the system.<br/>
|
5
|
+
It should also be possible to delete a data owner and then all data related to that data owner should be inaccessible.
|
6
|
+
|
7
|
+
|
8
|
+
### Protection of data that belongs to a data owner
|
9
|
+
One way to protect data in a field is to encrypt it, when requested it can then be decrypted.<br/>
|
10
|
+
If the data is required permanently deleted all there is to do is to throw away the key.<br/>
|
11
|
+
Another way is to delete the content in all fields for a given data owner on request.<br/>
|
12
|
+
|
13
|
+
### Composition of data in a log entry
|
14
|
+
Lets consider an example with a user, the user has som personal information directly on the users DB Record.
|
15
|
+
The user also has a relation to an address and the user might have a couple relations to other users, friends family members etc.<br/>
|
16
|
+
All this is created from one form and when it is submitted we want to log it.
|
17
|
+
One way of do it is to collect all the data from the DB and pack it into a json payload and submit it to the log, but then we have no control of<br/>
|
18
|
+
What data is confidential and who it belongs to. So instead lets make some configurations for how data are handled.
|
19
|
+
<br/>*Example*
|
20
|
+
```
|
21
|
+
┌──────────────────────┐ ┌──────────────────────┐
|
22
|
+
│ User │ ┌──▶│ Address │
|
23
|
+
├──────────────────────┤ │ ├──────────────────────┤
|
24
|
+
│name: String │ │ │street: String │
|
25
|
+
├──────────────────────┤ │ ├──────────────────────┤
|
26
|
+
│date_of_birth: Date │ │ │city: String │
|
27
|
+
├──────────────────────┤ │ └──────────────────────┘
|
28
|
+
│address_id: Reference │──┘
|
29
|
+
├──────────────────────┤
|
30
|
+
│system_task_uuid: UUID│
|
31
|
+
└──────────────────────┘
|
32
|
+
┼
|
33
|
+
│
|
34
|
+
╱│╲
|
35
|
+
┌──────────────────────┐
|
36
|
+
│ Friend │
|
37
|
+
├──────────────────────┤
|
38
|
+
│user_a_id: Reference │
|
39
|
+
├──────────────────────┤
|
40
|
+
│user_b_id: Reference │
|
41
|
+
└──────────────────────┘
|
42
|
+
```
|
43
|
+
Then a payload could look like this
|
44
|
+
```
|
45
|
+
|
46
|
+
{
|
47
|
+
user: {
|
48
|
+
name: Sting
|
49
|
+
date_of_birth "October 2, 1951"
|
50
|
+
address: {
|
51
|
+
street: "some street",
|
52
|
+
city: "London"
|
53
|
+
},
|
54
|
+
friend: [
|
55
|
+
user: {
|
56
|
+
name: "Bob"
|
57
|
+
date_of_birth: "September 01, 1991
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
63
|
+
But what about Bob, he is in the system and want to have control of his own data.<br/>
|
64
|
+
To achieve this we need to organize the way we store log entries so owners can be identified even within a payload.
|
65
|
+
```
|
66
|
+
┌────────────────────────┐
|
67
|
+
│ Activity │
|
68
|
+
├────────────────────────┤
|
69
|
+
│key: String │
|
70
|
+
├────────────────────────┤
|
71
|
+
│who_did_it_type: String │
|
72
|
+
├────────────────────────┤
|
73
|
+
│who_did_it_id: UUID │
|
74
|
+
├────────────────────────┤
|
75
|
+
│time: DateTime │
|
76
|
+
└────────────────────────┘
|
77
|
+
┼
|
78
|
+
│
|
79
|
+
│
|
80
|
+
╱│╲
|
81
|
+
┌────────────────────────┐
|
82
|
+
│ Payload │
|
83
|
+
├────────────────────────┤
|
84
|
+
│data: Json │
|
85
|
+
├────────────────────────┤
|
86
|
+
│record_id: UUID │
|
87
|
+
├────────────────────────┤
|
88
|
+
│record_type: String │
|
89
|
+
└────────────────────────┘
|
90
|
+
```
|
91
|
+
So now we can control access to Bobs data in the Logging DB
|
92
|
+
|
93
|
+
### example of how a `Loggable::Activity` is formatted for the view
|
94
|
+
```
|
95
|
+
activity = Loggable::Activity.lastest.last
|
96
|
+
activity.attrs ==>
|
97
|
+
|
98
|
+
payloads: [
|
99
|
+
primary: {
|
100
|
+
name: "User",
|
101
|
+
changes: {
|
102
|
+
attrs: {
|
103
|
+
first_name: {
|
104
|
+
from: "Bob",
|
105
|
+
to: "Rob"
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
relations: [
|
111
|
+
name: "Demo::Address
|
112
|
+
changes: {
|
113
|
+
street: {
|
114
|
+
from: "5th Avenue",
|
115
|
+
to: "Broadway"
|
116
|
+
}
|
117
|
+
}
|
118
|
+
]
|
119
|
+
]
|
120
|
+
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
data/GETTING-STARTED.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Getting started
|
2
|
+
This document should you getting started with `LoggableActivity`
|
3
|
+
|
4
|
+
## Prerequisite
|
5
|
+
1 A running Rails Application<br/>
|
6
|
+
2 An authorization system where there is a current available.
|
7
|
+
|
8
|
+
## Demo Application
|
9
|
+
You can download a demo application from<br/>
|
10
|
+
[https://github.com/maxgronlund/LoggableActivityDemoApp](https://github.com/maxgronlund/LoggableActivityDemoApp)
|
11
|
+
|
12
|
+
## 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
|
+
- record_display_name: <br>
|
16
|
+
You CAN define a method on the **User** model called full name, this will be a part of the json payload related to the **User** model
|
17
|
+
|
18
|
+
- loggable_attrs:<br/>
|
19
|
+
This are the fields in the database you HAS to define
|
20
|
+
|
21
|
+
- auto_log:<br/>
|
22
|
+
This are the actions that will be logged automatically, although you can log manually at any time.
|
23
|
+
Note there is no hook for `Show` in Rails so you would have to log that manually like this `log(:how)`, more about that later.
|
24
|
+
|
25
|
+
- relations:<br/>
|
26
|
+
If a model has `belongs_to` and `has_one` relations you can log them as well<br>
|
27
|
+
<br/>
|
28
|
+
*Example confuguration for logging of the user model*
|
29
|
+
```
|
30
|
+
User:
|
31
|
+
record_display_name: full_name
|
32
|
+
loggable_attrs:
|
33
|
+
- first_name
|
34
|
+
- last_name
|
35
|
+
auto_log:
|
36
|
+
- create
|
37
|
+
- update
|
38
|
+
- destroy
|
39
|
+
relations:
|
40
|
+
- belongs_to: :demo_address
|
41
|
+
model: Demo::Address
|
42
|
+
loggable_attrs:
|
43
|
+
- street
|
44
|
+
- city
|
45
|
+
Demo::Address:
|
46
|
+
record_display_name: full_address
|
47
|
+
actor_display_name: email
|
48
|
+
loggable_attrs:
|
49
|
+
- street
|
50
|
+
- city
|
51
|
+
- country
|
52
|
+
- postal_code
|
53
|
+
```
|
54
|
+
Then you HAVE TO to add `LogggableActivity::Hooks` to the `User Model` like this
|
55
|
+
|
56
|
+
```
|
57
|
+
class User < ApplicationRecord
|
58
|
+
include LoggableActivity::Hooks
|
59
|
+
...
|
60
|
+
```
|
61
|
+
|
62
|
+
And finally you have to add this to the `ApplicationController`
|
63
|
+
```
|
64
|
+
class ApplicationController < ActionController::Base
|
65
|
+
include LoggableActivity::CurrentUser
|
66
|
+
```
|
67
|
+
|
68
|
+
Now when you create a model like this:
|
69
|
+
```
|
70
|
+
$ rails c
|
71
|
+
$ User.create(first_name: 'John', last_name: 'Doe')
|
72
|
+
```
|
73
|
+
|
74
|
+
Then an `LoggableActivity::Activity` is created. You can inspect it from the terminal like this.
|
75
|
+
```
|
76
|
+
puts activity = Loggable::Activity.all.latest.first
|
77
|
+
puts activity.activity_type
|
78
|
+
puts activity.payloads
|
79
|
+
puts activity.payload_attrs
|
80
|
+
```
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Max Groenlund
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Loggable Activity 🌟
|
2
|
+
- Keep an activity log of how data in the db are handled.
|
3
|
+
- Protect and secure the privacy of data stored in Activity Logs
|
4
|
+
- Prepare for General Data Protection Regulation (GDPR) compliance.
|
5
|
+
- Handles activities that involves more than one table in the DB.
|
6
|
+
|
7
|
+
### What it is not
|
8
|
+
- An error logging system
|
9
|
+
- A paper trails system with rollback.
|
10
|
+
|
11
|
+
### Applications
|
12
|
+
Most organizations needs to keep a log of how users interact with data stored in the DB
|
13
|
+
- Finance
|
14
|
+
- Healthcare
|
15
|
+
- Sales
|
16
|
+
- Organizations
|
17
|
+
|
18
|
+
*Super simplified example from the healthcare.*
|
19
|
+
- Each patient has a journal, that is updated on a regular basis.
|
20
|
+
- Supervisor needs to follow the journal.
|
21
|
+
- Security personnel needs to know how the journal is handled, who did what when.
|
22
|
+
- Patients has the right to their journal.
|
23
|
+
|
24
|
+
Beside the journal in the db, an activity log is kept so it is possible to track how the journal is used.<br/>
|
25
|
+
At some point in time the patients data from the DB and the activity log has to be removed according to GDPR.<br/>
|
26
|
+
|
27
|
+
|
28
|
+
👉 Join the Slack channel here: [LoggableActivity Slack Workspace](https://join.slack.com/t/loggableactivity/shared_invite/zt-2a3tvgv37-mGwjHJTrBXBH2srXFRRSXQ)
|
29
|
+
|
30
|
+
We value each contribution and believe in the power of community. Looking forward to seeing you there!
|
31
|
+
|
32
|
+
|
data/ROADMAP.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Roadmap
|
2
|
+
Outline of steps to get the LoggableActivity adapted.
|
3
|
+
|
4
|
+
### RD project
|
5
|
+
Nothing is better than gain som experience by getting som real world tests and experiences
|
6
|
+
|
7
|
+
### Open Source
|
8
|
+
More eyes and brains on the project wil make it mature and better.
|
9
|
+
|
10
|
+
### Investigations
|
11
|
+
- Does there exists a protocol for activity logging
|
12
|
+
- Will a bigger company like platformatec sponsor the project
|
13
|
+
- Legal approval, official, medical approval.
|
14
|
+
- RFC for protocol
|
15
|
+
- Commercial potentials, business models.
|
16
|
+
- Explainers
|
17
|
+
- Hosting of example project.
|
18
|
+
- Homepage.
|
19
|
+
- Documentation
|
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
require 'rails/generators/named_base'
|
5
|
+
|
6
|
+
module LoggableActivity
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::NamedBase
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
10
|
+
|
11
|
+
FILE_NAMES = %w[activity payload encryption_key].freeze
|
12
|
+
TIME = Time.now
|
13
|
+
|
14
|
+
def create_migration
|
15
|
+
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}")
|
20
|
+
template migration_file_name, destination
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_model_file
|
25
|
+
template 'loggable_activity.en.yml', 'config/locales/loggable_activity.en.yml'
|
26
|
+
template "current_user.rb", 'app/controllers/concerns/loggable_activity/current_user.rb'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateLoggableActivities < ActiveRecord::Migration[6.1]
|
4
|
+
def change
|
5
|
+
create_table :loggable_activities do |t|
|
6
|
+
t.string :action
|
7
|
+
t.references :actor, polymorphic: true, null: true
|
8
|
+
t.string :encrypted_actor_display_name
|
9
|
+
t.string :encrypted_record_display_name
|
10
|
+
t.references :record, polymorphic: true, null: true
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
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 :parrent_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
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Stores current user in a thread variable so that is can be accessed from the 'models/conserns/loggable/activities.rb' file.
|
4
|
+
module LoggableActivity
|
5
|
+
module CurrentUser
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_action :set_current_user
|
10
|
+
after_action :clear_current_user
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_current_user
|
16
|
+
# return if request.path == "/users/sign_out"
|
17
|
+
return unless current_user
|
18
|
+
|
19
|
+
Thread.current[:current_user] = current_user
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear_current_user
|
23
|
+
Thread.current[:current_user] = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
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
|
Binary file
|