effective_memberships 0.6.4 → 0.6.7

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: 6b4247d703d9b732691ae59a81c10d8713603ec2b43fc6f206ae7594c9a4145c
4
- data.tar.gz: 36764403e8da32f0666e88689d263e34e5c67161e2f130cdd53ba8569e7f95e1
3
+ metadata.gz: 994cc88bc7e75f8660b8af1a9930175493759241323675edc72da9ab53640ab5
4
+ data.tar.gz: e29658115f728da1b3b33f5776fc24e461f6abe5ac9cb8d1362834153598a96e
5
5
  SHA512:
6
- metadata.gz: 37404019ffba0de0a2284b412e7d9c97c9bdbcf664cb2ccda104f8227c14b941025cc493af431a206443296352f625a685fd1425ba12f2988ad1f673e5cad5b0
7
- data.tar.gz: 1bdd05c77546a13276c94f7c5c0688749b5d198f232cac214a051bf18e2cab28fe08cead0395d5c6bae823c93abd373f0ed751edcaa4db634501bbb4aa020294
6
+ metadata.gz: 9b2a8938998de7838aef913e2e4f2262a0cde28fc04de5fb0d74816a1ff9ddc23db3000985aceca51b4578339553c9be2c39b0ca0df11c6bbecd7a620101e17f
7
+ data.tar.gz: 95f6268d44cc10e4dabe9c4208f5d42ae669533f31876643aa2b31749414dc5cbf68e8368c062c5997cc61261579e6bec5decfb446020c5497fe74cc02a29640
@@ -14,16 +14,16 @@ module Admin
14
14
  success: -> { "#{resource.owner} has been reclassified to #{resource.owner.membership.category}" },
15
15
  redirect: -> { admin_owners_path(resource) }
16
16
 
17
- submit :status_change, 'Change Status',
18
- success: -> { "#{resource.owner} has been status changed to #{resource.owner.membership.status || 'None'}" },
17
+ submit :status_assign, 'Assign Status',
18
+ success: -> { "#{resource.owner} has been assigned #{resource.owner.membership.statuses_sentence}" },
19
19
  redirect: -> { admin_owners_path(resource) }
20
20
 
21
21
  submit :status_remove, 'Remove Status',
22
- success: -> { "#{resource.owner} has had their status removed" },
22
+ success: -> { "#{resource.owner} has been removed from #{resource.status}" },
23
23
  redirect: -> { admin_owners_path(resource) }
24
24
 
25
25
  submit :assign, 'Assign',
26
- success: -> { "#{resource.owner} has been assigned to #{resource.owner.membership.categories.to_sentence}" },
26
+ success: -> { "#{resource.owner} has been assigned to #{resource.owner.membership.categories_sentence}" },
27
27
  redirect: -> { admin_owners_path(resource) }
28
28
 
29
29
  submit :remove, 'Remove',
@@ -195,7 +195,7 @@ module EffectiveMembershipsApplicant
195
195
  before_validation(if: -> { (new_record? || current_step == :select) && owner.present? }) do
196
196
  self.applicant_type ||= can_apply_applicant_types_collection().first
197
197
  self.from_category = owner.membership&.category
198
- self.from_status = owner.membership&.status
198
+ self.from_status = owner.membership&.status if reinstatement?
199
199
  end
200
200
 
201
201
  before_validation(if: -> { current_step == :experience }) do
@@ -559,7 +559,7 @@ module EffectiveMembershipsApplicant
559
559
  def can_apply_applicant_types_collection
560
560
  if owner.blank? || owner.membership.blank? || owner.membership.categories.blank?
561
561
  ['Apply to Join']
562
- elsif owner.membership.statuses.present?
562
+ elsif owner.membership.statuses.any?(&:reinstatable?)
563
563
  ['Apply for Reinstatement', 'Apply to Join']
564
564
  else
565
565
  ['Apply to Reclassify']
