effective_memberships 0.1.2 → 0.1.6

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: d6e16095d62eababb9b14b78f65c13b45b744e15c16f92b79724b8e138b4b38d
4
- data.tar.gz: e4a51731819350e85f49615a982614197fc05fcf3b4b5da4558a6a534eab1ea2
3
+ metadata.gz: 94c86611361e96c3285e00fde6075fcffa29463c30a7dd2b50eaec13b9932874
4
+ data.tar.gz: faaa7786c43295547b10febc3c6f55b1e4041235d693f6f7e02094c22780f5af
5
5
  SHA512:
6
- metadata.gz: c333cb75909efad3f4400b0fead9397b5f3f89d3d4df9dc920e9b5867ad58223fa0baeb3170db00b0d652bbf41d48405832b103e3fb84b872ed042634a20a0a3
7
- data.tar.gz: 859cea163d8380b4daf5e6dbc98f575a1b755fded7a27c3a227ddc36e1de61b1225304e091d44c9a4fa6096b1b464aeaf0f339013c57920ad5bd91e027575992
6
+ metadata.gz: b9c66aaa1fe570f885d5b36b83f733cf15f8b4d3e2a1968d5bd4db197cbddd33a91247405a60fde9ab5dbde210de04119d3f51594baf09946a7ebdcc8c29029d
7
+ data.tar.gz: 3b36dee1f865804437f63415680c49c131b9ee94a4ae7f8e31e2df789268ae413e43ea8db3ea8c8548e352a63cf33273b508832dcd1eb476ae877c19c8bcdc50
@@ -0,0 +1,19 @@
1
+ module Admin
2
+ class FeePaymentsController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_memberships) }
5
+
6
+ include Effective::CrudController
7
+
8
+ resource_scope -> { EffectiveMemberships.FeePayment.deep.all }
9
+ datatable -> { Admin::EffectiveFeePaymentsDatatable.new }
10
+
11
+ private
12
+
13
+ def permitted_params
14
+ model = (params.key?(:effective_applicant) ? :effective_fee_payment : :fee_payment)
15
+ params.require(model).permit!
16
+ end
17
+
18
+ end
19
+ end
@@ -24,8 +24,9 @@ module Effective
24
24
 
25
25
  def permitted_params
26
26
  permitted = params.require(:effective_applicant_reference).permit!.except(:token, :last_notified_at, :status, :status_steps)
27
+ authorized = current_user.effective_memberships_owners.include?(resource.applicant.owner) == false
27
28
 
28
- if resource.submitted? && resource.applicant.was_submitted? && (resource.applicant.owner != current_user.effective_memberships_owner)
29
+ if resource.submitted? && resource.applicant.was_submitted? && authorized
29
30
  permitted
30
31
  else
31
32
  permitted.except(:reservations, :reservations_reason, :work_history, :accept_declaration)
@@ -4,7 +4,7 @@ module Effective
4
4
 
5
5
  include Effective::WizardController
6
6
 
7
- resource_scope -> { EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owner) }
7
+ resource_scope -> { EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owners) }
8
8
 
9
9
  # Allow only 1 in-progress application at a time
10
10
  before_action(only: [:new, :show], unless: -> { resource&.done? }) do
@@ -4,7 +4,7 @@ module Effective
4
4
 
5
5
  include Effective::WizardController
6
6
 
7
- resource_scope -> { EffectiveMemberships.FeePayment.deep.where(owner: current_user.effective_memberships_owner) }
7
+ resource_scope -> { EffectiveMemberships.FeePayment.deep.where(owner: current_user.effective_memberships_owners) }
8
8
 
9
9
  # Allow only 1 in-progress fee payment at a time
10
10
  before_action(only: [:new, :show], unless: -> { resource&.done? }) do
@@ -20,8 +20,7 @@ module Effective
20
20
 
21
21
  def permitted_params
22
22
  params.require(:fee_payment).permit!.except(
23
- :owner_id, :owner_type, :status, :status_steps, :wizard_steps,
24
- :submitted_at
23
+ :status, :status_steps, :wizard_steps, :submitted_at
25
24
  )
26
25
  end
27
26
 
