approval2 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDljMWE3ODNiZjFjMzJhODEyN2MwZDRiYTQ1ZWUxM2IxNzZkZmY4MA==
4
+ YzM2YjVmY2EwOTRlOTk1MmQ3ZGQ4NTRhYzU5N2ZlNTUwOWM4NmNiMw==
5
5
  data.tar.gz: !binary |-
6
- YzYxODYyNjBlNmJkZWM5MDc4MmRmMDc3YmZiZjhiY2FjZjEyMWMzOA==
6
+ NGIxYTM1NDY5ZGRmNmE0MDc2MzNjYzJkNzhhMTJmOWI0MTlmOWFhMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODE3M2FlNDMzMTM0YzU2NGQ0NGQwZTUyYTVhZTMzODdhZTkzODM0N2MzY2E3
10
- OWMxYmFmZGY2NzcwNTJhNDY3ZWMwYjNjZjY5MGE4OTI5MTdjY2Y3ZmRiYjJj
11
- MTI4MTUxZTkxYjE5ODcyOWU5ZGFmZjQzNTA2ZTI4OGQyMjg1MDg=
9
+ NWVjNGIxMGI0ZTRkNTk5NGQ0MDU5ZjQ3YzM3Y2Y1Nzk5MGJhMzI0MWU5Nzg4
10
+ MmEwYjYyOWVmYWY2NTcyN2NmYTRjNzQ5NDA2MjEwMTc2MmJiZTg5YTZhNGM0
11
+ MTg0ZGVlOGE1M2IxMjc2MWUyYmZkZDM5ODA2ZDVhMmM3NmIyM2E=
12
12
  data.tar.gz: !binary |-
13
- OGFlOGQyOTlhYjQ5NzBmMDQ4OGIwMmU4Mzg3ZWY0YjZlZjkwYzQ0MDI2NzQ5
14
- Nzk0ZDg5MGFlZmI1OTA1ZTVkYzNiZjRkZTcyMzc2NTE4YTQ4ZWFjNmQwYmI2
15
- Yzg2MmQ0MTYwYmIzZTNkNzg3OTdhOWJlY2ZkY2E3ZDUzMDUwM2I=
13
+ MmU4NGY2ZTdkZjZiMzE0YWNkNDdiYmFkMmM4OTUyMGVhYTEzYjM3YmZjZGI3
14
+ ODViMmU0MDY1ZTllMDU0NGQ3MTlhOGQyZGZlNmM5MGNlYjNkMDFhNGJiOWIw
15
+ N2Q5MGI3YmE5NTVkZTA3NzQxYWJjNGE5Mjg1ODYwMjM2YTMwOTk=
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A trivial implementation of the 4 eyes principle. All record actions require an approval to take effect.
4
4
 
5
+ Models that require an approval have a column called approval_status, a value of U implies that the record is un-approved, and a value of A implies that the record is approved.
6
+
7
+ A default scope on the model ensures that only records with approval_status = 'A' are used.
8
+
5
9
 
6
10
  ## Installation
7
11
 
@@ -21,15 +25,42 @@ Or install it yourself as:
21
25
 
22
26
  ## Usage
23
27
 
24
- Models that need an approval, should have the standard approval columns (can be added by included t.approval_columns) and should include include Approval2::ModelAdditions in the class.
28
+ The gem provides a generator to get started
29
+
30
+ ```ruby
31
+ rails g approval2:install
32
+ ```
33
+ This creates a migration for unapproved_records, and its associated model & controller. This is used to keep track of all unapproved records across the application, and can be used to create an 'approval worklist'.
25
34
 
26
- Doing so adds the following columns to the model
35
+ Models that need an approval, should have the following columns
27
36
 
28
37
  1. approval_status
29
38
  2. approved_version
30
39
  3. approved_id
31
40
  4. last_action
32
41
 
42
+ These columns can be added by calling 'approval_columns' in the migration. This method is added by the gem to the TableGeneator.
43
+
44
+ In addition to these columns, the model should include the module Approval2::ModelAdditions in its class.
45
+
46
+ The gem does not yet modify the routes, and an approve action needs to be added for each model manually.
47
+
48
+ All unique indexes on the model need to be modified to include 'approval_status' as an additional column, this is required because the Edit action creates a new record.
49
+
50
+ ## The Approval Cycle
51
+
52
+ ### Create
53
+ When a record is created, it has approval_status 'U', and a entry is added to unapproved_records.
54
+ When the record is approved, the approval_status is updated from 'U' to 'A'
55
+
56
+ ### Edit
57
+ When a record is edited, a clone of the record is created. This clone has approval_status = 'U and the approved_version and approved_id is set to the id & lock_version of the record that was edited. This clone is persisted, and you now have 2 records in the table, one with approval_status = A (the record that was edited, but without any changes), and one with approval_status = U (the clone, with the changes applied).
58
+ When the changes are approved, the record with approval_status = 'A' is deleted, and the approval_status of the cloned record is changed from 'U' to 'A'. To prevent buried updates, this is done only if the lock_version of the A record is still the same as the approved_version of the U record . ( It is expected that any application that updates such records increments lock_version whenever it updates an A record)
59
+
60
+
61
+
62
+
63
+
33
64
  ## Contributing
34
65
 
35
66
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/approval2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -31,7 +31,7 @@ module Approval2
31
31
  end
32
32
 
33
33
  def approve
34
- return "The record version is different from that of the approved version" if !self.approved_record.nil? and self.approved_version != self.approved_record.lock_version
34
+ return "The record version is different from that of the approved version" if !self.approved_record.nil? and self.approved_version != self.approved_record.lock_version
35
35
 
36
36
  # make the U the A record, also assign the id of the A record, this looses history
37
37
  # self.approval_status = 'A'
@@ -43,6 +43,7 @@ module Approval2
43
43
  if self.approved_record.nil?
44
44
  # create action, all we need to do is set the status to approved
45
45
  self.approval_status = 'A'
46
+ self.save!
46
47
  else
47
48
  # copy all attributes of the U record to the A record, and delete the U record
48
49
  attributes = self.attributes.select do |attr, value|
@@ -87,4 +88,4 @@ module Approval2
87
88
  end
88
89
  end
89
90
  end
90
- end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module Approval2
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,4 +1,4 @@
1
- class CreateUnApprovedRecords < ActiveRecord::Migration
1
+ class CreateUnapprovedRecords < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :unapproved_records, {:sequence_start_value => '1 cache 20 order increment by 1'} do |t|
4
4
  t.integer :approvable_id
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approval2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - akil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler