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.
- checksums.yaml +4 -4
- data/README.md +21 -5
- data/lib/dcidev_approval.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceacb6241a269f4b1c40dc7f83d1fb245619456759e9814514cbdb694365b757
|
4
|
+
data.tar.gz: d3fe771c426cd90a58d1f8bb83658652d42081f1fdda5e53a1f767196d9346b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
8
|
-
|
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`
|
data/lib/dcidev_approval.rb
CHANGED
@@ -64,8 +64,8 @@ module DcidevApproval
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def last_approved_by
|
67
|
-
last_approve = audit_trails.where(
|
68
|
-
last_entry = audit_trails.limit(1).
|
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 :
|
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
|