@@ -151,7 +151,7 @@ module EffectiveMembershipsRegistrar
151
151
  save!(owner, date: date)
152
152
  end
153
153
 
154
- def reclassify!(owner, to:, date: nil, skip_fees: false)
154
+ def reclassify!(owner, to:, status: nil, date: nil, skip_fees: false)
155
155
  raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
156
156
  raise('owner must have an existing membership. use register! instead') if owner.membership.blank?
157
157
 
@@ -159,6 +159,7 @@ module EffectiveMembershipsRegistrar
159
159
 
160
160
  raise('expecting a to memberships category') unless to.class.respond_to?(:effective_memberships_category?)
161
161
  raise('expecting a from memberships category') unless from.class.respond_to?(:effective_memberships_category?)
162
+ raise('expecting a memberships status') unless status.nil? || status.class.respond_to?(:effective_memberships_status?)
162
163
  raise('expected to and from to be different') if from == to
163
164
 
164
165
  date ||= Time.zone.now
@@ -171,6 +172,9 @@ module EffectiveMembershipsRegistrar
171
172
  membership.build_membership_category(category: to)
172
173
  membership.membership_category(category: from).mark_for_destruction
173
174
 
175
+ # Assign Status
176
+ membership.build_membership_status(status: status) if status.present?
177
+
174
178
  unless skip_fees
175
179
  fee = owner.build_prorated_fee(date: date)
176
180
  raise('already has purchased prorated fee') if fee.purchased?
@@ -202,37 +206,63 @@ module EffectiveMembershipsRegistrar
202
206
  save!(owner, date: date)
203
207
  end
204
208
 
205
- # This clears the status entirely from user
206
- def status_remove!(owner, date: nil)
207
- status_change!(owner, to: nil, date: date)
209
+ def status_clear!(owner, date: nil)
210
+ raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
211
+ raise('owner must have an existing membership. use register! instead') if owner.membership.blank?
212
+
213
+ status_assign!(owner, date: date, status: [])
208
214
  end
209
215
 
210
- # To can be nil to clear the status entirely
211
- def status_change!(owner, to:, date: nil)
216
+ def status_add!(owner, status:, date: nil)
212
217
  raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
213
218
  raise('owner must have an existing membership. use register! instead') if owner.membership.blank?
214
219
 
215
- from = owner.membership.status
220
+ status_assign!(owner, date: date, status: owner.membership.statuses + Array(status))
221
+ end
216
222
 
217
- raise('expecting a to memberships status') if to.present? && !to.class.respond_to?(:effective_memberships_status?)
218
- raise('expecting a from memberships status') if from.present? && !from.class.respond_to?(:effective_memberships_status?)
219
- raise('expected to and from to be different') if from == to
223
+ def status_remove!(owner, status:, date: nil)
224
+ raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
225
+ raise('owner must have an existing membership. use register! instead') if owner.membership.blank?
220
226
 
221
- date ||= Time.zone.now
227
+ status_assign!(owner, date: date, status: owner.membership.statuses - Array(status))
228
+ end
229
+
230
+ def status_assign!(owner, status:, date: nil)
231
+ raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
222
232
 
223
233
  membership = owner.membership
234
+ raise('owner must have an existing membership. use register! instead') if membership.blank?
224
235
 
225
- # Assign Status
226
- membership.build_membership_status(status: to) if to.present?
227
- membership.membership_status(status: from).mark_for_destruction if from.present?
236
+ statuses = Array(status)
237
+ raise('expected a memberships status') unless statuses.blank? || statuses.all? { |status| status.class.respond_to?(:effective_memberships_status?) }
228
238
 
