Skip to content

Commit

Permalink
Add feature gate for new managed register
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek committed Nov 20, 2023
1 parent 44e4a45 commit afaa176
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Event::ParticipationContactData::ManagedController <
Event::ParticipationContactDatasController

before_action :assert_feature_enabled

def update
if any_duplicates?
entry.errors.add(:base, :duplicates_present) if any_duplicates?
Expand Down Expand Up @@ -44,4 +46,8 @@ def person_duplicate_finder
def privacy_policy_param
params[:event_participation_contact_datas_managed][:privacy_policy_accepted]
end

def assert_feature_enabled
FeatureGate.assert!(:'people.people_managers.self_service_managed_creation')
end
end
4 changes: 4 additions & 0 deletions app/controllers/youth/event/register_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ def contact_data_class_with_manager
Event::ParticipationContactData
end
end

def feature_enabled?
FeatureGate.enabled?('people.people_managers.self_service_managed_creation')
end
end
7 changes: 6 additions & 1 deletion app/helpers/youth/dropdown/event/participant_add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def init_items_with_manageds(url_options)
end
end

if event.external_applications?
if register_new_managed?
opts = url_options.merge(event_role: { type: event.participant_types.first.sti_name })
add_item(
translate('.register_new_managed'),
Expand Down Expand Up @@ -104,6 +104,11 @@ def participant_types_sub_items(opts)
::Dropdown::Item.new(translate(:as, role: type.label), link)
end
end

def register_new_managed?
event.external_applications? &&
FeatureGate.enabled?(:'people.people_managers.self_service_managed_creation')
end
end
end
end
Expand Down
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'))
- FeatureGate.if('people.people_managers') do
- if FeatureGate.enabled?('people.people_managers') && FeatureGate.enabled?('people.people_managers.self_service_managed_creation')
= submit_button(f, t('.next_for_manager'), formaction: register_group_event_path(group, event, manager: true))
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
people:
people_managers:
enabled: true
self_service_managed_creation:
enabled: true
8 changes: 7 additions & 1 deletion spec/features/event_register_managed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(false)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
end

it 'does not show dropdown option for existing managed' do
Expand All @@ -49,6 +50,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(true)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
end

it 'shows dropdown option for existing managed' do
Expand Down Expand Up @@ -106,6 +108,7 @@
context 'with feature toggle disabled' do
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(false)
end

Expand All @@ -120,6 +123,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(true)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
end

it 'shows invitation for existing managed' do
Expand Down Expand Up @@ -159,6 +163,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(false)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
end

it 'does not show dropdown option for new managed' do
Expand All @@ -174,6 +179,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(true)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
end

it 'shows dropdown option for new managed' do
Expand Down Expand Up @@ -253,7 +259,7 @@
end

def attrs_for_event_type(type)
attrs = { application_opening_at: 5.days.ago, groups: [group], globally_visible: false }
attrs = { application_opening_at: 5.days.ago, groups: [group], globally_visible: false, external_applications: true }
case type
when :course
attrs.merge!(state: :application_open)
Expand Down
2 changes: 2 additions & 0 deletions spec/features/external_event_register_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
before do
allow(FeatureGate).to receive(:enabled?).with('groups.self_registration').and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(false)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
allow_any_instance_of(FeatureGate).to receive(:enabled?).and_return(false)
end

Expand All @@ -33,6 +34,7 @@
allow(FeatureGate).to receive(:enabled?).with(:self_registration_reason).and_return(false)
allow(FeatureGate).to receive(:enabled?).with('groups.self_registration').and_return(false)
allow(FeatureGate).to receive(:enabled?).with('people.people_managers').and_return(true)
allow(FeatureGate).to receive(:enabled?).with(:'people.people_managers.self_service_managed_creation').and_return(true)
allow_any_instance_of(FeatureGate).to receive(:enabled?).and_return(true)
CustomContent.create!(key: 'views/devise/sessions/info', label: 'foo', body: 'dummy custom content has to be created because the youth wagon does not have built-in custom content fixtures')
end
Expand Down

0 comments on commit afaa176

Please sign in to comment.