Skip to content

Commit

Permalink
PEOPLE: SAC entry wizard for existing users (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
Largo committed Oct 2, 2024
1 parent 0e3a967 commit 25b5bf9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
21 changes: 18 additions & 3 deletions app/controllers/sac_cas/groups/self_registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ module SacCas::Groups::SelfRegistrationController
delegate :email, to: :wizard

def create
return super unless person
return redirect_to_login if person && !signed_in?
return redirect_to_memberships_tab if member_or_applied?

redirect_to_login
super
end

def member_or_applied?
current_user.sac_membership.stammsektion_role ||
current_user.sac_membership.neuanmeldung_stammsektion_role
end

private
Expand All @@ -38,7 +44,7 @@ def person
end

def redirect_to_login
store_location_for(person, group_self_inscription_path(group))
store_location_for(person, group_self_registration_path(group))

path = new_person_session_path(person: {login_identity: email})
notice = t("groups.self_registration.create.redirect_existing_email")
Expand All @@ -48,4 +54,13 @@ def redirect_to_login
flash[:notice] = notice
render js: "window.location='#{path}';"
end

def redirect_to_memberships_tab
flash[:notice] = t("groups.self_registration.create.existing_membership_notice")
redirect_to history_group_person_path(group_id: current_user.primary_group_id, id: current_user.id)
end

def redirect_to_group_if_necessary
redirect_to group_path(group) unless group.self_registration_active?
end
end
10 changes: 3 additions & 7 deletions app/models/wizards/signup/sektion_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module Wizards::Signup
class SektionOperation
include ActiveModel::Model

def initialize(group:, person_attrs:, newsletter:)
def initialize(group:, person:, newsletter:)
@group = group
@person_attrs = person_attrs
@person = person
@newsletter = newsletter
end

Expand Down Expand Up @@ -40,7 +40,7 @@ def save!

private

attr_reader :group, :person_attrs, :newsletter
attr_reader :group, :person, :newsletter

def validate(model)
model.valid?.tap do
Expand All @@ -58,10 +58,6 @@ def paying_person?
role.person.sac_membership.paying_person?(role.beitragskategorie)
end

def person
@person ||= Person.new(person_attrs)
end

def role
@role ||= build_role
end
Expand Down
23 changes: 20 additions & 3 deletions app/models/wizards/signup/sektion_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ class SektionWizard < Wizards::RegisterNewUserWizard
MIN_ADULT_YEARS = SacCas::Beitragskategorie::Calculator::AGE_RANGE_ADULT.begin
ADDRESS_KEYS = %i[address_care_of street housenumber postbox zip_code town country]

delegate :email, to: :main_email_field
delegate :person_attributes, :birthday, to: :person_fields
delegate :self_registration_reason_id, to: :various_fields
delegate :newsletter, :privacy_policy_accepted_at, to: :summary_fields

def build_person
return current_user.tap { |user| user.assign_attributes(person_attributes) } if current_user.persisted?

super
end

def email
current_user&.email || step(:main_email_field)&.email
end

public :group

def save!
Expand All @@ -41,7 +50,13 @@ def birthdays

def operations
@operation ||= people_attrs.map do |person_attrs|
SektionOperation.new(person_attrs:, group:, newsletter:)
person = if person_attrs[:sac_family_main_person] && current_user.persisted?
current_user
else
Person.new(person_attrs)
end

SektionOperation.new(person:, group:, newsletter:)
end
end

Expand Down Expand Up @@ -85,7 +100,9 @@ def read_birthdays
end

def step_after(step_name_or_class)
if step_name_or_class == Wizards::Steps::Signup::Sektion::PersonFields && too_young_for_household?
if current_user.persisted?
Wizards::Steps::Signup::Sektion::PersonFields.step_name
elsif step_name_or_class == Wizards::Steps::Signup::Sektion::PersonFields && too_young_for_household?
Wizards::Steps::Signup::Sektion::VariousFields.step_name
else
super
Expand Down
1 change: 1 addition & 0 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ de:
international: Weltweit
create:
redirect_existing_email: Es existiert bereits ein Login für diese E-Mail. Melde dich hier an.
existing_membership_notice: Du besitzt bereits eine SAC-Mitgliedschaft. Wenn du diese anpassen möchtest, kontaktiere bitte die SAC Geschäftsstelle.

agreement_link:
statutes_text: Ich habe die %{link} gelesen und stimme diesen zu
Expand Down

0 comments on commit 25b5bf9

Please sign in to comment.