229
- # Save
230
- save!(owner, date: date)
239
+ # Add
240
+ statuses.each do |status|
241
+ next if membership.membership_status(status: status).present?
242
+ membership.build_membership_status(status: status)
243
+ end
244
+
245
+ # Remove
246
+ membership.statuses.each do |existing|
247
+ next if statuses.include?(existing)
248
+ membership.membership_status(status: existing).mark_for_destruction
249
+ end
250
+
251
+ changed = membership.membership_statuses.any? { |ms| ms.new_record? || ms.marked_for_destruction? }
252
+
253
+ if changed
254
+ date ||= Time.zone.now
255
+
256
+ membership.registration_on = date # Always new registration_on
257
+ save!(owner, date: date)
258
+ end
259
+
260
+ true
231
261
  end
232
262
 
233
263
  def remove!(owner, date: nil)
234
264
  raise('expecting a memberships owner') unless owner.class.respond_to?(:effective_memberships_owner?)
235
- raise('expected a member') unless owner.membership.present?
265
+ raise('expected a member with a membership') unless owner.membership.present?
236
266
 
237
267
  # Date
238
268
  date ||= Time.zone.now
@@ -68,4 +68,9 @@ module EffectiveMembershipsStatus
68
68
  status_type == 'Organization'
69
69
  end
70
70
 
71
+ # Used for Apply to Join Reinstatement
72
+ def reinstatable?
73
+ true
74
+ end
75
+
71
76
  end
@@ -113,6 +113,10 @@ module Effective
113
113
  categories.first.id
114
114
  end
115
115
 
116
+ def categories_sentence
117
+ categories.map(&:to_s).to_sentence.presence || 'None'
118
+ end
119
+
116
120
  def membership_category(category:)
117
121
  raise('expected a category') unless category.class.respond_to?(:effective_memberships_category?)
118
122
  membership_categories.find { |mc| mc.category_id == category.id && mc.category_type == category.class.name }
@@ -134,6 +138,10 @@ module Effective
134
138
  membership_statuses.reject(&:marked_for_destruction?).map(&:status_id)
135
139
  end
136
140
 
141
+ def statuses_sentence
142
+ statuses.map(&:to_s).to_sentence.presence || 'None'
143
+ end
144
+
137
145
  # We might want to use singular memberships.
138
146
  def status
139
147
  raise('expected singular usage but there are more than one membership status') if statuses.length > 1
@@ -21,8 +21,8 @@ module Effective
21
21
  attr_accessor :skip_fees
22
22
 
23
23
  # Status Change
24
+ attr_accessor :status_ids
24
25
  attr_accessor :status_id
25
- attr_accessor :status_remove_action
26
26
 
27
27
  # Assign
28
28
  attr_accessor :category_ids
@@ -46,8 +46,11 @@ module Effective
46
46
  validates :category_id, presence: true,
47
47
  if: -> { current_action == :reclassify || current_action == :register }
48
48
 
49
- # Status Change
50
- validates :status_id, presence: true, if: -> { current_action == :status_change }
49
+ # Status Assign
50
+ validates :status_ids, presence: true, if: -> { current_action == :status_assign }
51
+
52
+ # Status Remove
53
+ validates :status_id, presence: true, if: -> { current_action == :status_remove }
51
54
 
52
55
  # Assign
53
56
  validates :category_ids, presence: true, if: -> { current_action == :assign }
@@ -66,14 +69,14 @@ module Effective
66
69
  EffectiveMemberships.Registrar.reclassify!(owner, to: category, skip_fees: skip_fees?)
67
70
  end
68
71
 
69
- def status_change!
70
- update!(current_action: :status_change)
71
- EffectiveMemberships.Registrar.status_change!(owner, to: status)
72
+ def status_assign!
73
+ update!(current_action: :status_assign)
74
+ EffectiveMemberships.Registrar.status_assign!(owner, status: statuses)
72
75
  end
73
76
 
74
77
  def status_remove!
75
78
  update!(current_action: :status_remove)
76
- EffectiveMemberships.Registrar.status_remove!(owner)
79
+ EffectiveMemberships.Registrar.status_remove!(owner, status: status)
77
80
  end
78
81
 
79
82
  def assign!
@@ -101,6 +104,10 @@ module Effective
101
104
  EffectiveMemberships.Registrar.remove!(owner)
