effective_memberships 0.3.14 → 0.4.0

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/admin/organizations_controller.rb +19 -0
  3. data/app/controllers/admin/representatives_controller.rb +19 -0
  4. data/app/controllers/effective/applicants_controller.rb +2 -3
  5. data/app/controllers/effective/fee_payments_controller.rb +1 -2
  6. data/app/controllers/effective/organizations_controller.rb +16 -0
  7. data/app/controllers/effective/representatives_controller.rb +19 -0
  8. data/app/datatables/admin/effective_applicants_datatable.rb +10 -5
  9. data/app/datatables/admin/effective_categories_datatable.rb +7 -0
  10. data/app/datatables/admin/effective_fee_payments_datatable.rb +11 -6
  11. data/app/datatables/admin/effective_organizations_datatable.rb +31 -0
  12. data/app/datatables/admin/effective_representatives_datatable.rb +28 -0
  13. data/app/datatables/effective_applicants_datatable.rb +1 -1
  14. data/app/datatables/effective_fee_payments_datatable.rb +5 -4
  15. data/app/datatables/effective_organizations_datatable.rb +18 -0
  16. data/app/datatables/effective_representatives_datatable.rb +40 -0
  17. data/app/helpers/effective_memberships_helper.rb +25 -0
  18. data/app/mailers/effective/memberships_mailer.rb +7 -7
  19. data/app/models/concerns/effective_memberships_applicant.rb +63 -30
  20. data/app/models/concerns/effective_memberships_category.rb +32 -5
  21. data/app/models/concerns/effective_memberships_fee_payment.rb +44 -45
  22. data/app/models/concerns/effective_memberships_organization.rb +94 -0
  23. data/app/models/concerns/effective_memberships_owner.rb +0 -55
  24. data/app/models/concerns/effective_memberships_registrar.rb +2 -2
  25. data/app/models/concerns/effective_memberships_user.rb +70 -0
  26. data/app/models/effective/fee.rb +1 -1
  27. data/app/models/effective/organization.rb +8 -0
  28. data/app/models/effective/representative.rb +56 -0
  29. data/app/views/admin/categories/_form_applicant_eligibility.html.haml +1 -1
  30. data/app/views/admin/categories/_form_applicant_steps.html.haml +29 -24
  31. data/app/views/admin/categories/_form_category.html.haml +3 -0
  32. data/app/views/admin/categories/_form_renewals.html.haml +0 -2
  33. data/app/views/admin/organizations/_fields.html.haml +6 -0
  34. data/app/views/admin/organizations/_form.html.haml +31 -0
  35. data/app/views/admin/organizations/_form_organization.html.haml +23 -0
  36. data/app/views/admin/representatives/_form.html.haml +38 -0
  37. data/app/views/{effective/applicants/_demographics_fields.html.haml → admin/representatives/_user_fields.html.haml} +2 -6
  38. data/app/views/effective/applicants/_dashboard.html.haml +24 -5
  39. data/app/views/effective/applicants/_demographics.html.haml +1 -1
  40. data/app/views/effective/applicants/_missing_info.html.haml +7 -3
  41. data/app/views/effective/applicants/_organization.html.haml +9 -0
  42. data/app/views/effective/applicants/_select_organization.html.haml +21 -0
  43. data/app/views/effective/applicants/_summary.html.haml +17 -9
  44. data/app/views/effective/applicants/billing.html.haml +2 -2
  45. data/app/views/effective/applicants/demographics.html.haml +7 -6
  46. data/app/views/effective/applicants/education.html.haml +2 -2
  47. data/app/views/effective/applicants/organization.html.haml +19 -0
  48. data/app/views/effective/applicants/references.html.haml +1 -1
  49. data/app/views/effective/applicants/select.html.haml +11 -1
  50. data/app/views/effective/applicants/stamp.html.haml +2 -2
  51. data/app/views/effective/applicants/start.html.haml +17 -11
  52. data/app/views/effective/applicants/submitted.html.haml +5 -5
  53. data/app/views/effective/applicants/summary.html.haml +1 -1
  54. data/app/views/effective/fee_payments/_demographics.html.haml +1 -1
  55. data/app/views/effective/fee_payments/_organization.html.haml +9 -0
  56. data/app/views/effective/fee_payments/_summary.html.haml +39 -1
  57. data/app/views/effective/fee_payments/billing.html.haml +2 -2
  58. data/app/views/effective/fee_payments/demographics.html.haml +2 -2
  59. data/app/views/effective/fee_payments/organization.html.haml +18 -0
  60. data/app/views/effective/fee_payments/start.html.haml +20 -17
  61. data/app/views/effective/fee_payments/submitted.html.haml +10 -3
  62. data/app/views/effective/fees/_dashboard.html.haml +20 -8
  63. data/app/views/effective/memberships/_dashboard.html.haml +16 -5
  64. data/app/views/effective/organizations/_dashboard.html.haml +10 -0
  65. data/app/views/effective/organizations/_form.html.haml +8 -0
  66. data/app/views/effective/organizations/_form_organization.html.haml +11 -0
  67. data/app/views/effective/representatives/_form.html.haml +33 -0
  68. data/app/views/effective/{fee_payments/_demographics_fields.html.haml → representatives/_user_fields.html.haml} +2 -6
  69. data/app/views/organizations/_demographics.html.haml +45 -0
  70. data/app/views/organizations/_fields_demographics.html.haml +29 -0
  71. data/app/views/users/_demographics.html.haml +50 -0
  72. data/app/views/users/_fields_demographics.html.haml +29 -0
  73. data/config/effective_memberships.rb +3 -0
  74. data/config/routes.rb +9 -0
  75. data/db/migrate/01_create_effective_memberships.rb.erb +57 -10
  76. data/db/seeds.rb +18 -0
  77. data/lib/effective_memberships/engine.rb +3 -0
  78. data/lib/effective_memberships/version.rb +1 -1
  79. data/lib/effective_memberships.rb +6 -2
  80. metadata +33 -20
  81. data/app/views/effective/applicants/_demographics_owner.html.haml +0 -20
  82. data/app/views/effective/fee_payments/_demographics_owner.html.haml +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa55f7742a08e8756e0b3db669d79875ac368f92c0b0363a04975ce1aa201b13
