Skip to content

Commit

Permalink
Organizations can have a custom Code of Conduct
Browse files Browse the repository at this point in the history
This changes the link on the Event and RSVP forms.

Currently the custom_code_of_conduct_url can only
be edited using the DB console.
  • Loading branch information
tjgrathwell committed Dec 7, 2015
1 parent 98de79e commit 7b86e97
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Event < ActiveRecord::Base
PERMITTED_ATTRIBUTES = [:title, :target_audience, :location_id, :chapter_id, :details, :time_zone, :volunteer_details, :public_email, :starts_at, :ends_at, :student_rsvp_limit, :volunteer_rsvp_limit, :course_id, :allow_student_rsvp, :student_details, :plus_one_host_toggle, :email_on_approval, :has_childcare, :restrict_operating_systems,
:survey_greeting]
DEFAULT_CODE_OF_CONDUCT_URL = 'http://bridgefoundry.org/code-of-conduct/'

serialize :allowed_operating_system_ids, JSON
serialize :external_event_data, JSON
Expand Down Expand Up @@ -288,6 +289,10 @@ def allowed_operating_systems
OperatingSystem.all.select { |os| allowed_operating_system_ids.include?(os.id) }
end

def code_of_conduct_url
chapter.organization.code_of_conduct_url || DEFAULT_CODE_OF_CONDUCT_URL
end

def update_rsvp_counts
update_columns(
volunteer_rsvps_count: volunteer_rsvps.count,
Expand Down
12 changes: 11 additions & 1 deletion app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,22 @@
<a href="https://github.com/bridgefoundry/WorkshopCookbook/wiki/Workshop-Planning-Tasks">Workshop Planning Tasks</a> page. You're already posting an event on Bridge Troll, which is a thing on that page!</p>

<div class="field">
<script>
var chapterOrganization = <%= Chapter.all.each_with_object({}) { |c, hsh| hsh[c.id] = c.organization_id }.to_json.html_safe %>;
var organizationCoc = <%= Organization.where.not(code_of_conduct_url: nil).each_with_object({}) { |o, hsh| hsh[o.id] = o.code_of_conduct_url }.to_json.html_safe %>;
$('#event_chapter_id').on('change', function () {
var chapterId = parseInt(this.value, 10);
$('#coc_url').attr('href', organizationCoc[chapterOrganization[chapterId]] || '<%= Event::DEFAULT_CODE_OF_CONDUCT_URL %>');
$('#coc').attr('checked', false);
});
</script>

<%= label_tag :coc, class: 'question' do %>
<strong><%= check_box_tag :coc, '1', params[:coc], data: {
'toggle-target' => 'coc-required',
'toggle-enable-when-checked' => true
} %>
I accept the <a href="http://bridgefoundry.org/code-of-conduct/" target="_blank">Code of Conduct</a> and will communicate it at the beginning of the event.
I accept the <%= link_to 'Code of Conduct', Event::DEFAULT_CODE_OF_CONDUCT_URL, target: :blank, id: 'coc_url' %> and will communicate it at the beginning of the event.
</strong>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/rsvps/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<%= check_box_tag :coc, '1', params[:coc], data: {
'toggle-target' => 'coc-required',
'toggle-enable-when-checked' => true
} %> I accept the <a href="http://bridgefoundry.org/code-of-conduct/" target="_blank">Code of Conduct</a>
} %> I accept the <%= link_to 'Code of Conduct', @event.code_of_conduct_url, target: :blank %>
<% end %>
</div>
<%end%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCodeOfConductUrlToOrganizations < ActiveRecord::Migration
def change
add_column :organizations, :code_of_conduct_url, :string
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151207004629) do
ActiveRecord::Schema.define(version: 20151207055515) do

create_table "authentications", force: :cascade do |t|
t.integer "user_id"
Expand Down Expand Up @@ -154,8 +154,9 @@

create_table "organizations", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "code_of_conduct_url"
end

create_table "profiles", force: :cascade do |t|
Expand Down
14 changes: 13 additions & 1 deletion spec/features/event_rsvp_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
describe 'creating or editing an rsvp' do
context "for a teaching event" do
let(:no_preference_text) { 'No preference' }
let(:chapter) { create(:chapter) }
before do
@event = create(:event)
@event = create(:event, chapter: chapter)
@user = create(:user)
sign_in_as @user
end
Expand Down Expand Up @@ -92,6 +93,17 @@
expect(page).to have_no_content(coc_text)
end
end

context 'when the organization has a different code of conduct' do
let(:organization) do
create(:organization, name: 'CoolBridge', code_of_conduct_url: 'http://example.com/coc')
end
let(:chapter) { create(:chapter, organization: organization) }

it 'shows a custom code of conduct URL' do
expect(page.find('label[for=coc] a')['href']).to eq('http://example.com/coc')
end
end
end

context 'with an invalid RSVP' do
Expand Down
26 changes: 21 additions & 5 deletions spec/features/new_event_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
before do
@user_organizer = create(:user, email: "organizer@mail.com", first_name: "Sam", last_name: "Spade")
@chapter = create(:chapter)
3.times { create(:location) }
@archived = Location.last.tap { |l| l.archive! }

sign_in_as(@user_organizer)

Expand Down Expand Up @@ -40,11 +38,29 @@
expect(page).to have_unchecked_field("coc")
end

it 'changes the code of conduct URL if the chapter-org has a custom one', js: true do
custom_coc_org = create(:organization, name: 'CustomCoc', code_of_conduct_url: 'http://example.com/coc')
create(:chapter, name: 'CustomCocChapter', organization: custom_coc_org)

visit "/events/new"
expect(page.find('label[for=coc] a')['href']).to eq(Event::DEFAULT_CODE_OF_CONDUCT_URL)
check("coc")

select 'CustomCocChapter', from: 'event_chapter_id'
expect(page.find('label[for=coc] a')['href']).to eq('http://example.com/coc')
expect(page).to have_unchecked_field('coc')
end

it "should have appropriate locations available" do
available_locations = Location.available.map(&:name_with_region)
available_locations.unshift "Please select"
live_location = create(:location)
archived_location = create(:location)
archived_location.archive!

expect(page).to have_select('event_location_id', :options => available_locations)
visit "/events/new"
expect(page).to have_select('event_location_id', options: [
"Please select",
live_location.name_with_region
])
end

it 'allows organizers to specify a whitelist of allowed OSes', js: true do
Expand Down

0 comments on commit 7b86e97

Please sign in to comment.