102
105
  end
103
106
 
107
+ def assign_attributes(atts)
108
+ super(atts.reject { |k, _| k.to_s.start_with?('status_remove_action_') })
109
+ end
110
+
104
111
  def update!(atts)
105
112
  assign_attributes(atts); save!
106
113
  end
@@ -121,8 +128,6 @@ module Effective
121
128
  @owner_id || (@owner.id if @owner)
122
129
  end
123
130
 
124
- private
125
-
126
131
  def category
127
132
  EffectiveMemberships.Category.find(@category_id) if @category_id.present?
128
133
  end
@@ -3,6 +3,7 @@
3
3
  %h5.card-title Status Change
4
4
 
5
5
  = effective_form_with(model: [:admin, registrar_action], url: effective_memberships.admin_registrar_actions_path) do |f|
6
+
6
7
  = f.hidden_field :owner_id
7
8
  = f.hidden_field :owner_type
8
9
 
@@ -13,29 +14,33 @@
13
14
  Change or remove a member's existing status.
14
15
 
15
16
  = f.static_field :current_action, label: 'Current Status' do
16
- = (membership.status || 'None').to_s
17
+ = badges(membership.statuses) || 'None'
17
18
 
18
19
  = f.check_box :current_action, label: 'Yes, change member status'
19
20
 
20
21
  = f.show_if :current_action, true do
21
22
  %p The member will keep their existing membership number: #{membership.number}.
22
23
 
23
- - statuses = f.object.owner.registrar_action_statuses(:status_change) - membership.statuses
24
- = f.select :status_id, statuses, label: 'Change status to', required: true
24
+ - statuses = f.object.owner.registrar_action_statuses(:status_change)
25
+ - f.object.status_ids = membership.status_ids
26
+
27
+ = f.select :status_ids, statuses, label: 'Change status to', required: true, multiple: true
25
28
 
26
29
  %p No fees will be created
27
30
 
28
- = f.submit 'Change Status', border: false, center: true, 'data-confirm': "Really change #{f.object.owner}?"
31
+ = f.submit 'Assign Status', border: false, center: true, 'data-confirm': "Really assign #{f.object.owner} status?"
32
+
33
+ - # Remove Actions
34
+ - membership.statuses.each do |status|
35
+ = f.check_box "status_remove_action_#{status.id}", label: "Yes, remove #{status} status"
29
36
 
30
- - # Remove Action
31
- - if membership.status.present?
32
- = f.check_box :status_remove_action, label: "Yes, remove #{membership.status} status"
37
+ = f.show_if("status_remove_action_#{status.id}", true, validate: false) do
38
+ = f.hidden_field :status_id, value: status.id
33
39
 
34
- = f.show_if :status_remove_action, true do
35
40
  %p The member will keep their existing membership number: #{membership.number}
36
41
 
37
- %p This action will remove the #{membership.status} status
42
+ %p This action will remove the #{badge(status)} status
38
43
 
39
44
  %p No fees will be created
40
45
 
41
- = f.submit 'Remove Status', border: false, center: true, 'data-confirm': "Really remove status #{f.object.owner}?"
46
+ = f.submit "Remove Status", border: false, center: true, 'data-confirm': "Remove #{status} from #{f.object.owner}?"
data/db/seeds.rb CHANGED
@@ -10,6 +10,8 @@ if Rails.env.test?
10
10
  end
11
11
 
12
12
  Effective::Status.where(title: 'Resigned').first_or_create!
13
+ Effective::Status.where(title: 'Deceased').first_or_create!
14
+ Effective::Status.where(title: 'On Leave').first_or_create!
13
15
 
14
16
  member = Effective::Category.create!(
15
17
  title: "Full Member",
@@ -1,3 +1,3 @@
1
1
  module EffectiveMemberships
2
- VERSION = '0.6.4'
2
+ VERSION = '0.6.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_memberships
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.7
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: 2022-09-01 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails