Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi authored and amaierhofer committed Dec 18, 2024
1 parent fa031a7 commit f86b1ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
34 changes: 10 additions & 24 deletions app/models/wizards/signup/abo_basic_login_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ class AboBasicLoginWizard < Wizards::RegisterNewUserWizard

public :group

delegate :email, to: :main_email_field
delegate :newsletter, to: :person_fields

self.asides = ["aside_abo_basic_login"]

def member_or_applied?
current_user.login? #do not allow if person already has a login
end

def save!
if current_user.present?
if current_user
person.save!
else
super
Expand All @@ -32,37 +35,20 @@ def save!
private

def build_person
if current_user.present?
current_user.tap do |person|
person.roles.build(group: group, type: group.self_registration_role_type)
end
else
super do |_person, role|
role.end_on = Date.current.end_of_year
end
super do |_person, role|
role.end_on = Date.current.end_of_year
end
end

def person_attributes
person_fields
.person_attributes
.merge(main_email_field.attributes)
person_fields.person_attributes.merge(email:)
end

def step_after(step_class_or_name)
case step_class_or_name
when :_start
handle_start
else
super
end
end

def handle_start
if current_user.present?
if step_class_or_name == :_start && current_user
Wizards::Steps::Signup::AboBasicLogin::PersonFields.step_name
else
Wizards::Steps::Signup::MainEmailField.step_name
super
end
end

Expand Down
10 changes: 10 additions & 0 deletions app/models/wizards/signup/abo_magazin_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ class AboMagazinWizard < AboBasicLoginWizard

self.asides = ["aside_abo"]

RESTRICTED_ROLES = [
Group::AboMagazin::Abonnent.sti_name,
Group::AboMagazin::Neuanmeldung.sti_name,
Group::AboMagazin::Gratisabonnent.sti_name
].freeze

delegate :newsletter, to: :summary

def member_or_applied?
current_user&.roles&.map(&:type)&.any? { |type| RESTRICTED_ROLES.include?(type) }
end

def costs = SacCas::ABO_COSTS[:magazin]

def requires_policy_acceptance? = false
Expand Down
9 changes: 9 additions & 0 deletions app/models/wizards/signup/abo_touren_portal_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class AboTourenPortalWizard < AboBasicLoginWizard

self.asides = ["aside_abo"]

RESTRICTED_ROLES = [
Group::AboTourenPortal::Abonnent.sti_name,
Group::AboTourenPortal::Neuanmeldung.sti_name
].freeze

def member_or_applied?
current_user&.roles&.map(&:type)&.any? { |type| RESTRICTED_ROLES.include?(type) }
end

def costs = SacCas::ABO_COSTS[:tourenportal]
end
end
5 changes: 3 additions & 2 deletions app/models/wizards/signup/sektion_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class SektionWizard < Wizards::RegisterNewUserWizard

public :group

def email
current_user&.email || step(:main_email_field)&.email
def member_or_applied?
current_user&.sac_membership&.stammsektion_role ||
current_user&.sac_membership&.neuanmeldung_stammsektion_role
end

def save!
Expand Down

0 comments on commit f86b1ec

Please sign in to comment.