Skip to content

Commit

Permalink
Merge pull request #235 from aackerman/aackerman/code-of-conduct-agre…
Browse files Browse the repository at this point in the history
…ement

Code of conduct agreement
  • Loading branch information
jennapederson committed Aug 29, 2020
2 parents d58ece5 + 944e175 commit 4322a68
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cache: bundler
sudo: false
rvm:
- 2.6.4
dist: trusty

notifications:
email:
Expand Down
8 changes: 4 additions & 4 deletions src/app/assets/stylesheets/formtastic.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ html[xmlns] form.formtastic fieldset ol li { display: block; }
form.formtastic fieldset ol li.required { }
form.formtastic fieldset ol li.optional { }
form.formtastic fieldset ol li.error { }


/* LABELS
--------------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -100,7 +100,7 @@ form.formtastic fieldset ol li.hidden { display:none; }

/* BOOLEAN OVERRIDES
--------------------------------------------------------------------------------------------------*/
form.formtastic fieldset ol li.boolean label { padding-left:25%; width:auto; }
form.formtastic fieldset ol li.boolean label { padding-left:0%; width:auto; }
form.formtastic fieldset ol li.boolean label input { margin:0 0.5em 0 0.2em; }


Expand Down Expand Up @@ -133,6 +133,6 @@ form.formtastic fieldset ol li.date fieldset ol li label,
form.formtastic fieldset ol li.time fieldset ol li label,
form.formtastic fieldset ol li.datetime fieldset ol li label { display:none; }

form.formtastic fieldset ol li.date fieldset ol li label input,
form.formtastic fieldset ol li.time fieldset ol li label input,
form.formtastic fieldset ol li.date fieldset ol li label input,
form.formtastic fieldset ol li.time fieldset ol li label input,
form.formtastic fieldset ol li.datetime fieldset ol li label input { display:inline; margin:0; padding:0; }
24 changes: 18 additions & 6 deletions src/app/controllers/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,40 @@ def edit
end

def update
@participant.update(participant_params)
@participant.update(participant_params.except(:code_of_conduct_agreement))
create_code_of_conduct_agreement_if_not_exists!
respond_with(@participant)
end

def create
@participant.attributes = participant_params
@participant.attributes = participant_params.except(:code_of_conduct_agreement)
if @participant.save
create_code_of_conduct_agreement_if_not_exists!
flash[:notice] = "Thanks for registering an account. You may now create sessions and mark sessions you'd like to attend."
redirect_to root_path
else
flash[:error] = "There was a problem creating that account."
flash[:error] = "There was a problem creating that account."
render :new
end
end

def create_code_of_conduct_agreement_if_not_exists!
if participant_params[:code_of_conduct_agreement] == '1' && @participant.signed_code_of_conduct_for_current_event? == false
CodeOfConductAgreement.create!({
participant_id: @participant.id,
event_id: Event.current_event.id,
})
end
end

private

def participant_params
params.require(controller_name.singularize).permit(:name, :email, :password,
:bio, :github_profile_username,
:twitter_handle)
params.require(controller_name.singularize).permit(
:name, :email, :password,
:bio, :github_profile_username,
:twitter_handle, :code_of_conduct_agreement
)
end

def verify_owner
Expand Down
4 changes: 4 additions & 0 deletions src/app/controllers/presentations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def create
flash[:error] = "Sorry, no presenter named '#{params[:name]}' was found. Please try again."
redirect_to session_presentations_path(@session)
return
elsif participant.signed_code_of_conduct_for_current_event? == false
flash[:error] = "Sorry, '#{params[:name]}' hasn't signed the Code of Conduct for this event."
redirect_to session_presentations_path(@session)
return
end

presentation = @session.presentations.new
Expand Down
24 changes: 22 additions & 2 deletions src/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,28 @@ def index
end

def create
@session.attributes = session_params
@session.attributes = session_params.except(:code_of_conduct_agreement)
@session.participant = current_participant
@session.event = Event.current_event

if @session.save
create_code_of_conduct_agreement_if_not_exists!
flash[:notice] = "Thanks for adding your session."
redirect_to @session
else
render :action => 'new'
end
end

