From f9dc675eb8e599cdb6d585825f8a9c3b8f08ea41 Mon Sep 17 00:00:00 2001 From: Daniel Illi Date: Mon, 4 Dec 2023 14:12:31 +0100 Subject: [PATCH] Use helper method, also check people_managers feature gate --- .../managed_controller.rb | 3 +- .../youth/event/register_controller.rb | 9 ++-- .../event/register/_email_check.html.haml | 2 +- app/views/event/register/register.html.haml | 4 +- .../managed_controller_spec.rb | 52 +++++++++++++++++++ 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 spec/controllers/event/participation_contact_data/managed_controller_spec.rb diff --git a/app/controllers/event/participation_contact_data/managed_controller.rb b/app/controllers/event/participation_contact_data/managed_controller.rb index 4ba01d83..835fee10 100644 --- a/app/controllers/event/participation_contact_data/managed_controller.rb +++ b/app/controllers/event/participation_contact_data/managed_controller.rb @@ -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 diff --git a/app/controllers/youth/event/register_controller.rb b/app/controllers/youth/event/register_controller.rb index 3d054c84..e6ae16c3 100644 --- a/app/controllers/youth/event/register_controller.rb +++ b/app/controllers/youth/event/register_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/views/event/register/_email_check.html.haml b/app/views/event/register/_email_check.html.haml index e7ad9f64..478e1445 100644 --- a/app/views/event/register/_email_check.html.haml +++ b/app/views/event/register/_email_check.html.haml @@ -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)) diff --git a/app/views/event/register/register.html.haml b/app/views/event/register/register.html.haml index 9ec0bb06..98cb5f10 100644 --- a/app/views/event/register/register.html.haml +++ b/app/views/event/register/register.html.haml @@ -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) @@ -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 diff --git a/spec/controllers/event/participation_contact_data/managed_controller_spec.rb b/spec/controllers/event/participation_contact_data/managed_controller_spec.rb new file mode 100644 index 00000000..378d21ae --- /dev/null +++ b/spec/controllers/event/participation_contact_data/managed_controller_spec.rb @@ -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