@@ -0,0 +1,51 @@
1
+ module Admin
2
+ class EffectiveFeePaymentsDatatable < Effective::Datatable
3
+ filters do
4
+ scope :all
5
+ scope :in_progress, label: 'Open / Active'
6
+ scope :done, label: 'Done'
7
+ end
8
+
9
+ datatable do
10
+ order :id
11
+ col :id, visible: false
12
+
13
+ col :status
14
+
15
+ col :created_at, label: 'Created', as: :date, visible: false
16
+ col :updated_at, label: 'Updated', visible: false
17
+
18
+ col :period, visible: false
19
+ col :submitted_at, label: 'Submitted', visible: false, as: :date
20
+
21
+ col :owner
22
+
23
+ col :category, search: { collection: EffectiveMemberships.Category.all, polymorphic: false }
24
+
25
+ col :orders, visible: false
26
+
27
+ actions_col
28
+ end
29
+
30
+ collection do
31
+ fee_payments = EffectiveMemberships.FeePayment.deep.all
32
+
33
+ raise('expected an owner_id, not user_id') if attributes[:user_id].present?
34
+
35
+ if fee_payments == :in_progress && attributes[:owner_id].blank?
36
+ fee_payments = fee_payments.where.not(status: :draft)
37
+ end
38
+
39
+ if attributes[:owner_id].present?
40
+ fee_payments = fee_payments.where(owner_id: attributes[:owner_id])
41
+ end
42
+
43
+ if attributes[:except_id].present?
44
+ fee_payments = fee_payments.where.not(id: attributes[:except_id])
45
+ end
46
+
47
+ fee_payments
48
+ end
49
+
50
+ end
51
+ end
@@ -28,7 +28,7 @@ class EffectiveApplicantsDatatable < Effective::Datatable
28
28
  end
29
29
 
30
30
  collection do
31
- EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owner)
31
+ EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owners)
32
32
  end
33
33
 
34
34
  end
@@ -0,0 +1,24 @@
1
+ # Dashboard Fee Payments
2
+ class EffectiveFeePaymentsDatatable < Effective::Datatable
3
+ datatable do
4
+ order :created_at
5
+
6
+ col :token, visible: false
7
+ col :created_at, visible: false
8
+
9
+ col :owner
10
+ col :status, visible: false
11
+ col :submitted_at, label: 'Submitted', as: :date
12
+ col :period, visible: false
13
+
14
+ col :orders, action: :show
15
+
16
+ actions_col(new: false)
17
+ end
18
+
19
+ collection do
20
+ EffectiveMemberships.FeePayment.deep.done
21
+ .where(owner: current_user.effective_memberships_owners)
22
+ end
23
+
24
+ end
@@ -50,10 +50,16 @@ module EffectiveMembershipsFeePayment
50
50
  attr_accessor :declare_code_of_ethics
51
51
  attr_accessor :declare_truth
52
52
 
53
+ # Throwaway
54
+ attr_accessor :upgrade, :downgrade
55
+
53
56
  # Application Namespace
54
57
  belongs_to :owner, polymorphic: true
55
58
  accepts_nested_attributes_for :owner
56
59
 
60
+ belongs_to :user, polymorphic: true, optional: true
61
+ accepts_nested_attributes_for :user
62
+
57
63
  # Like maybe optionally it makes sense.
58
64
  belongs_to :category, polymorphic: true, optional: true
59
65
 
@@ -153,6 +159,41 @@ module EffectiveMembershipsFeePayment
153
159
  owner&.outstanding_fee_payment_fees
154
160
  end
155
161
 
162
+ def select!
163
+ reset!
164
+ end
165
+
166
+ def reset!
167
+ assign_attributes(wizard_steps: wizard_steps.slice(:start))
168
+ save!
169
+ end
170
+
171
+ # Work with effective_organizations
172
+ def organization!
173
+ if upgrade_individual_to_organization?
174
+ save!
175
+ update!(owner: owner.representatives.first.organization)
176
+ elsif downgrade_organization_to_individual?
177
+ save!
178
+ update!(owner: current_user)
179
+ else
180
+ save!
181
+ end
182
+ end
183
+
184
+ def upgrade_individual_to_organization?
185
+ return false unless EffectiveResources.truthy?(upgrade)
186
+ return false unless owner.class.respond_to?(:effective_organizations_user?)
187
+ owner.representatives.any?(&:new_record?)
188
+ end
189
+
190
+ def downgrade_organization_to_individual?
191
+ return false unless EffectiveResources.truthy?(downgrade)
192
+ return false unless owner.class.respond_to?(:effective_organizations_organization?)
193
+ return false if current_user.blank?
194
+ owner.representatives.any?(&:marked_for_destruction?)
195
+ end
196
+
156
197
  # All Fees and Orders