4
- data.tar.gz: 5b664867bf6a689067f160141f0718b376b5b98f03be4dfa927ee285f295111e
3
+ metadata.gz: 223d0bdf9ce08beacd79d4fdeb3e184878bb9e9cdb8b5964aa1c4ace9f1d2735
4
+ data.tar.gz: 158b570a8dc933b247245e450c74a78c63877ece8f35a59b1e400b0fdb017b43
5
5
  SHA512:
6
- metadata.gz: 4a9dbe5ec6aec0b9fd1a5e446aa36cede071772da8bc2ac801316224b92c61fcd4807704da4c69ae65135ef48861abf82328d3ed2113970b5cf6a7a6015e3493
7
- data.tar.gz: 3b94e9838b8a70f9e18f0924ff6d8d67d9554a2c091181114d09e8a5bd714712a3daabc23a243bc3a1e373083f15c861557bcbd1a915b009225518b158daf195
6
+ metadata.gz: b8e3fe9641f2826a4df557f1817163d719bb53112a835b3a5456ea7020283f360e4bcdc99d75c1a79256f6515b2fa05f5a2c0001b6eb1ecfa988dd09eba8eb5d
7
+ data.tar.gz: 013d39152828dce9d873e1eb1f1bb9f3a42aa83fc31105e020adbd47734f42902eec0659ff661b1fd4e8bd1983a389374848847221b6aec35dcbb8bfb5552661
@@ -0,0 +1,19 @@
1
+ module Admin
2
+ class OrganizationsController < 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.Organization.deep.all }
9
+ datatable -> { EffectiveResources.best('Admin::EffectiveMembershipsDatatable').new }
10
+
11
+ private
12
+
13
+ def permitted_params
14
+ model = (params.key?(:effective_organization) ? :effective_organization : :organization)
15
+ params.require(model).permit!
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Admin
2
+ class RepresentativesController < 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 -> { Effective::Representative.deep.all }
9
+ datatable -> { Admin::EffectiveRepresentativesDatatable.new }
10
+
11
+ private
12
+
13
+ def permitted_params
14
+ model = (params.key?(:effective_representative) ? :effective_representative : :representative)
15
+ params.require(model).permit!
16
+ end
17
+
18
+ end
19
+ end
@@ -4,9 +4,8 @@ module Effective
4
4
 
