From 03ef28e74d76273028346226c6786fbfb482a7d8 Mon Sep 17 00:00:00 2001 From: James Mason Date: Fri, 16 Mar 2018 16:23:01 -0700 Subject: [PATCH] Require code of conduct acceptance on registration --- .../admin/registrations_controller.rb | 9 ++++-- .../conference_registrations_controller.rb | 2 +- app/models/registration.rb | 4 +++ app/views/admin/registrations/index.html.haml | 10 ++++++ .../_registration_info.html.haml | 13 ++++++++ .../conference_registrations/show.html.haml | 19 +++++++++++ ...cepted_code_of_conduct_to_registrations.rb | 5 +++ db/schema.rb | 5 +-- spec/features/code_of_conduct_spec.rb | 32 +++++++++++++++++-- 9 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20180316220446_add_accepted_code_of_conduct_to_registrations.rb diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 475c18c8..3537cded 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -12,6 +12,7 @@ module Admin @registration_distribution = @conference.registration_distribution @affiliation_distribution = @conference.affiliation_distribution + @code_of_conduct = @conference.code_of_conduct.present? end def edit; end @@ -61,9 +62,11 @@ module Admin end def registration_params - params.require(:registration).permit(:user_id, :conference_id, :arrival, :departure, :attended, - :volunteer, :other_special_needs, - vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: []) + params.require(:registration).permit( + :user_id, :conference_id, :arrival, :departure, :attended, + :volunteer, :other_special_needs, :accepted_code_of_conduct, + vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: [] + ) end end end diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index f2751a31..c61be8a4 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -112,7 +112,7 @@ class ConferenceRegistrationsController < ApplicationController params.require(:registration) .permit( :conference_id, :arrival, :departure, - :volunteer, + :volunteer, :accepted_code_of_conduct, vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: [], diff --git a/app/models/registration.rb b/app/models/registration.rb index 45d2d55b..ed8a2982 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -28,6 +28,10 @@ class Registration < ApplicationRecord validate :registration_limit_not_exceed, on: :create validate :registration_to_events_only_if_present + validates :accepted_code_of_conduct, acceptance: { + if: -> { conference.code_of_conduct.present? } + } + after_create :set_week, :subscribe_to_conference, :send_registration_mail ## diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index a51d41fc..91268ac0 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -25,6 +25,9 @@ %th ID# %th Name %th E-Mail + - if @code_of_conduct + %th + %abbr{ title: 'Code of Conduct' } CoC %th Arrival %th Departure - if @conference.questions.any? @@ -43,6 +46,13 @@ = role.name.titleize %td = registration.email + - if @code_of_conduct + - if registration.accepted_code_of_conduct + %td.text-success.text-center= fa_icon('check', title: 'accepted') + - else + %td.text-center.text-warning + = fa_icon('exclamation-circle', + title: 'Has not accepted Code of Conduct') %td - if registration.arrival = registration.arrival.strftime('%d %b %H:%M') diff --git a/app/views/conference_registrations/_registration_info.html.haml b/app/views/conference_registrations/_registration_info.html.haml index e9d6e12a..cb6cd90c 100644 --- a/app/views/conference_registrations/_registration_info.html.haml +++ b/app/views/conference_registrations/_registration_info.html.haml @@ -1,3 +1,14 @@ +- unless @conference.code_of_conduct.blank? + - code_of_conduct_link = link_to 'Code of Conduct', '#', + data: { toggle: 'modal', target: '#modal-code-of-conduct'} + - if @registration.accepted_code_of_conduct + = fa_icon 'check-square-o' + I have read and accepted the + = code_of_conduct_link + - else + = f.input :accepted_code_of_conduct, + label: "I have read and accept the #{code_of_conduct_link}".html_safe, + required: true - if @conference.questions.any? = render partial: 'conference_registrations/questions', locals: { f: f } - if @conference.program.events.with_registration_open.any? || @registration.events.any? @@ -19,3 +30,5 @@ = f.inputs 'Your Travel Info' do = f.input :arrival, as: :string, label: 'Your arrival time', hint: "Leave blank if not sure", input_html: { value: (f.object.arrival.to_formatted_s(:db_without_seconds) unless f.object.arrival.nil?), id: 'registration-arrival-datepicker',start_date: @conference.start_date,end_date: @conference.end_date} = f.input :departure, as: :string, label: 'Your departure time', hint: "Leave blank if not sure", input_html: { value: (f.object.departure.to_formatted_s(:db_without_seconds) unless f.object.departure.nil?), id: 'registration-departure-datepicker'} + += render 'conferences/code_of_conduct', organization: @conference.organization diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml index 83efbd60..223d7c12 100644 --- a/app/views/conference_registrations/show.html.haml +++ b/app/views/conference_registrations/show.html.haml @@ -14,6 +14,25 @@ = "#{@conference.venue.city} / #{@conference.venue.country_name}." %small = date_string(@conference.start_date, @conference.end_date) + - unless @conference.code_of_conduct.blank? + .row + .col-md-12 + %h4= fa_stacked_icon 'handshake-o', base: 'square-o', text: 'Code of Conduct' + %ul.fa-ul + - if @registration.accepted_code_of_conduct + %li.text-info + = fa_icon('check li') + You have accepted the + = link_to 'Code of Conduct', '#', + data: { toggle: 'modal', target: '#modal-code-of-conduct'} + - else + %li.text-warning + = fa_icon('exclamation-circle li') + You need to accept the + = link_to 'Code of Conduct', '#', + data: { toggle: 'modal', target: '#modal-code-of-conduct'} + = render 'conferences/code_of_conduct', + organization: @conference.organization .row .col-md-12 %h4 diff --git a/db/migrate/20180316220446_add_accepted_code_of_conduct_to_registrations.rb b/db/migrate/20180316220446_add_accepted_code_of_conduct_to_registrations.rb new file mode 100644 index 00000000..fb5f043b --- /dev/null +++ b/db/migrate/20180316220446_add_accepted_code_of_conduct_to_registrations.rb @@ -0,0 +1,5 @@ +class AddAcceptedCodeOfConductToRegistrations < ActiveRecord::Migration[5.0] + def change + add_column :registrations, :accepted_code_of_conduct, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 0ea8a9e8..a6d7dbf1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180316185150) do +ActiveRecord::Schema.define(version: 20180316220446) do create_table "ahoy_events", force: :cascade do |t| t.integer "visit_id" @@ -386,10 +386,11 @@ ActiveRecord::Schema.define(version: 20180316185150) do t.datetime "created_at" t.datetime "updated_at" t.text "other_special_needs" - t.boolean "attended", default: false + t.boolean "attended", default: false t.boolean "volunteer" t.integer "user_id" t.integer "week" + t.boolean "accepted_code_of_conduct" end create_table "registrations_vchoices", id: false, force: :cascade do |t| diff --git a/spec/features/code_of_conduct_spec.rb b/spec/features/code_of_conduct_spec.rb index f92063d7..7ce27ce5 100644 --- a/spec/features/code_of_conduct_spec.rb +++ b/spec/features/code_of_conduct_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' feature 'Code of Conduct:' do let!(:organization) { create(:organization) } + let!(:conference) { create(:full_conference, organization: organization) } let(:admin) { create(:admin) } let(:sample_text) { Faker::Lorem.paragraph } @@ -45,8 +46,6 @@ feature 'Code of Conduct:' do end context 'on a conference' do - let!(:conference) { create(:full_conference, organization: organization) } - it 'is linked from the index' do visit conferences_path within "#conference-#{conference.id}" do @@ -62,5 +61,34 @@ feature 'Code of Conduct:' do end end end + + describe 'as a participant' do + let!(:organization) { create(:organization, code_of_conduct: sample_text) } + let!(:participant) { create(:user) } + + before { sign_in participant } + + it 'must be accepted', js: true do + visit conferences_path + within "#conference-#{conference.id}" do + click_on 'Register' + end + expect(page).to have_text('I have read and accept the Code of Conduct') + expect(page).not_to have_text(sample_text) + within 'form' do + click_on 'Code of Conduct' + end + expect(page).to have_content(sample_text) + find('button.close').click + click_on 'Register' + expect(conference.user_registered?(participant)).to be_falsey + expect(page).to have_content('Accepted code of conduct must be accepted') + check 'registration[accepted_code_of_conduct]' + click_on 'Register' + expect(conference.user_registered?(participant)).to be_truthy + visit conference_conference_registration_path(conference) + expect(page).to have_content('You have accepted the Code of Conduct') + end + end end end