157
198
  def submit_fees
158
199
  fees
@@ -203,7 +244,6 @@ module EffectiveMembershipsFeePayment
203
244
  save!
204
245
  end
205
246
 
206
-
207
247
  # Called automatically via after_purchase hook above
208
248
  def submit_purchased!
209
249
  return false if was_submitted?
@@ -22,8 +22,8 @@ module EffectiveMembershipsOwner
22
22
 
23
23
  included do
24
24
  # App scoped
25
- has_many :applicants, as: :owner
26
- has_many :fee_payments, as: :owner
25
+ has_many :applicants, -> { order(:id) }, inverse_of: :owner, as: :owner
26
+ has_many :fee_payments, -> { order(:id) }, inverse_of: :owner, as: :owner
27
27
 
28
28
  # Effective scoped
29
29
  has_many :fees, -> { order(:id) }, inverse_of: :owner, as: :owner, class_name: 'Effective::Fee', dependent: :nullify
@@ -46,7 +46,23 @@ module EffectiveMembershipsOwner
46
46
  end
47
47
 
48
48
  def effective_memberships_owner
49
- self
49
+ raise('expected singular usage but there are more than one owner') if effective_memberships_owners.length > 1
50
+ effective_memberships_owners.first
51
+ end
52
+
53
+ def effective_memberships_owners
54
+ owners = users if respond_to?(:users) && users.any? { |user| user.class.respond_to?(:effective_memberships_owner?) }
55
+ owners = organizations if respond_to?(:organizations) && organizations.any? { |organization| organization.class.respond_to?(:effective_memberships_owner?) }
56
+
57
+ owners || [self]
58
+ end
59
+
60
+ def outstanding_fee_payment_owners
61
+ effective_memberships_owners.select { |owner| !owner.membership_fees_paid? }
62
+ end
63
+
64
+ def current_fee_payment_owner
65
+ outstanding_fee_payment_owners.first || self
50
66
  end
51
67
 
52
68
  def owner_label
@@ -27,8 +27,8 @@ module Effective
27
27
 
28
28
  validates :owner, presence: true
29
29
 
30
- validates :categories, presence: true, unless: -> { removed? }
31
- validates :category_ids, presence: true, unless: -> { removed? }
30
+ # validates :categories, presence: true, unless: -> { removed? }
31
+ # validates :category_ids, presence: true, unless: -> { removed? }
32
32
 
33
33
  validates :start_on, presence: true
34
34
 
@@ -0,0 +1 @@
1
+ = render 'effective/fee_payments/fee_payment', fee_payment: fee_payment
@@ -0,0 +1,8 @@
1
+ - datatable = EffectiveResources.best('EffectiveFeePaymentsDatatable').new(self, namespace: :effective)
2
+
3
+ %h2 Fee Payments
4
+
5
+ - if datatable.present?
6
+ = render_simple_datatable(datatable)
7
+ - else
8
+ %p You have no past fee payments. When you do, we'll show them here.
@@ -3,4 +3,4 @@
3
3
  - steps = fee_payment.required_steps - blacklist
4
4
 
5
5
  - steps.select { |step| fee_payment.has_completed_step?(step) }.each do |partial|
6
- = render "effective/fee_payments/#{partial}", fee_payment: fee_payment, step: partial
6
+ = render "effective/fee_payments/#{partial}", fee_payment: fee_payment, resource: fee_payment, step: partial
@@ -2,19 +2,33 @@
2
2
 
3
3
  .card
4
4
  .card-body
5
- %p Welcome #{current_user.effective_memberships_owner}!
5
+ - current_owner = current_user.current_fee_payment_owner
6
+
7
+ %p Welcome #{current_owner}!
6
8
 
7
9
  = render 'effective/fee_payments/content', resource: resource
8
10
 
9
- - if resource.outstanding_fees.blank?
11
+ - if current_owner.membership_fees_paid?
10
12
  %p You have no fees due at this time.
11
13
  = link_to 'Home', root_path, class: 'btn btn-primary'
12
14
 