5
5
  include Effective::WizardController
6
6
 
7
- resource_scope -> { EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owners) }
8
-
9
- submit :resubmit, 'Submit Application'
7
+ resource_scope -> { EffectiveMemberships.Applicant.deep.where(user: current_user) }
10
8
 
9
+ submit :resubmit, 'Resubmit Application'
11
10
  end
12
11
  end
@@ -4,7 +4,6 @@ module Effective
4
4
 
5
5
  include Effective::WizardController
6
6
 
7
- resource_scope -> { EffectiveMemberships.FeePayment.deep.where(owner: current_user.effective_memberships_owners) }
8
-
7
+ resource_scope -> { EffectiveMemberships.FeePayment.deep.where(user: current_user) }
9
8
  end
10
9
  end
@@ -0,0 +1,16 @@
1
+ module Effective
2
+ class OrganizationsController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+
5
+ include Effective::CrudController
6
+
7
+ resource_scope -> { EffectiveMemberships.Organization.deep.where(id: current_user.organizations) }
8
+
9
+ private
10
+
11
+ def permitted_params
12
+ params.require(:organization).permit!
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module Effective
2
+ class RepresentativesController < ApplicationController
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+
5
+ include Effective::CrudController
6
+
7
+ resource_scope -> {
8
+ organizations = EffectiveMemberships.Organization.deep.where(id: current_user.organizations)
9
+ Effective::Representative.deep.where(organization: organizations)
10
+ }
11
+
12
+ private
13
+
14
+ def permitted_params
15
+ params.require(:effective_representative).permit!
16
+ end
17
+
18
+ end
19
+ end
@@ -26,7 +26,8 @@ module Admin
26
26
 
27
27
  col :approved_at, label: 'Approved', visible: false, as: :date
28
28
 
29
- col :owner
29
+ col :user
30
+ col :organization
30
31
 
31
32
  col :applicant_type
32
33
  col :category, search: { collection: EffectiveMemberships.Category.all, polymorphic: false }
@@ -40,14 +41,18 @@ module Admin
40
41
  collection do
41
42
  applicants = EffectiveMemberships.Applicant.deep.all
42
43
 
43
- raise('expected an owner_id, not user_id') if attributes[:user_id].present?
44
+ raise('expected a user_id or organization_id, not owner_id') if attributes[:owner_id].present?
44
45
 
45
- if scope == :in_progress && attributes[:owner_id].blank?
46
+ if scope == :in_progress && attributes[:user_id].blank? && attributes[:organization_id].blank?
46
47
  applicants = applicants.where.not(status: :draft)
47
48
  end
48
49
 
49
- if attributes[:owner_id].present?
50
- applicants = applicants.where(owner_id: attributes[:owner_id])
50
+ if attributes[:user_id].present?
51
+ applicants = applicants.where(user_id: attributes[:owner_id])
52
+ end
53
+
54
+ if attributes[:organization_id].present?
55
+ applicants = applicants.where(organization_id: attributes[:organization_id])
51
56
  end
52
57
 
53
58
  if attributes[:except_id].present?
@@ -8,13 +8,20 @@ module Admin
8
8
  col :id, visible: false
9
9
 
10
10
  col :title
