protected_record 0.0.2 → 0.0.3
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba5e182fe0caec23566af06a804659fd64927ce
|
4
|
+
data.tar.gz: dd283cab9d1fef2b38b4468acc7c57f332b4af76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c8a5c244a1ca72eb8a70e9c4afe89664ff1307e5db0832192fd39faea382efd305bb6ce8d08d81bd00fd5273dbe4732d9942c12d37c7041aa9035c678c5dcb2
|
7
|
+
data.tar.gz: a609d10024a34d026e45203bf85179d2b188e4d3ddeb9a8595eea7dc6f0532f8cfb2db972f37eab1c3e4643e7c1a65db2da41f255e244e190e4b711dba91ea19
|
data/README.md
CHANGED
@@ -1,47 +1,67 @@
|
|
1
1
|
# protected_record
|
2
|
-
##
|
3
|
-
|
4
|
-
If any changes are allowed through the filter, protected_record will create a ProtectedRecord::ChangeLog::Record to log who changed what, and for which record.
|
5
|
-
ProtectedRecord is opt-in only. In order to update with protection, use the following:
|
2
|
+
## Setup for rails applications
|
3
|
+
I've created an engine to provide the necessary migrations as well as a basic interface for traiging change requests. You are free to use this gem without the engine, but you'll need to visit [protected_record_manager](https://github.com/rthbound/protected_record_manager/tree/master/db/migrate) and copy the migrations into your app manually.
|
6
4
|
|
7
|
-
|
8
|
-
params: visit_params,
|
9
|
-
protected_record: @patient_visit,
|
10
|
-
user: current_user,
|
11
|
-
protected_keys: %w{ visit_date do_not_resuscitate }
|
12
|
-
}).execute!
|
5
|
+
Add to your Rails application's Gemfile:
|
13
6
|
|
7
|
+
gem "protected_record_manager"
|
8
|
+
|
9
|
+
And to your Rails application's `routes.rb`:
|
10
|
+
```ruby
|
11
|
+
mount ProtectedRecordManager::Engine, :at => "/protected_record_manager", as: "protected_record_manager"
|
12
|
+
```
|
13
|
+
Which will provide a user interface for triaging change requests at:
|
14
|
+
```
|
15
|
+
http://localhost:3000/protected_record_manager/change_requests
|
16
|
+
```
|
17
|
+
**Important:** Only users with `@user.protected_record_manager == true` will be able to access these resources.
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
and include in your user model:
|
19
|
+
Now copy over and run the migrations:
|
20
|
+
```
|
21
|
+
$ rake protected_record_manager:install:migrations
|
22
|
+
$ rake db:migrate
|
23
|
+
```
|
24
|
+
Lastly, you'll need to prepare your models. There's two types of models at play here:
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
1. User (for now I expect a `User` class and `current_user` method
|
27
|
+
2. records .. these are the models you want to track
|
26
28
|
|
27
|
-
|
29
|
+
So in `user.rb`
|
30
|
+
```ruby
|
31
|
+
include ProtectedRecord::ChangeRequest::Changer
|
32
|
+
include ProtectedRecord::ChangeLog::Changer
|
33
|
+
```
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
And in any model where you want to use protection:
|
36
|
+
```ruby
|
37
|
+
include ProtectedRecord::ChangeRequest::Changeling
|
38
|
+
include ProtectedRecord::ChangeLog::Changeling
|
39
|
+
```
|
40
|
+
## Usage
|
41
|
+
1. protected_record will prevent changes to attributes you specify as protected.
|
42
|
+
2. Any attempted change will be logged as a `ProtectedRecord::ChangeRequest::Record`.
|
43
|
+
3. If any changes are allowed through the filter, protected_record will create a `ProtectedRecord::ChangeLog::Record` to log who changed what, and for which record.
|
44
|
+
4. **Important**: ProtectedRecord is opt-in only. It does not change the way behavior of any AR methods, nor does it use any callbacks. In order to update with protection, use the following:
|
34
45
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
```ruby
|
47
|
+
result = ProtectedRecord::UseCase::Update.new({
|
48
|
+
params: record_params,
|
49
|
+
protected_record: @record,
|
50
|
+
user: current_user,
|
51
|
+
protected_keys: %w{ do_not_resuscitate organ_donor }
|
52
|
+
}).execute!
|
41
53
|
|
42
|
-
|
54
|
+
# UseCase module will filter changes to protected_keys,
|
55
|
+
# creating a "change request" rather than applying changes
|
43
56
|
|
57
|
+
# UseCase module will allow other changes to be applied,
|
58
|
+
# creating a "change log" entry for the observed changes
|
59
|
+
update_result.successful? #=> true
|
60
|
+
```
|
44
61
|
and call methods like
|
45
|
-
|
46
|
-
|
47
|
-
|
62
|
+
```ruby
|
63
|
+
@user.change_log_records
|
64
|
+
@user.change_request_records
|
65
|
+
@record.change_log_records
|
66
|
+
@record.change_request_records
|
67
|
+
```
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protected_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tad Hosford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pay_dirt
|