dcidev_approval 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -5
  3. data/lib/dcidev_approval.rb +3 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acf499a815402aa955b457d3fa2db0a97a6018135c1c8814ecad4c4894eeaf62
4
- data.tar.gz: 12c8dffb9dea52b6d335e0a38194344f780dbf9e7d13259d4c92892d92dbdc60
3
+ metadata.gz: ceacb6241a269f4b1c40dc7f83d1fb245619456759e9814514cbdb694365b757
4
+ data.tar.gz: d3fe771c426cd90a58d1f8bb83658652d42081f1fdda5e53a1f767196d9346b0
5
5
  SHA512:
6
- metadata.gz: 1cd2869a8e8709375a4b82fde759ab37a7e43a41f1ceedbdf1f563e68a6ac58976c950b8b1088ca8bd7c50ee81e42a8d744bd207d5a5819d23d967fa6be8f242
7
- data.tar.gz: 844432fe9092b9918d238ce1ff730dd4028993c087665f26c8361518f49d7c5a189362a7a987c2fc3a92fcb81ecd94cadcd651d3311649fa62e4a79357718e80
6
+ metadata.gz: 1a85f826b582a4e27af4c43136024b7c033fbaf89a6f97fa93b459fde6de38c08fbfba026a96d48d80e5b5a8b0baef675af25a52a1baa411dbc432bde14a7ad0
7
+ data.tar.gz: 0a2a2d68986cd8285614bad0531030c064e759139da4180929c08b39ff23515505f3a87254e80c2f7e897f96ba54e890773ad2a8a9728b267a1566b1485e3528
data/README.md CHANGED
@@ -4,8 +4,11 @@
4
4
  ```ruby
5
5
  class AddStatusToProduk < ActiveRecord::Migration[6.0]
6
6
  def change
7
- add_column :produk, :status, :string
8
- add_column :produk, :change_status, :string
7
+ change_column :model do |t|
8
+ t.string :status
9
+ t.string :change_status
10
+ t.json :data_changes
11
+ end
9
12
  end
10
13
  end
11
14
  ```
@@ -18,8 +21,6 @@ CHANGE_STATUS = %w(pending_delete pending_update).freeze
18
21
  enum change_status: CHANGE_STATUS.zip(CHANGE_STATUS).to_h, _prefix: true
19
22
  ```
20
23
 
21
-
22
-
23
24
  ##### 2. Format your `Agent` and `Role` with one-many relationship.
24
25
  ##### 3. Declare instance method `is_admin?` to `Agent` to find out whether an agent is an admin or not
25
26
 
@@ -56,8 +57,23 @@ Explanation
56
57
  * `current_user`: the agent responsible for the changes
57
58
  * `bypass`: boolean value to toogle the approval system. If not sent, the default value is `true`
58
59
 
59
- To track changes peformed to a record, call
60
+ To track changes peformed to a record, call `instance_model.audit_trails`
61
+
62
+ # Approval
63
+ To approve / reject changes, call `approval(params)`.
64
+ You MUST use `status` as the param name otherwise it wont work.
65
+ ```ruby
66
+ params do
67
+ requires :status, type: String, values: %w[approved rejected]
68
+ end
69
+ post "/approval/:id" do
70
+ @produk.approval(params, current_user)
71
+ present :produk, @produk
72
+ end
73
+ ```
74
+
60
75
  # Callbacks
76
+
61
77
  To execute code before/after the CRUD, include module `DcidevApproval` in `ApplicationRecord` and peform overide and or overload on it's child model.
62
78
 
63
79
  `app/models/application_record.rb`
@@ -64,8 +64,8 @@ module DcidevApproval
64
64
  end
65
65
 
66
66
  def last_approved_by
67
- last_approve = audit_trails.where(activity_type: :approve).limit(1).try(:first)
68
- last_entry = audit_trails.limit(1).order(created_at: :desc).try(:first)
67
+ last_approve = audit_trails.where(approval: true).limit(1).try(:first)
68
+ last_entry = audit_trails.limit(1).try(:first)
69
69
  {
70
70
  approved_by: last_approve.try(:id) == last_entry.try(:id) ? last_approve.try(:agent).try(:name).to_s + " (#{last_approve.try(:agent_role).try(:name)})" : nil,
71
71
  approved_at: last_approve.try(:id) == last_entry.try(:id) ? last_approve.try(:created_at) : nil
@@ -97,7 +97,7 @@ module DcidevApproval
97
97
  raise errors.full_messages.join(', ') unless update_by_params(params, false)
98
98
  elsif changes_present?(params)
99
99
  ActiveRecord::Base.transaction do
100
- data = agent.is_admin? || status == 'waiting' ? params : { change_status: :pending_update, data_changes: agent.is_admin? ? nil : params }
100
+ data = agent.is_admin? || status == 'waiting' ? params :{ change_status: :pending_update, data_changes: agent.is_admin? ? nil : params }
101
101
  raise errors.full_messages.join(', ') unless update_by_params(data, false)
102
102
  end
103
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcidev_approval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Punto Damar P