11
+ col :can_apply_new, label: 'Can Apply'
11
12
  col :applicant_fee, as: :price
13
+
12
14
  col :renewal_fee, as: :price
13
15
  col :late_fee, as: :price
14
16
  col :rich_text_body, label: 'Body'
15
17
  col :tax_exempt
16
18
  col :qb_item_name, visible: false
17
19
 
20
+ col :category_type, search: EffectiveMemberships.Category.category_types
21
+
22
+ col :optional_applicant_wizard_steps, label: 'Applicant Steps'
23
+ col :optional_fee_payment_wizard_steps, label: 'Fee Payment Steps'
24
+
18
25
  actions_col
19
26
  end
20
27
 
@@ -18,7 +18,8 @@ module Admin
18
18
  col :period, visible: false
19
19
  col :submitted_at, label: 'Submitted', visible: false, as: :date
20
20
 
21
- col :owner
21
+ col :user
22
+ col :organization
22
23
 
23
24
  col :category, search: { collection: EffectiveMemberships.Category.all, polymorphic: false }
24
25
 
@@ -27,17 +28,21 @@ module Admin
27
28
  actions_col
28
29
  end
29
30
 
30
- collection do
31
+ collection(apply_belongs_to: false) do
31
32
  fee_payments = EffectiveMemberships.FeePayment.deep.all
32
33
 
33
- raise('expected an owner_id, not user_id') if attributes[:user_id].present?
34
+ raise('expected an user_id but was given an owner_id') if attributes[:owner_id].present?
34
35
 
35
- if fee_payments == :in_progress && attributes[:owner_id].blank?
36
+ if fee_payments == :in_progress && attributes[:user_id].blank? && attributes[:organization_id].blank?
36
37
  fee_payments = fee_payments.where.not(status: :draft)
37
38
  end
38
39
 
39
- if attributes[:owner_id].present?
40
- fee_payments = fee_payments.where(owner_id: attributes[:owner_id])
40
+ if attributes[:user_id].present?
41
+ fee_payments = fee_payments.where(user_id: attributes[:user_id])
42
+ end
43
+
44
+ if attributes[:organization_id].present?
45
+ fee_payments = fee_payments.where(organization_id: attributes[:organization_id])
41
46
  end
42
47
 
43
48
  if attributes[:except_id].present?
@@ -0,0 +1,31 @@
1
+ module Admin
2
+ class EffectiveOrganizationsDatatable < Effective::Datatable
3
+ datatable do
4
+
5
+ col :updated_at, visible: false
6
+ col :created_at, visible: false
7
+
8
+ col :id, visible: false
9
+
10
+ if categories.present?
11
+ col :category, search: categories
12
+ end
13
+
14
+ col :title
15
+
16
+ col :representatives_count
17
+ col :representatives
18
+
19
+ actions_col
20
+ end
21
+
22
+ collection do
23
+ EffectiveMemberships.Organization.deep.all
24
+ end
25
+
26
+ def categories
27
+ EffectiveMemberships.Organization.categories
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module Admin
2
+ class EffectiveRepresentativesDatatable < Effective::Datatable
3
+ datatable do
4
+ col :id, visible: false
5
+ col :user_id, visible: false
6
+
7
+ col :organization
8
+ col :user
9
+
10
+ col :email do |representative|
11
+ mail_to(representative.user.email)
12
+ end
13
+
14
+ col :roles, search: roles_collection
15
+
16
+ actions_col
17
+ end
18
+
19
+ collection do
20
+ Effective::Representative.deep.all
21
+ end
22
+
23
+ def roles_collection
24
+ EffectiveRoles.roles_collection(Effective::Representative.new).map(&:second)
25
+ end
26
+
27
+ end
28
+ end
@@ -34,7 +34,7 @@ class EffectiveApplicantsDatatable < Effective::Datatable
34
34
  end
35
35
 
36
36
  collection do
37
- EffectiveMemberships.Applicant.deep.where(owner: current_user.effective_memberships_owners)
37
+ EffectiveMemberships.Applicant.deep.for(current_user)
38
38
  end
