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 21, 2023
1 parent 705e2a8 commit 69fde6c
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 100 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
160 changes: 102 additions & 58 deletions 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(false)
end

it 'does not show dropdown option for existing managed' do
Expand All @@ -45,10 +46,11 @@
end
end

context 'with feature toggle enabled' do
context 'with people_managers feature toggle enabled' do
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(false)
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 @@ -155,105 +159,145 @@
end

describe 'registering new managed' do
context 'with feature toggle disabled' do
context 'with people_managers 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').and_return(false)
end

it 'does not show dropdown option for new managed' do
visit group_event_path(group, event)
context 'with self_service_managed_creation feature toggle disabled' do
before do
allow(FeatureGate).to receive(:enabled?).with('people.people_managers.self_service_managed_creation').and_return(false)
end

expect(page).to_not have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
expect(page).to_not have_css('dropdown-menu a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
expect(page).to have_css('a.btn', text: /Anmelden/i, exact_text: true)
it 'does not show dropdown option for new managed' do
visit group_event_path(group, event)

expect(page).to_not have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
expect(page).to_not have_css('dropdown-menu a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
expect(page).to have_css('a.btn', text: /Anmelden/i, exact_text: true)
end
end

context 'with self_service_managed_creation feature toggle enabled' do
before do
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
visit group_event_path(group, event)

expect(page).to_not have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
expect(page).to_not have_css('dropdown-menu a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
expect(page).to have_css('a.btn', text: /Anmelden/i, exact_text: true)
end
end
end

context 'with feature toggle enabled' do
context 'with people_managers feature toggle enabled' do
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)
end

it 'shows dropdown option for new managed' do
visit group_event_path(group, event)
context 'with self_service_managed_creation feature toggle disabled' do
before do
allow(FeatureGate).to receive(:enabled?).with('people.people_managers.self_service_managed_creation').and_return(false)
end

expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
it 'does not show dropdown option for new managed' do
visit group_event_path(group, event)

expect(page).to_not have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
expect(page).to_not have_css('dropdown-menu a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
expect(page).to have_css('a.btn', text: /Anmelden/i, exact_text: true)
end
end

it 'allows you to create new managed even if you cancel before creating participation' do
visit group_event_path(group, event)
context 'with self_service_managed_creation feature toggle enabled' do
before do
allow(FeatureGate).to receive(:enabled?).with('people.people_managers.self_service_managed_creation').and_return(true)
end

expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
find('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true).click
it 'shows dropdown option for new managed' do
visit group_event_path(group, event)

contact_data_path = contact_data_managed_group_event_participations_path(group, event)
expect(current_path).to eq(contact_data_path)
expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
end

fill_in('Vorname', with: 'Bob')
fill_in('Nachname', with: 'Miller')
it 'allows you to create new managed even if you cancel before creating participation' do
visit group_event_path(group, event)

expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Person.count }.by(1)
expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
find('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true).click

new_managed = Person.last
expect(new_managed.managers).to eq([user])
contact_data_path = contact_data_managed_group_event_participations_path(group, event)
expect(current_path).to eq(contact_data_path)

expect(current_path).to eq(new_group_event_participation_path(group, event))
fill_in('Vorname', with: 'Bob')
fill_in('Nachname', with: 'Miller')

expect do
find('a.cancel').click
end.to_not change { Event::Participation.count }
expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Person.count }.by(1)

new_managed.reload
expect(new_managed).to be_present
expect(new_managed.managers).to eq([user])
new_managed = Person.last
expect(new_managed.managers).to eq([user])

expect(current_path).to eq(group_event_path(group, event))
end
expect(current_path).to eq(new_group_event_participation_path(group, event))

it 'allows you to create new managed and participation for said person' do
visit group_event_path(group, event)
expect do
find('a.cancel').click
end.to_not change { Event::Participation.count }

expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
find('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true).click
new_managed.reload
expect(new_managed).to be_present
expect(new_managed.managers).to eq([user])

contact_data_path = contact_data_managed_group_event_participations_path(group, event)
expect(current_path).to eq(contact_data_path)
expect(current_path).to eq(group_event_path(group, event))
end

fill_in('Vorname', with: 'Bob')
fill_in('Nachname', with: 'Miller')
it 'allows you to create new managed and participation for said person' do
visit group_event_path(group, event)

expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Person.count }.by(1)
expect(page).to have_css('a.dropdown-toggle', text: /Anmelden/i, exact_text: true)
find('a.dropdown-toggle', text: /Anmelden/i, exact_text: true).click
expect(page).to have_css('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true)
find('ul.dropdown-menu li a', text: /Neues Kind erfassen und anmelden/i, exact_text: true).click

new_managed = Person.last
expect(new_managed.managers).to eq([user])
contact_data_path = contact_data_managed_group_event_participations_path(group, event)
expect(current_path).to eq(contact_data_path)

expect(current_path).to eq(new_group_event_participation_path(group, event))
fill_in('Vorname', with: 'Bob')
fill_in('Nachname', with: 'Miller')

expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Event::Participation.count }.by(1)
expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Person.count }.by(1)

new_managed = Person.last
expect(new_managed.managers).to eq([user])

expect(page).to have_content(participation_success_text_for_event(event, new_managed))
expect(current_path).to eq(new_group_event_participation_path(group, event))

expect do
find_all('button.btn[type="submit"]').last.click
end.to change { Event::Participation.count }.by(1)

expect(page).to have_content(participation_success_text_for_event(event, new_managed))
end
end
end
end
end
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
Loading

0 comments on commit 69fde6c

Please sign in to comment.