From 03f795167637978d5f442a9a5f0d05fe34148012 Mon Sep 17 00:00:00 2001 From: James Mason Date: Thu, 18 Oct 2018 12:01:42 -0700 Subject: [PATCH] Add a switch for allowing registration on events (proposals) --- app/controllers/admin/cfps_controller.rb | 6 +++++- app/views/admin/cfps/_form.html.haml | 5 +++++ app/views/proposals/_proposal_form.html.haml | 9 +++++---- app/views/proposals/new.html.haml | 3 ++- .../20181017183243_add_allow_reservations_on_cfps.rb | 5 +++++ db/schema.rb | 6 ++++-- spec/factories/cfps.rb | 1 + spec/features/commercials_spec.rb | 1 + spec/features/proposals_spec.rb | 1 + spec/features/versions_spec.rb | 2 +- 10 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20181017183243_add_allow_reservations_on_cfps.rb diff --git a/app/controllers/admin/cfps_controller.rb b/app/controllers/admin/cfps_controller.rb index 5751797b..fab49f2f 100644 --- a/app/controllers/admin/cfps_controller.rb +++ b/app/controllers/admin/cfps_controller.rb @@ -57,7 +57,11 @@ module Admin private def cfp_params - params.require(:cfp).permit(:start_date, :end_date, :description, :cfp_type) + params.require(:cfp).permit( + :start_date, :end_date, + :description, :cfp_type, + :enable_registrations + ) end def cfp_params_or_first_remaining_type diff --git a/app/views/admin/cfps/_form.html.haml b/app/views/admin/cfps/_form.html.haml index c7113ff1..178b9033 100644 --- a/app/views/admin/cfps/_form.html.haml +++ b/app/views/admin/cfps/_form.html.haml @@ -18,6 +18,11 @@ readonly: 'readonly' } = f.input :description, hint: markdown_hint, input_html: { rows: 2, data: { provide: 'markdown-editable' } } + - if cfp.cfp_type == 'events' + = f.input :enable_registrations, as: :boolean, + hint: 'Allow submitters to request registration?' + - else + = f.input :enable_registrations, as: :hidden %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/proposals/_proposal_form.html.haml b/app/views/proposals/_proposal_form.html.haml index 1b642d94..9629e82d 100644 --- a/app/views/proposals/_proposal_form.html.haml +++ b/app/views/proposals/_proposal_form.html.haml @@ -43,10 +43,11 @@ 250 words. - = f.inputs 'Enable pre-registration' do - = f.input :require_registration, label: 'Require participants to register to your event' - - message = @event.room ? "Value must be between 1 and #{@event.room.size}" : 'Check room capacity after scheduling.' - = f.input :max_attendees, hint: 'The maximum number of participants. ' + message + - if @program.cfp.enable_registrations? + = f.inputs 'Enable pre-registration' do + = f.input :require_registration, label: 'Require participants to register to your event' + - message = @event.room ? "Value must be between 1 and #{@event.room.size}" : 'Check room capacity after scheduling.' + = f.input :max_attendees, hint: 'The maximum number of participants. ' + message - if current_user.has_any_role? :admin, { name: :organizer, resource: @conference }, { name: :cfp, resource: @conference } = f.input :is_highlight diff --git a/app/views/proposals/new.html.haml b/app/views/proposals/new.html.haml index 0f699559..7885f990 100644 --- a/app/views/proposals/new.html.haml +++ b/app/views/proposals/new.html.haml @@ -59,7 +59,8 @@ 250 words. - = f.input :require_registration, label: 'Require participants to register to your event' + - if @program.cfp.enable_registrations? + = f.input :require_registration, label: 'Require participants to register to your event' %p.text-right = link_to '#description', 'data-toggle' => 'collapse', id: 'description_link' do diff --git a/db/migrate/20181017183243_add_allow_reservations_on_cfps.rb b/db/migrate/20181017183243_add_allow_reservations_on_cfps.rb new file mode 100644 index 00000000..e43fd7fd --- /dev/null +++ b/db/migrate/20181017183243_add_allow_reservations_on_cfps.rb @@ -0,0 +1,5 @@ +class AddAllowReservationsOnCfps < ActiveRecord::Migration[5.0] + def change + add_column 'cfps', 'enable_registrations', :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 509363e3..9e3aae67 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -42,13 +42,14 @@ ActiveRecord::Schema.define(version: 20181113195810) do end create_table "cfps", force: :cascade do |t| - t.date "start_date", null: false - t.date "end_date", null: false + t.date "start_date", null: false + t.date "end_date", null: false t.datetime "created_at" t.datetime "updated_at" t.integer "program_id" t.string "cfp_type" t.text "description" + t.boolean "enable_registrations", default: false end create_table "comments", force: :cascade do |t| @@ -434,6 +435,7 @@ ActiveRecord::Schema.define(version: 20181113195810) do t.datetime "updated_at" t.boolean "include_cfp", default: false t.boolean "include_booths" + t.boolean "shuffle_highlights", default: false, null: false end create_table "sponsors", force: :cascade do |t| diff --git a/spec/factories/cfps.rb b/spec/factories/cfps.rb index 97371814..d134f150 100644 --- a/spec/factories/cfps.rb +++ b/spec/factories/cfps.rb @@ -8,6 +8,7 @@ FactoryBot.define do end_date { 2.days.from_now } cfp_type { 'events' } description { 'This is a test description' } + enable_registrations { true } program end end diff --git a/spec/features/commercials_spec.rb b/spec/features/commercials_spec.rb index 289c4f07..107a0693 100644 --- a/spec/features/commercials_spec.rb +++ b/spec/features/commercials_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' feature Commercial do # It is necessary to use bang version of let to build roles before user let!(:conference) { create(:conference) } + let!(:cfp) { create(:cfp, program: conference.program) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organizer) { create(:user, role_ids: [organizer_role.id]) } let!(:participant) { create(:user) } diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index f48ea034..0a9ea422 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -94,6 +94,7 @@ feature Event do scenario 'update a proposal' do conference = create(:conference) + create(:cfp, program: conference.program) proposal = create(:event, program: conference.program) sign_in proposal.submitter diff --git a/spec/features/versions_spec.rb b/spec/features/versions_spec.rb index 14b8154c..a0963323 100644 --- a/spec/features/versions_spec.rb +++ b/spec/features/versions_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' feature 'Version' do let!(:conference) { create(:conference) } + let!(:cfp) { create(:cfp, program: conference.program) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organizer) { create(:user, role_ids: [organizer_role.id]) } let(:event_with_commercial) { create(:event, program: conference.program) } @@ -35,7 +36,6 @@ feature 'Version' do end scenario 'display changes in cfp', feature: true, versioning: true, js: true do - cfp = create(:cfp, program: conference.program) cfp.update_attributes(start_date: (Time.zone.today + 1).strftime('%d/%m/%Y'), end_date: (Time.zone.today + 3).strftime('%d/%m/%Y')) cfp_id = cfp.id cfp.destroy