Skip to content

Commit

Permalink
Merge pull request #371 from cs169/187217062-enable-public-submission…
Browse files Browse the repository at this point in the history
…-event-types

187217062 enable public submission event types
  • Loading branch information
cycomachead authored Jul 20, 2024
2 parents 4223687 + 0ea87b2 commit bb3ba43
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/event_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def destroy

def event_type_params
params.require(:event_type).permit(:title, :length, :minimum_abstract_length, :maximum_abstract_length,
:submission_template, :color, :conference_id, :description)
:submission_template, :color, :conference_id, :description, :enable_public_submission)
end
end
end
8 changes: 6 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ def volunteer_links(event)
end, ', ')
end

def event_types_sentence(conference)
conference.event_types.map { |et| et.title.pluralize }.to_sentence
def event_types_sentence(conference, is_admin)
if is_admin
conference.event_types.map { |et| et.title.pluralize }.to_sentence
else
conference.event_types.available_for_public.map { |et| et.title.pluralize }.to_sentence
end
end

def sign_in_path
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/event_types_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def event_type_select_options(event_types = {})
"#{type.title} - #{show_time(type.length)}",
type.id,
{ data: {
min_words: type.minimum_abstract_length,
max_words: type.maximum_abstract_length,
instructions: type.submission_template
min_words: type.minimum_abstract_length,
max_words: type.maximum_abstract_length,
template: type.submission_template
} }
]
end
Expand Down
30 changes: 19 additions & 11 deletions app/models/event_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
#
# Table name: event_types
#
# id :bigint not null, primary key
# color :string
# description :string
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
# id :bigint not null, primary key
# color :string
# description :string
# enable_public_submission :boolean default(TRUE), not null
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
#
class EventType < ApplicationRecord
belongs_to :program, touch: true
Expand All @@ -31,9 +32,12 @@ class EventType < ApplicationRecord
validates :color, format: /\A#[0-9A-F]{6}\z/

before_validation :capitalize_color
before_validation :strip_title

alias_attribute :name, :title

scope :available_for_public, -> { where(enable_public_submission: true) }

private

##
Expand All @@ -53,4 +57,8 @@ def capitalize_color
def conference_id
program.conference_id
end

def strip_title
self.title = title.strip unless title.nil?
end
end
2 changes: 1 addition & 1 deletion app/views/admin/cfps/_events_cfp.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
%dt
Event types:
%dd
= event_types_sentence(conference)
= event_types_sentence(conference, true)
%dt
Tracks:
%dd
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/event_types/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
= f.label :description
= f.text_area :description, class: 'form-control', rows: 5, data: { provide: 'markdown' }
.help-block= markdown_hint
.form-group
= f.label "Allow public submission?", for: :enable_public_submission
= f.check_box :enable_public_submission, class: 'switch-checkbox'
.form-group
= f.label :minimum_abstract_length
%abbr{title: 'This field is required'} *
Expand Down
5 changes: 4 additions & 1 deletion app/views/admin/event_types/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
%tr
%th Title
%th Description
%th Instructions
%th Enable Public Submission
%th Template
%th Length
%th Abstract Length
%th Color
Expand All @@ -23,6 +24,8 @@
= event_type.title
%td
= markdown(event_type.description)
%td
= event_type.enable_public_submission ? 'Yes' : 'No'
%td
= markdown(event_type.submission_template)
%td
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/programs/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%dt
Event types:
%dd
= event_types_sentence(@conference)
= event_types_sentence(@conference, true)
%dt
Tracks:
%dd
Expand Down
2 changes: 1 addition & 1 deletion app/views/proposals/_encouragement_text.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%p.lead
- if @program.event_types.any?
You can submit proposals for
= "#{event_types_sentence(@conference)}."
= "#{event_types_sentence(@conference, current_user&.is_admin || false)}."
- if @program.tracks.confirmed.cfp_active.any?
Proposals should fit in one of the
= "#{pluralize(@program.tracks.confirmed.cfp_active.count, 'track')}:"
Expand Down
5 changes: 3 additions & 2 deletions app/views/proposals/_submission_type_content_form.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
%p Please select a submission type, then fill in the abstract and extended details.

.form-group
= f.label :event_type_id, 'Type'
= f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' }
= f.label :event_type_id, "Type"
- visible_event_types = current_user&.is_admin ? @conference.program.event_types : @conference.program.event_types.available_for_public
= f.select :event_type_id, event_type_select_options(visible_event_types), { include_blank: false }, { class: 'select-help-toggle form-control' }

- program.event_types.each do |event_type|
.help-block.event_event_type_id.collapse{ id: "#{dom_id(event_type)}-help" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEnablePublicSubmissionToEventTypes < ActiveRecord::Migration[7.0]
def change
add_column :event_types, :enable_public_submission, :boolean, default: true, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_03_15_025823) do
ActiveRecord::Schema[7.0].define(version: 2024_03_18_164346) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down Expand Up @@ -234,6 +234,7 @@
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.text "submission_template"
t.boolean "enable_public_submission", default: true, null: false
end

create_table "event_users", force: :cascade do |t|
Expand Down
24 changes: 13 additions & 11 deletions spec/factories/event_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
#
# Table name: event_types
#
# id :bigint not null, primary key
# color :string
# description :string
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
# id :bigint not null, primary key
# color :string
# description :string
# enable_public_submission :boolean default(TRUE), not null
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
#

FactoryBot.define do
factory :event_type do
title { 'Example Event Type' }
length { 30 }
description { 'Example Event Description\nThis event type is an example.' }
enable_public_submission { true }
minimum_abstract_length { 0 }
maximum_abstract_length { 500 }
submission_template { 'Example Event Template _with_ **markdown**' }
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,22 @@
expect(conference_logo_url(conference2)).to include('2.png')
end
end

describe '#event_type_sentence' do
before do
create(:event_type, title: 'Keynote', program: conference.program, enable_public_submission: false)
end

context 'when a user is an admin' do
it 'returns a sentence with all event types' do
expect(helper.event_types_sentence(conference, true)).to eq 'Talks, Workshops, and Keynotes'
end
end

context 'when a user is not an admin' do
it 'returns a sentence only event types that allow public submission' do
expect(helper.event_types_sentence(conference, false)).to eq 'Talks and Workshops'
end
end
end
end
43 changes: 32 additions & 11 deletions spec/models/event_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
#
# Table name: event_types
#
# id :bigint not null, primary key
# color :string
# description :string
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
# id :bigint not null, primary key
# color :string
# description :string
# enable_public_submission :boolean default(TRUE), not null
# length :integer default(30)
# maximum_abstract_length :integer default(500)
# minimum_abstract_length :integer default(0)
# submission_template :text
# title :string not null
# created_at :datetime
# updated_at :datetime
# program_id :integer
#
require 'spec_helper'

Expand Down Expand Up @@ -61,5 +62,25 @@
expect(build(:event_type, program: conference.program, length: 37)).not_to be_valid
end
end

describe 'title' do
it 'removes leading and trailing whitespace from title' do
event_type = EventType.new(title: ' Movie ')
event_type.valid?
expect(event_type.title).to eq('Movie')
end
end
end

describe 'scope :available_for_public' do
it 'includes event types with enable_public_submission set to true' do
public_event_type = create(:event_type, program: conference.program, enable_public_submission: true)
expect(EventType.available_for_public).to include(public_event_type)
end

it 'excludes event types with enable_public_submission set to false' do
non_public_event_type = create(:event_type, program: conference.program, enable_public_submission: false)
expect(EventType.available_for_public).not_to include(non_public_event_type)
end
end
end

0 comments on commit bb3ba43

Please sign in to comment.