39
39
 
40
40
  end
@@ -6,7 +6,9 @@ class EffectiveFeePaymentsDatatable < Effective::Datatable
6
6
  col :token, visible: false
7
7
  col :created_at, visible: false
8
8
 
9
- col :owner
9
+ col :user
10
+ col :organization
11
+
10
12
  col :status, visible: false
11
13
  col :submitted_at, label: 'Submitted', as: :date
12
14
  col :period, visible: false
@@ -16,9 +18,8 @@ class EffectiveFeePaymentsDatatable < Effective::Datatable
16
18
  actions_col(new: false)
17
19
  end
18
20
 
19
- collection do
20
- EffectiveMemberships.FeePayment.deep.done
21
- .where(owner: current_user.effective_memberships_owners)
21
+ collection(apply_belongs_to: false) do
22
+ scope = EffectiveMemberships.FeePayment.deep.done.for(current_user)
22
23
  end
23
24
 
24
25
  end
@@ -0,0 +1,18 @@
1
+ # Dashboard Organizations
2
+ class EffectiveOrganizationsDatatable < Effective::Datatable
3
+ datatable do
4
+ order :title
5
+
6
+ col :id, visible: false
7
+
8
+ col :title
9
+ col :representatives
10
+
11
+ actions_col
12
+ end
13
+
14
+ collection do
15
+ EffectiveMemberships.Organization.deep.where(id: current_user.organizations)
16
+ end
17
+
18
+ end
@@ -0,0 +1,40 @@
1
+ class EffectiveRepresentativesDatatable < Effective::Datatable
2
+ datatable do
3
+ col :id, visible: false
4
+
5
+ col :organization
6
+ col :user
7
+
8
+ unless attributes[:user_id]
9
+ col :email do |representative|
10
+ mail_to(representative.user.email)
11
+ end
12
+ end
13
+
14
+ col :roles, search: roles_collection
15
+
16
+ unless attributes[:actions] == false
17
+ actions_col
18
+ end
19
+
20
+ end
21
+
22
+ collection do
23
+ scope = Effective::Representative.deep.all.where(organization: current_user.organizations)
24
+
25
+ if attributes[:organization_id]
26
+ scope = scope.where(organization_id: attributes[:organization_id])
27
+ end
28
+
29
+ if attributes[:user_id]
30
+ scope = scope.where(user_id: attributes[:user_id])
31
+ end
32
+
33
+ scope
34
+ end
35
+
36
+ def roles_collection
37
+ EffectiveRoles.roles_collection(Effective::Representative.new).map(&:second)
38
+ end
39
+
40
+ end
@@ -8,4 +8,29 @@ module EffectiveMembershipsHelper
8
8
  end.compact
9
9
  end
10
10
 
11
+ def effective_memberships_select_applicant_organization_collection(resource)
12
+ user = (resource.respond_to?(:user) ? resource.user : resource)
13
+ raise('expected an effective memberships user') unless user.class.try(:effective_memberships_user?)
14
+
15
+ representatives = user.representatives.select { |rep| rep.is?(:owner) || rep.is?(:billing) }
16
+ organizations = representatives.map { |rep| [rep.organization.to_s, rep.organization.id] }
17
+
18
+ organizations + [['New Organization...', 'new']]
19
+ end
20
+
21
+ # This is the select yourself or organization field on FeePayments#start
22
+ def effective_memberships_select_fee_payment_organization(resource)
23
+ user = (resource.respond_to?(:user) ? resource.user : resource)
24
+ raise('expected an effective memberships user') unless user.class.try(:effective_memberships_user?)
25
+
26
+ owners = user.memberships_owners.select { |owner| owner.outstanding_fee_payment_fees.present? }
27
+
28
+ owners.map do |owner|
29
+ [
30
+ owner.to_s,
31
+ (owner.to_param if owner.kind_of?(EffectiveMemberships.Organization)) # Nil when user
32
+ ]
33
+ end
34
+ end
35
+
11
36
  end