def create_code_of_conduct_agreement_if_not_exists!
if session_params[:code_of_conduct_agreement] == '1' && @session.participant.signed_code_of_conduct_for_current_event? == false
CodeOfConductAgreement.create!({
participant_id: @session.participant.id,
event_id: Event.current_event.id,
})
end
end

STOP_WORDS = Set.new(['session', 'etc', 'just', 'presentation', 'get', 'discussion'])

def words
Expand Down Expand Up @@ -97,7 +107,17 @@ def popularity
private

def session_params
params.require(controller_name.singularize).permit(:title, :description, :level_id, :name, :email, :category_ids => [])
params
.require(controller_name.singularize)
.permit(
:title,
:description,
:level_id,
:name,
:email,
:code_of_conduct_agreement,
:category_ids => []
)
end

def verify_owner
Expand Down
4 changes: 4 additions & 0 deletions src/app/models/code_of_conduct_agreement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CodeOfConductAgreement < ActiveRecord::Base
belongs_to :participant
belongs_to :event
end
12 changes: 12 additions & 0 deletions src/app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Participant < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true

# used for formtastic form to allow sending a field related to a separate model
attr_accessor :code_of_conduct_agreement

acts_as_authentic do |config|
config.crypto_provider = Authlogic::CryptoProviders::BCrypt
config.require_password_confirmation = false
Expand Down Expand Up @@ -39,6 +42,15 @@ def deliver_password_reset_instructions!
Notifier.password_reset_instructions(self).deliver_now!
end

def signed_code_of_conduct_for_current_event?
return false unless Event.current_event

CodeOfConductAgreement.where({
participant_id: id,
event_id: Event.current_event.id,
}).exists?
end

def attending_session?(session)
sessions_attending.include?(session)
end
Expand Down
8 changes: 4 additions & 4 deletions src/app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Session < ActiveRecord::Base
scope :for_past_events, -> { where.not(event_id: Event.current_event.id).includes(:event).order('events.date desc') }

scope :recent, -> { order('created_at desc') }

scope :random_order, -> { order('random()') }

validates_presence_of :description
Expand All @@ -34,7 +34,7 @@ class Session < ActiveRecord::Base
#validates_uniqueness_of :timeslot_id, :scope => :room_id, :allow_blank => true, :message => 'and room combination already in use'


attr_accessor :name, :email
attr_accessor :name, :email, :code_of_conduct_agreement

after_create :create_presenter

Expand Down Expand Up @@ -132,7 +132,7 @@ def self.preload_attendance_counts(sessions)
sessions.each do |session|
sessions_by_id[session.id] = session
end

# Surely there’s a Rails helper for this?
# But I can’t find it — only some abandoned gems.
Attendance
Expand Down Expand Up @@ -181,7 +181,7 @@ def estimated_interest
# make estimated_interest tend toward the mean in cases when there are few real votes.

ballast_votes = 10.0
session_votes / (possible_votes + ballast_votes * session_count) * total_votes
session_votes / (possible_votes + ballast_votes * session_count) * total_votes
end
end

Expand Down
9 changes: 9 additions & 0 deletions src/app/views/participants/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<%= f.input :github_profile_username, :label => 'Your GitHub username' %>
<%= f.input :twitter_handle, :label => 'Your Twitter handle' %>
<%= f.input :bio, :hint => 'You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> syntax here. Examples: <strong>**bold**</strong>, <em>*italic*</em>, [link](http://example.com)'.html_safe %>
<%=
f.input :code_of_conduct_agreement,
as: :boolean,
label: 'I agree to the Code of Conduct governing this event',
input_html: {
checked: @participant.signed_code_of_conduct_for_current_event?,
disabled: @participant.signed_code_of_conduct_for_current_event?
}
%>
<% end %>
<%= f.actions do %>
Expand Down
9 changes: 9 additions & 0 deletions src/app/views/participants/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<%= f.input :name, :label => 'Your name', :hint => "Please use your real name. This will be used in our printed materials. Use JUST your name. For joint sessions, you will be able to add co-presenters." %>
<%= f.input :email, :label => 'Your email', :hint => "Please use a real email address. We need this to contact you about your presentation." %>
<%= f.input :password, :label => 'Password' %>
<%=
f.input :code_of_conduct_agreement,
as: :boolean,
label: 'I agree to the Code of Conduct governing this event',
input_html: {
checked: @participant.signed_code_of_conduct_for_current_event?,
disabled: @participant.signed_code_of_conduct_for_current_event?
}
%>
<% end %>
<%= f.actions do %>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/presentations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<h2>Add presenters</h2>

