effective_resources 2.2.7 → 2.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2b489df65b7ef3e426fa8e43fe5e142560f861c7c1f7a2d580b3ce864d74d4
|
4
|
+
data.tar.gz: 7776fbc00d3ad40f8c8ac6ccff80ff2e114c48b52f47d59ea054ae4bddfaf15d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3d35a468f47af10084426d26d461d5168a6637bfe973b0ba5182bf65cbd1a4804255f956d28a558bc227b4ed986d8ad47eaf39385639db18b9e27afa6a1a24
|
7
|
+
data.tar.gz: e9bfd478683a588e25f4a24986d9f695485e4d59451af70415c83852a7fe0f48ec7b7211b000b0541e19e931154df8f2ccf2362e6c785c1fba072dd42120fed7
|
@@ -49,7 +49,7 @@ module Effective
|
|
49
49
|
|
50
50
|
existing = resource_scope.in_progress.order(:id).where.not(id: resource).first
|
51
51
|
return unless existing.present?
|
52
|
-
return if (existing.id > resource.id) # Otherwise we get an infinite loop
|
52
|
+
return if resource.persisted? && (existing.id > resource.id) # Otherwise we get an infinite loop
|
53
53
|
|
54
54
|
flash[:success] = "You have been redirected to your in-progress wizard"
|
55
55
|
redirect_to resource_wizard_path(existing, existing.next_step)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# HasManyPurgable
|
2
|
+
#
|
3
|
+
# Mark your model with 'has_many_purgable' or 'has_one_purgable' to allow any has_many or has_one to be purgable
|
4
|
+
# Pass 'has_many_purgable :files, :avatar' to only allow the files and avatar to be purged.
|
5
|
+
# Works with effective_bootstrap file_field to display a Delete file on save checkbox
|
6
|
+
# to submit a _purge_attached array or association names to purge.
|
7
|
+
|
8
|
+
module HasManyPurgable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
module Base
|
12
|
+
def has_many_purgable(*args)
|
13
|
+
options = args.extract_options!
|
14
|
+
names = Array(args).compact.presence || :all
|
15
|
+
|
16
|
+
@has_many_purgable_options = options.merge(names: names)
|
17
|
+
|
18
|
+
include ::HasManyPurgable
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_one_purgable(*args)
|
22
|
+
has_many_purgable(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
included do
|
28
|
+
options = @has_many_purgable_options
|
29
|
+
self.send(:define_method, :has_many_purgable_options) { options }
|
30
|
+
|
31
|
+
attr_accessor :_purge_attached
|
32
|
+
|
33
|
+
with_options(if: -> { _purge_attached.present? }) do
|
34
|
+
before_validation { has_many_purgable_mark_for_destruction }
|
35
|
+
after_save { has_many_purgable_purge }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
def has_many_purgable?; true; end
|
42
|
+
end
|
43
|
+
|
44
|
+
# All the possible names, merging the actual associations and the given options
|
45
|
+
def has_many_purgable_names
|
46
|
+
names = has_many_purgable_options.fetch(:names)
|
47
|
+
|
48
|
+
associations = self.class.reflect_on_all_associations
|
49
|
+
.select { |ass| ass.class_name == 'ActiveStorage::Attachment' }
|
50
|
+
.map { |ass| ass.name.to_s.chomp('_attachments').chomp('_attachment').to_sym }
|
51
|
+
|
52
|
+
names == :all ? associations : (names & associations)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# As submitted by the form and permitted by our associations and options
|
58
|
+
def has_many_purgable_attachments
|
59
|
+
submitted = (Array(_purge_attached) - [nil, '', '0', ' ', 'false', 'f', 'off']).map(&:to_sym)
|
60
|
+
submitted & has_many_purgable_names
|
61
|
+
end
|
62
|
+
|
63
|
+
def has_many_purgable_mark_for_destruction
|
64
|
+
has_many_purgable_attachments.each do |name|
|
65
|
+
Array(public_send(name)).each { |attachment| attachment.mark_for_destruction }
|
66
|
+
end
|
67
|
+
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def has_many_purgable_purge
|
72
|
+
has_many_purgable_attachments.each do |name|
|
73
|
+
Rails.logger.info "[has_many_purgable] Purging #{name} attachments"
|
74
|
+
Array(public_send(name)).each { |attachment| attachment.purge }
|
75
|
+
end
|
76
|
+
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -29,6 +29,7 @@ module EffectiveResources
|
|
29
29
|
ActiveRecord::Base.extend(ActsAsStatused::Base)
|
30
30
|
ActiveRecord::Base.extend(ActsAsWizard::Base)
|
31
31
|
ActiveRecord::Base.extend(ActsAsPurchasableWizard::Base)
|
32
|
+
ActiveRecord::Base.extend(HasManyPurgable::Base)
|
32
33
|
ActiveRecord::Base.extend(HasManyRichTexts::Base)
|
33
34
|
|
34
35
|
ActiveRecord::Base.extend(EffectiveDeviseUser::Base)
|
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.2.
|
4
|
+
version: 2.2.9
|
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-01-
|
11
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- app/models/concerns/effective_after_commit.rb
|
166
166
|
- app/models/concerns/effective_devise_user.rb
|
167
167
|
- app/models/concerns/effective_resource.rb
|
168
|
+
- app/models/concerns/has_many_purgable.rb
|
168
169
|
- app/models/concerns/has_many_rich_texts.rb
|
169
170
|
- app/models/effective/access_denied.rb
|
170
171
|
- app/models/effective/action_failed.rb
|