effective_resources 2.5.3 → 2.6.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00988bb634b26b3acd5d90cf94a2cffbb55dc5d4c73db5afe6668d06860a3091'
|
4
|
+
data.tar.gz: d55a09844c23668b754c9ac1d43a6f087330620b32d642b7ceca1990f00a3134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 452023c6b1e60a9317914409b9da54887ec6f686f49c762c7ea87c574ed77172e92519edc685800d297d87976eb936ace8ee3978f0be7f20602c201c0148d366
|
7
|
+
data.tar.gz: 65021dd0297c40f44d1aef163c8dcfbfa4c94aea720ec42290f164ae3f00950fcd79a1df3167eaac86ca1916c9a10f86ed8655d5e5c2788d1a3a0f8973a4bfa2
|
@@ -37,7 +37,7 @@ module EffectiveResourcesHelper
|
|
37
37
|
|
38
38
|
def render_resource_buttons(resource, atts = {}, &block)
|
39
39
|
effective_resource = find_effective_resource
|
40
|
-
actions = controller.try(:buttons) ||
|
40
|
+
actions = controller.try(:buttons) || effective_resource.buttons()
|
41
41
|
|
42
42
|
actions = if resource.kind_of?(Class)
|
43
43
|
actions.select { |_, v| effective_resource.collection_get_actions.include?(v[:action]) }
|
@@ -278,7 +278,7 @@ module EffectiveResourcesHelper
|
|
278
278
|
link_to('Edit', wizard_path(step), title: "Edit #{title}")
|
279
279
|
end
|
280
280
|
|
281
|
-
content_tag(:div, class: 'card') do
|
281
|
+
content_tag(:div, class: 'card mb-4') do
|
282
282
|
content_tag(:div, class: 'card-body') do
|
283
283
|
content_tag(:div, class: 'row') do
|
284
284
|
content_tag(:div, class: 'col-sm') do
|
@@ -24,67 +24,6 @@ module ActsAsStatused
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
module CanCan
|
28
|
-
# The idea here is you can go forward but you can't go back.
|
29
|
-
def acts_as_statused(klass, only: nil, except: nil)
|
30
|
-
raise "klass does not implement acts_as_statused" unless klass.acts_as_statused?
|
31
|
-
|
32
|
-
statuses = klass.const_get(:STATUSES)
|
33
|
-
instance = klass.new
|
34
|
-
|
35
|
-
only = Array(only).compact
|
36
|
-
except = Array(except).compact
|
37
|
-
|
38
|
-
statuses.each_with_index do |status, index|
|
39
|
-
action = status_active_verb(status, instance)
|
40
|
-
|
41
|
-
next if action.blank?
|
42
|
-
next if only.present? && !only.include?(action)
|
43
|
-
next if except.present? && except.include?(action)
|
44
|
-
|
45
|
-
if index == 0
|
46
|
-
can(action, klass) and next
|
47
|
-
end
|
48
|
-
|
49
|
-
if status == :approved && statuses.include?(:declined)
|
50
|
-
if (position = statuses.index { |status| (status == :approved || status == :declined) }) > 0
|
51
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[position-1]}?") || obj.declined? }
|
52
|
-
next
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
if status == :declined && statuses.include?(:approved)
|
57
|
-
if (position = statuses.index { |status| (status == :approved || status == :declined) }) > 0
|
58
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[position-1]}?") }
|
59
|
-
next
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[index-1]}?") }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
# requested -> request, approved -> approve, declined -> decline, pending -> pending
|
70
|
-
def status_active_verb(status, instance)
|
71
|
-
status = status.to_s.strip
|
72
|
-
|
73
|
-
if status.end_with?('ied')
|
74
|
-
action = status[0...-3] + 'y'
|
75
|
-
return action.to_sym if instance.respond_to?(action + '!')
|
76
|
-
end
|
77
|
-
|
78
|
-
# ed, e, ing
|
79
|
-
[-1, -2, -3].each do |index|
|
80
|
-
action = status[0...index]
|
81
|
-
return action.to_sym if instance.respond_to?(action + '!')
|
82
|
-
end
|
83
|
-
|
84
|
-
nil
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
27
|
included do
|
89
28
|
acts_as_statused_options = @acts_as_statused_options
|
90
29
|
|
@@ -103,38 +42,85 @@ module ActsAsStatused
|
|
103
42
|
self.status ||= self.class.const_get(:STATUSES).first
|
104
43
|
|
105
44
|
# Set an existing belongs_to automatically
|
106
|
-
if respond_to?("#{status}_by
|
45
|
+
if respond_to?("#{status}_by") && send("#{status}_by").blank?
|
107
46
|
self.send("#{status}_by=", current_user)
|
108
47
|
end
|
109
48
|
|
110
49
|
# Set an existing timestamp automatically
|
111
|
-
if respond_to?("#{status}_at
|
50
|
+
if respond_to?("#{status}_at") && send("#{status}_at").blank?
|
112
51
|
self.send("#{status}_at=", Time.zone.now)
|
113
52
|
end
|
114
53
|
|
54
|
+
if current_user.present?
|
55
|
+
self.status_steps["#{status}_by_id".to_sym] ||= current_user.id
|
56
|
+
self.status_steps["#{status}_by_type".to_sym] ||= current_user.class.name
|
57
|
+
end
|
58
|
+
|
115
59
|
self.status_steps["#{status}_at".to_sym] ||= Time.zone.now
|
116
|
-
self.status_steps["#{status}_by".to_sym] ||= current_user.try(:id)
|
117
60
|
end
|
118
61
|
|
119
62
|
validates :status, presence: true, inclusion: { in: const_get(:STATUSES).map(&:to_s) }
|
120
63
|
|
121
64
|
# Create an received scope and approved? method for each status
|
122
65
|
acts_as_statused_options[:statuses].each do |sym|
|
66
|
+
sym_at = "#{sym}_at".to_sym
|
67
|
+
sym_by = "#{sym}_by".to_sym
|
68
|
+
sym_by_id = "#{sym}_by_id".to_sym
|
69
|
+
sym_by_type = "#{sym}_by_type".to_sym
|
70
|
+
|
123
71
|
scope(sym, -> { where(status: sym.to_s) })
|
124
72
|
|
73
|
+
# approved?
|
125
74
|
define_method("#{sym}?") { status == sym.to_s }
|
126
|
-
define_method("was_#{sym}?") { send("#{sym}_at").present? }
|
127
75
|
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
#
|
76
|
+
# was_approved?
|
77
|
+
define_method("was_#{sym}?") { send(sym_at).present? }
|
78
|
+
|
79
|
+
# approved_at
|
80
|
+
define_method(sym_at) { self[sym_at.to_s] || status_steps[sym_at] }
|
81
|
+
|
82
|
+
# approved_by_id
|
83
|
+
define_method(sym_by_id) { self[sym_by_id.to_s] || status_steps[sym_by_id] }
|
84
|
+
|
85
|
+
# approved_by_type
|
86
|
+
define_method(sym_by_type) { self[sym_by_type.to_s] || status_steps[sym_by_type] }
|
87
|
+
|
88
|
+
# approved_by
|
89
|
+
define_method(sym_by) do
|
90
|
+
user = (super() if attributes.key?(sym_by_id.to_s))
|
91
|
+
|
92
|
+
user ||= begin
|
93
|
+
id = status_steps[sym_by_id]
|
94
|
+
klass = status_steps[sym_by_type]
|
95
|
+
|
96
|
+
klass.constantize.find(id) if id.present? && klass.present?
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# approved_at=
|
101
|
+
define_method("#{sym_at}=") do |value|
|
102
|
+
super(value) if attributes.key?(sym_at.to_s)
|
103
|
+
status_steps[sym_at] = value
|
104
|
+
end
|
105
|
+
|
106
|
+
# approved_by_id=
|
107
|
+
define_method("#{sym_by_id}=") do |value|
|
108
|
+
super(value) if attributes.key?(sym_by_id.to_s)
|
109
|
+
status_steps[sym_by_id] = value
|
110
|
+
end
|
111
|
+
|
112
|
+
# approved_by_type=
|
113
|
+
define_method("#{sym_by_type}=") do |value|
|
114
|
+
super(value) if attributes.key?(sym_by_type.to_s)
|
115
|
+
status_steps[sym_by_type] = value
|
116
|
+
end
|
132
117
|
|
133
|
-
#
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
118
|
+
# approved_by=
|
119
|
+
define_method("#{sym_by}=") do |value|
|
120
|
+
super(value) if attributes.key?(sym_by_id.to_s)
|
121
|
+
status_steps[sym_by_id] = value&.id
|
122
|
+
status_steps[sym_by_type] = value&.class&.name
|
123
|
+
end
|
138
124
|
|
139
125
|
# approved!
|
140
126
|
define_method("#{sym}!") do |atts = {}|
|
@@ -146,17 +132,18 @@ module ActsAsStatused
|
|
146
132
|
define_method("un#{sym}!") do
|
147
133
|
self.status = nil if (status == sym.to_s)
|
148
134
|
|
149
|
-
|
150
|
-
status_steps.delete("#{sym}_by".to_sym)
|
151
|
-
|
152
|
-
if respond_to?("#{sym}_at=") && respond_to?("#{sym}_at") && send("#{sym}_at").present?
|
135
|
+
if respond_to?("#{sym}_at") && send("#{sym}_at").present?
|
153
136
|
self.send("#{sym}_at=", nil)
|
154
137
|
end
|
155
138
|
|
156
|
-
if respond_to?("#{sym}_by
|
139
|
+
if respond_to?("#{sym}_by") && send("#{sym}_by").present?
|
157
140
|
self.send("#{sym}_by=", nil)
|
158
141
|
end
|
159
142
|
|
143
|
+
status_steps.delete(sym_at)
|
144
|
+
status_steps.delete(sym_by_id)
|
145
|
+
status_steps.delete(sym_by_type)
|
146
|
+
|
160
147
|
true
|
161
148
|
end
|
162
149
|
|
@@ -167,16 +154,4 @@ module ActsAsStatused
|
|
167
154
|
def acts_as_statused?; true; end
|
168
155
|
end
|
169
156
|
|
170
|
-
private
|
171
|
-
|
172
|
-
def acts_as_statused_by_user(status)
|
173
|
-
return nil if status_steps["#{status}_by".to_sym].blank?
|
174
|
-
|
175
|
-
@acts_as_statused_by_users ||= begin
|
176
|
-
User.where(id: status_steps.map { |k, v| v.presence if k.to_s.end_with?('_by') }.compact).all.inject({}) { |h, user| h[user.id] = user; h }
|
177
|
-
end
|
178
|
-
|
179
|
-
@acts_as_statused_by_users[status_steps["#{status}_by".to_sym]]
|
180
|
-
end
|
181
|
-
|
182
157
|
end
|
@@ -281,7 +281,8 @@ module Effective
|
|
281
281
|
|
282
282
|
# Normalize the term.
|
283
283
|
# If you pass an email attribute it can return nil so we return the full value
|
284
|
-
term = Attribute.new(as).parse(value, name: name)
|
284
|
+
term = Attribute.new(as).parse(value, name: name)
|
285
|
+
term = value if term.nil?
|
285
286
|
|
286
287
|
# If using the joined syntax from datatables
|
287
288
|
joined = (sql_column.to_s.split('.').first.to_s.include?(relation.arel_table.name) == false)
|
@@ -305,7 +306,14 @@ module Effective
|
|
305
306
|
end
|
306
307
|
)
|
307
308
|
|
309
|
+
if as == :date
|
310
|
+
term = term.to_date
|
311
|
+
end_at = end_at.to_date
|
312
|
+
end
|
313
|
+
|
308
314
|
relation.where("#{sql_column} >= ? AND #{sql_column} <= ?", term, end_at)
|
315
|
+
elsif value.respond_to?(:strftime) && operation == :eq
|
316
|
+
relation.where(attribute.matches(value))
|
309
317
|
end
|
310
318
|
|
311
319
|
when :effective_obfuscation
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|