Skip to content

Commit

Permalink
Use helper method, also check people_managers feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Dec 4, 2023
1 parent 681f49b commit f9dc675
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def privacy_policy_param
end

def assert_feature_enabled
FeatureGate.assert!('people.people_managers.self_service_managed_creation')
FeatureGate.assert!('people.people_managers') &&
FeatureGate.assert!('people.people_managers.self_service_managed_creation')
end
end
9 changes: 5 additions & 4 deletions app/controllers/youth/event/register_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Youth::Event::RegisterController
extend ActiveSupport::Concern

included do
helper_method :manager
helper_method :manager, :people_managers_and_self_service_enabled?

alias_method_chain :registered_notice, :manager
alias_method_chain :contact_data_class, :manager
Expand All @@ -21,7 +21,7 @@ def registered_notice_with_manager
end

def manager
@manager ||= true?(params[:manager])
@manager ||= true?(params[:manager]) && people_managers_and_self_service_enabled?
end

def contact_data_class_with_manager
Expand All @@ -32,7 +32,8 @@ def contact_data_class_with_manager
end
end

def feature_enabled?
FeatureGate.enabled?('people.people_managers.self_service_managed_creation')
def people_managers_and_self_service_enabled?
FeatureGate.enabled?('people.people_managers') &&
FeatureGate.enabled?('people.people_managers.self_service_managed_creation')
end
end
2 changes: 1 addition & 1 deletion app/views/event/register/_email_check.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
= f.honeypot(:verification)
= f.indented do
= submit_button(f, t('.next'))
- if FeatureGate.enabled?('people.people_managers') && FeatureGate.enabled?('people.people_managers.self_service_managed_creation')
- if people_managers_and_self_service_enabled?
= submit_button(f, t('.next_for_manager'), formaction: register_group_event_path(group, event, manager: true))
4 changes: 2 additions & 2 deletions app/views/event/register/register.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- title t(".title.#{manager ? 'manager' : 'participant'}")

- unless FeatureGate.enabled?('people.people_managers')
- unless people_managers_and_self_service_enabled?
= render 'event/participations/step_wizard', step: 1

- return_url = FeatureGate.enabled?('people.people_managers') ? group_event_path(group, event) : new_group_event_participation_path(group, event)
Expand All @@ -21,7 +21,7 @@
= hidden_field_tag(:manager, manager)
= hidden_field_tag(:return_url, return_url)

- if FeatureGate.enabled?('people.people_managers') && manager
- if manager
= render 'manager_fields', f: f
- else
= render 'event/participation_contact_datas/form', f: f
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of
# hitobito_youth and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_youth

require 'spec_helper'

describe Event::ParticipationContactData::ManagedController do

let(:params) { { group_id: groups(:top_layer), event_id: events(:top_event) } }

def request(method, action)
send(method, action, params: params)
end

{ get: :edit, post: :update }.each do |method, action|
context 'with people_manager feature enabled' do
before do
allow(FeatureGate).to receive(:enabled?).
with('people.people_managers').
and_return(true)
end

it "with self_service_managed_creation enabled does not raise FeatureGate error" do
expect { request(method, action) }.not_to raise_error
end

it "with self_service_managed_creation disabled raises FeatureGate error" do
expect { request(method, action) }.to raise_error(FeatureGate::FeatureDisabled)
end
end

context 'with people_manager feature disabled' do
before do
allow(FeatureGate).to receive(:enabled?).
with('people.people_managers').
and_return(false)
end

it "with self_service_managed_creation enabled raises FeatureGate error" do
expect { request(method, action) }.to raise_error(FeatureGate::FeatureDisabled)
end

it "with self_service_managed_creation disabled raises FeatureGate error" do
expect { request(method, action) }.to raise_error(FeatureGate::FeatureDisabled)
end
end
end

end

0 comments on commit f9dc675

Please sign in to comment.