@@ -11,7 +11,7 @@ module Effective
11
11
  subject = subject_for(__method__, 'Applicant Completed', resource, opts)
12
12
  headers = headers_for(resource, opts)
13
13
 
14
- mail(to: resource.owner.email, subject: subject, **headers)
14
+ mail(to: resource.user.email, subject: subject, **headers)
15
15
  end
16
16
 
17
17
  def applicant_missing_info(resource, opts = {})
@@ -21,7 +21,7 @@ module Effective
21
21
  subject = subject_for(__method__, 'Applicant Missing Info', resource, opts)
22
22
  headers = headers_for(resource, opts)
23
23
 
24
- mail(to: resource.owner.email, subject: subject, **headers)
24
+ mail(to: resource.user.email, subject: subject, **headers)
25
25
  end
26
26
 
27
27
  def applicant_approved(resource, opts = {})
@@ -31,7 +31,7 @@ module Effective
31
31
  subject = subject_for(__method__, 'Applicant Approved', resource, opts)
32
32
  headers = headers_for(resource, opts)
33
33
 
34
- mail(to: resource.owner.email, subject: subject, **headers)
34
+ mail(to: resource.user.email, subject: subject, **headers)
35
35
  end
36
36
 
37
37
  def applicant_declined(resource, opts = {})
@@ -41,7 +41,7 @@ module Effective
41
41
  subject = subject_for(__method__, 'Applicant Declined', resource, opts)
42
42
  headers = headers_for(resource, opts)
43
43
 
44
- mail(to: resource.owner.email, subject: subject, **headers)
44
+ mail(to: resource.user.email, subject: subject, **headers)
45
45
  end
46
46
 
47
47
  def applicant_reference_notification(resource, opts = {})
@@ -58,11 +58,11 @@ module Effective
58
58
 
59
59
  def assigns_for(resource)
60
60
  if resource.class.respond_to?(:effective_memberships_applicant?)
61
- return applicant_assigns(resource).merge(user_assigns(resource.owner))
61
+ return applicant_assigns(resource).merge(owner_assigns(resource.owner))
62
62
  end
63
63
 
64
64
  if resource.kind_of?(Effective::ApplicantReference)
65
- return reference_assigns(resource).merge(user_assigns(resource.applicant.owner))
65
+ return reference_assigns(resource).merge(owner_assigns(resource.applicant.owner))
66
66
  end
67
67
 
68
68
  raise('unexpected resource')
@@ -99,7 +99,7 @@ module Effective
99
99
  { reference: values }
100
100
  end
101
101
 
102
- def user_assigns(owner)
102
+ def owner_assigns(owner)
103
103
  raise('expected a owner') unless owner.class.respond_to?(:effective_memberships_owner?)
104
104
 