<p><strong>Note:</strong> In order to add a presenter to your session, they must be registered in the system.</p>
<p><strong>Note:</strong> In order to add a presenter to your session, they must be registered in the system and agreed to the Code of Conduct.</p>

<%= semantic_form_for([@session, @presentation]) do |f| %>
<%= text_field_tag 'name', '', :placeholder => 'Type a name', :id => 'typeahead' %> <%= submit_tag 'Add', :id => 'add-presenter' %>
Expand Down
7 changes: 7 additions & 0 deletions src/app/views/sessions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<%= f.input :categories, :as => :check_boxes %>
<%= f.input :level, :as => :select, :label => 'Topic level' %>
<%=
f.input :code_of_conduct_agreement,
as: :boolean,
required: true,
label: 'I agree to the Code of Conduct governing this event',
input_html: { checked: current_participant.signed_code_of_conduct_for_current_event? }
%>
<% end %>
<%= f.actions do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateCodeOfConductAgreements < ActiveRecord::Migration[5.2]
def change
create_table :code_of_conduct_agreements do |t|
t.references :participant, null: false
t.references :event, null: false
t.timestamps
end
end
end
12 changes: 10 additions & 2 deletions src/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_07_13_173911) do

ActiveRecord::Schema.define(version: 2019_07_17_012137) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand All @@ -36,6 +35,15 @@
t.index ["category_id", "session_id"], name: "index_categorizations_on_category_id_and_session_id", unique: true
end

create_table "code_of_conduct_agreements", force: :cascade do |t|
t.bigint "participant_id", null: false
t.bigint "event_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["event_id"], name: "index_code_of_conduct_agreements_on_event_id"
t.index ["participant_id"], name: "index_code_of_conduct_agreements_on_participant_id"
end

create_table "events", id: :serial, force: :cascade do |t|
t.string "name", limit: 255, null: false
t.date "date", null: false
Expand Down
22 changes: 18 additions & 4 deletions src/spec/controllers/presentations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,35 @@

describe "#create" do
context "when the user exists" do
before { create(:joe) }
before do
create(:event)
create(:joe)
end

it "should be successful when the user has signed the code of conduct" do
CodeOfConductAgreement.create!({
participant_id: Participant.where(name: 'Joe Schmoe').first.id,
event_id: Event.current_event.id,
})

it "should be successful" do
expect {
post :create, params: {session_id: session, name: 'Joe Schmoe'}
post :create, params: { session_id: session, name: 'Joe Schmoe' }
}.to change { session.presentations.count }.by(1)
expect(response).to redirect_to session_presentations_path(session)
expect(flash[:notice]).to eq "Presenter added."
end

it 'is unsuccessful when the user hasnt signed the code of conduct' do
post :create, params: { session_id: session, name: 'Joe Schmoe' }
expect(response).to redirect_to session_presentations_path(session)
expect(flash[:error]).to match(/hasn\'t signed the Code of Conduct for this event/)
end
end

context "when the user is not found" do
it "should set a flash message" do
expect {
post :create, params: {session_id: session, name: 'Grace Hopper'}
post :create, params: { session_id: session, name: 'Grace Hopper' }
}.not_to change { session.presentations.count }
expect(flash[:error]).to eq "Sorry, no presenter named 'Grace Hopper' was found. Please try again."
expect(response).to redirect_to session_presentations_path(session)
Expand Down

0 comments on commit 4322a68

Please sign in to comment.