13
- - if resource.outstanding_fees.present?
14
- %p You have the following fees due at this time:
15
+ - else
16
+ - if resource.outstanding_fees.present?
17
+ %p You have the following fees due at this time:
18
+ = render_purchasables(resource.outstanding_fees)
19
+ - else
20
+ %p You have fees due. Please continue.
15
21
 
16
- = render_purchasables(resource.outstanding_fees)
22
+ - resource.user = current_user
23
+ - resource.owner = current_owner
17
24
 
18
25
  = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
19
26
  = f.hidden_field :id
27
+
28
+ = f.hidden_field :owner_type
29
+ = f.hidden_field :owner_id
30
+
31
+ = f.hidden_field :user_type
32
+ = f.hidden_field :user_id
33
+
20
34
  = f.save 'Save and Continue'
data/config/routes.rb CHANGED
@@ -26,6 +26,7 @@ EffectiveMemberships::Engine.routes.draw do
26
26
  resources :applicant_course_areas, except: [:show]
27
27
  resources :applicant_course_names, except: [:show]
28
28
 
29
+ resources :fee_payments, only: [:index, :show]
29
30
  resources :registrar_actions, only: [:create]
30
31
  end
31
32
 
@@ -353,6 +353,9 @@ class CreateEffectiveMemberships < ActiveRecord::Migration[6.0]
353
353
  t.integer :owner_id
354
354
  t.string :owner_type
355
355
 
356
+ t.integer :user_id
357
+ t.string :user_type
358
+
356
359
  t.integer :category_id
357
360
  t.string :category_type
358
361
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveMemberships
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.6'
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.1.2
4
+ version: 0.1.6
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: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -214,6 +214,7 @@ files:
214
214
  - app/controllers/admin/applicant_course_names_controller.rb
215
215
  - app/controllers/admin/applicants_controller.rb
216
216
  - app/controllers/admin/categories_controller.rb
217
+ - app/controllers/admin/fee_payments_controller.rb
217
218
  - app/controllers/admin/fees_controller.rb
218
219
  - app/controllers/admin/registrar_actions_controller.rb
219
220
  - app/controllers/effective/applicant_references_controller.rb
@@ -223,6 +224,7 @@ files:
223
224
  - app/datatables/admin/effective_applicant_course_names_datatable.rb
224
225
  - app/datatables/admin/effective_applicants_datatable.rb
225
226
  - app/datatables/admin/effective_categories_datatable.rb
227
+ - app/datatables/admin/effective_fee_payments_datatable.rb
226
228
  - app/datatables/admin/effective_fees_datatable.rb
227
229
  - app/datatables/admin/effective_membership_histories_datatable.rb
228
230
  - app/datatables/effective_applicant_courses_datatable.rb
@@ -230,6 +232,7 @@ files:
230
232
  - app/datatables/effective_applicant_experiences_datatable.rb
231
233
  - app/datatables/effective_applicant_references_datatable.rb
232
234
  - app/datatables/effective_applicants_datatable.rb
235
+ - app/datatables/effective_fee_payments_datatable.rb
233
236
  - app/helpers/effective_memberships_helper.rb
234
237
  - app/mailers/effective/memberships_mailer.rb
235
238
  - app/models/concerns/effective_memberships_applicant.rb
@@ -274,6 +277,7 @@ files:
274
277
  - app/views/admin/categories/_form_fee_payment_content.html.haml
275
278
  - app/views/admin/categories/_form_fee_payment_steps.html.haml
276
279
  - app/views/admin/categories/_form_renewals.html.haml
280
+ - app/views/admin/fee_payments/_fee_payment.html.haml
277
281
  - app/views/admin/fees/_fee.html.haml
278
282
  - app/views/admin/fees/_form.html.haml
279
283
  - app/views/admin/memberships/_status.html.haml
@@ -318,6 +322,7 @@ files:
318
322
  - app/views/effective/applicants/submitted.html.haml
319
323
  - app/views/effective/applicants/summary.html.haml
320
324
  - app/views/effective/fee_payments/_content.html.haml
325
+ - app/views/effective/fee_payments/_dashboard.html.haml
321
326
  - app/views/effective/fee_payments/_declarations.html.haml
322
327
  - app/views/effective/fee_payments/_demographics.html.haml
323
328
  - app/views/effective/fee_payments/_demographics_fields.html.haml