105
105
  values = {
@@ -44,7 +44,8 @@ module EffectiveMembershipsApplicant
44
44
  acts_as_wizard(
45
45
  start: 'Start',
46
46
  select: 'Select Application Type',
47
- demographics: 'Demographics',
47
+ demographics: 'Demographics', # Individual only. Users fields.
48
+ organization: 'Organization', # Organization only. Organization fields.
48
49
  education: 'Education',
49
50
  course_amounts: 'Courses',
50
51
  experience: 'Work Experience',
@@ -73,8 +74,11 @@ module EffectiveMembershipsApplicant
73
74
  attr_accessor :approved_membership_date
74
75
 
75
76
  # Application Namespace
76
- belongs_to :owner, polymorphic: true
77
- accepts_nested_attributes_for :owner
77
+ belongs_to :user, polymorphic: true
78
+ accepts_nested_attributes_for :user
79
+
80
+ belongs_to :organization, polymorphic: true, optional: true
81
+ accepts_nested_attributes_for :organization
78
82
 
79
83
  belongs_to :category, polymorphic: true, optional: true
80
84
  belongs_to :from_category, polymorphic: true, optional: true
@@ -142,7 +146,7 @@ module EffectiveMembershipsApplicant
142
146
  timestamps
143
147
  end
144
148
 
145
- scope :deep, -> { includes(:owner, :category, :from_category, :orders) }
149
+ scope :deep, -> { includes(:user, :organization, :category, :from_category, :orders) }
146
150
  scope :sorted, -> { order(:id) }
147
151
 
148
152
  scope :in_progress, -> { where.not(status: [:approved, :declined]) }
@@ -150,14 +154,15 @@ module EffectiveMembershipsApplicant
150
154
 
151
155
  scope :not_draft, -> { where.not(status: :draft) }
152
156
 
153
- # Set Apply to Join or Reclassification
154
- before_validation(if: -> { new_record? && owner.present? }) do
155
- self.applicant_type ||= (owner.membership.blank? ? 'Apply to Join' : 'Apply to Reclassify')
156
- self.from_category ||= owner.membership&.category
157
- end
157
+ scope :for, -> (user) {
158
+ raise('expected a effective memberships user') unless user.class.try(:effective_memberships_user?)
159
+ where(user: user).or(where(organization: user.organizations))
160
+ }
158
161
 
159
- before_validation(if: -> { current_step == :select && category_id.present? }) do
160
- self.category_type ||= EffectiveMemberships.Category.name
162
+ # Set Apply to Join or Reclassification
163
+ before_validation(if: -> { (new_record? || current_step == :select) && owner.present? }) do
164
+ self.applicant_type = (owner.membership.blank? ? 'Apply to Join' : 'Apply to Reclassify')
165
+ self.from_category = owner.membership&.category
161
166
  end
162
167
 
163
168
  before_validation(if: -> { current_step == :experience }) do
@@ -165,18 +170,16 @@ module EffectiveMembershipsApplicant
165
170
  end
166
171
 
167
172
  # All Steps validations
168
- validates :owner, presence: true
173
+ validates :user, presence: true
169
174
  validates :from_category, presence: true, if: -> { reclassification? }
170
175
 
171
176
  validate(if: -> { reclassification? }) do
172
177
  errors.add(:category_id, "can't reclassify to existing category") if category_id == from_category_id
173
178
  end
174
179
 
175
- # Start Step
176
- with_options(if: -> { current_step == :start && owner.present? }) do
177
- validate do
178
- errors.add(:base, 'may not have outstanding fees') if owner.outstanding_fee_payment_fees.present?
179
- end
180
+ validate(if: -> { category.present? }) do
181
+ self.errors.add(:organization_id, "can't be blank when organization category") if category.organization? && organization.blank?
182
+ self.errors.add(:organization_id, "must be blank when individual category") if category.individual? && organization.present?
180
183
  end
181
184
 
182
185
  # Select Step
@@ -185,6 +188,10 @@ module EffectiveMembershipsApplicant
185
188
  validates :category, presence: true
186
189
  end
187
190
 
191
+ validate(if: -> { current_step == :select && owner.present? }) do
192
+ self.errors.add(:base, 'may not have outstanding fees') if owner.outstanding_fee_payment_fees.present?
193
+ end
194
+
188
195
  # Applicant Educations Step
189
196
  with_options(if: -> { current_step == :education }) do
190
197
  validate do
@@ -291,6 +298,14 @@ module EffectiveMembershipsApplicant
291
298
 
292
299
  # Special logic for stamp step
293
300
  applicant_steps.delete(:stamp) unless apply_to_join?
301
+ applicant_steps.delete(:organization) unless category&.organization?
302
+
303
+ # change_wizard_steps is defined in effective_resources acts_as_wizard
304
+ applicant_steps = change_wizard_steps(applicant_steps)
305
+
306
+ unless applicant_steps.kind_of?(Array) && applicant_steps.all? { |step| step.kind_of?(Symbol) }
307
+ raise('expected change_wizard_steps to return an Array of steps with no nils')
308
+ end
294
309
 
295
310
  wizard_steps.select do |step|
296
311
  required_steps.include?(step) || category.blank? || applicant_steps.include?(step)
@@ -370,6 +385,18 @@ module EffectiveMembershipsApplicant
370
385
  end
371
386
  end
372
387
 
388
+ def owner
389
+ organization || user
390
+ end
391
+
392
+ def owner_symbol
393
+ organization? ? :organization : :user
394
+ end
395
+
396
+ def build_organization(params = {})
397
+ self.organization = EffectiveMemberships.Organization.new(params)
398
+ end
399
+
373
400
  def apply_to_join?
374
401
  applicant_type == 'Apply to Join'
375
402
  end
@@ -378,8 +405,12 @@ module EffectiveMembershipsApplicant
378
405
  applicant_type == 'Apply to Reclassify'
379
406
  end
380
407
 
381
- def owner_label
382
- owner_type.to_s.split('::').last
408
+ def individual?
409
+ !(owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?)
410
+ end
411
+
412
+ def organization?
413
+ owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?
383
414
  end
384
415
 
385
416
  def in_progress?
@@ -399,9 +430,11 @@ module EffectiveMembershipsApplicant
399
430
  when 'draft'
400
431
  "Applicant has not yet completed the #{category} wizard steps or paid to submit this application. This application will transition to 'submitted' after payment has been collected."
401
432
  when 'submitted'
402
- summary = "Application has been purchased and submitted. The following tasks must be done before this application will transition to 'completed':"
433
+ summary = "Application has been purchased and submitted."
434
+ tasks = "The following tasks remain before it can be completed:"
435
+ approval = "Waiting on approval."
403
436
  items = completed_requirements.map { |item, done| "<li>#{item}: #{done ? 'Complete' : 'Incomplete'}</li>" }.join
404
- "<p>#{summary}</p><ul>#{items}</ul>"
437
+ completed_requirements.present? ? "<p>#{summary} #{tasks}</p><ul>#{items}</ul>" : "#{summary} #{approval}"
405
438
  when 'completed'
406
439
  if applicant_reviews_required?
407
440
  "All required materials have been provided. This application will transition to 'reviewed' after all reviewers have voted."
@@ -425,11 +458,11 @@ module EffectiveMembershipsApplicant
425
458
  def can_apply_categories_collection
426
459
  categories = EffectiveMemberships.Category.sorted.can_apply
427
460
 
428
- if owner.blank? || owner.membership.blank?
461
+ if user.blank? || !user.is?(:member)
429
462
  return categories.where(can_apply_new: true)
430
463
  end
431
464
 
432
- category_ids = owner.membership.category_ids
465
+ category_ids = user.memberships.map(&:category_ids).flatten
433
466
 
434
467
  categories.select do |cat|
435
468
  cat.can_apply_existing? ||
@@ -503,10 +536,6 @@ module EffectiveMembershipsApplicant
503
536
  )
504
537
  end
505
538
 
506
- # The submit! method used to be here
507
- # But it needs to be inside the included do block
508
- # So see above. Sorry.
509
-
510
539
  def applicant_references_required?
511
540
  min_applicant_references > 0
512
541
  end
@@ -514,9 +543,13 @@ module EffectiveMembershipsApplicant
514
543
  # When an application is submitted, these must be done to go to completed.
515
544
  # An Admin can override this and just set them to completed.
516
545
  def completed_requirements
517
- {
518
- 'Applicant References' => (!applicant_references_required? || applicant_references.count(&:completed?) >= min_applicant_references)
519
- }
546
+ if category&.applicant_wizard_steps&.include?(:references) || applicant_references_required?
547
+ {
548
+ 'Applicant References' => (!applicant_references_required? || applicant_references.count(&:completed?) >= min_applicant_references)
549
+ }
550
+ else
551
+ {}
552
+ end
520
553
  end
521
554
 
522
555
  def complete!