Skip to content

Commit

Permalink
Consolidate validations around opening an event
Browse files Browse the repository at this point in the history
- Add Event#checklist_complete? for checking list and adding errors
- Don't show 'Update Status' button if the event cannot be opened

Schedule flow UI audit (rubycentral#261)
  • Loading branch information
jonsgreen committed Jan 10, 2018
1 parent 7c6d8af commit f6e090f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/controllers/staff/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def update

def open_cfp
authorize_update
if @event.open_cfp
if @event.update_attributes(state: Event::STATUSES[:open])
flash[:info] = "Your CFP was successfully opened."
else
flash[:danger] = "There was a problem opening your CFP: #{@event.errors.full_messages.to_sentence}"
flash['danger alert-confirm'] = "There was a problem opening your CFP: #{@event.errors.full_messages.to_sentence}"
end
redirect_to event_staff_path(@event)
end
Expand Down
16 changes: 0 additions & 16 deletions app/helpers/events_helper.rb

This file was deleted.

25 changes: 8 additions & 17 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class Event < ApplicationRecord

GUIDELINE_MESSAGE = 'Guidelines must be defined before event can be opened.'
SESSION_FORMAT_MESSAGE = 'At least one public session format must be defined before event can be opened.'

has_many :teammates, dependent: :destroy
has_many :proposals, dependent: :destroy
has_many :speakers
Expand Down Expand Up @@ -41,18 +38,16 @@ class Event < ApplicationRecord
before_validation :generate_slug
before_save :update_closes_at_if_manually_closed

STATUSES = { open: 'open',
draft: 'draft',
STATUSES = { draft: 'draft',
open: 'open',
closed: 'closed' }

def to_param
slug
end

with_options on: :update, if: :open? do
validates :public_session_formats, presence: { message: SESSION_FORMAT_MESSAGE }
validates :guidelines, presence: { message: GUIDELINE_MESSAGE }
end
validate :checklist_complete?, on: :update,
if: Proc.new { |e| e.state == STATUSES[:open] }

def initialize_speaker_emails
SpeakerEmailTemplate::TYPES.each do |type|
Expand Down Expand Up @@ -176,14 +171,10 @@ def incomplete_checklist_items
missing_items
end

def open_cfp
if incomplete_checklist_items.empty?
update_attribute(:state, STATUSES[:open])
true
else
errors.add(incomplete_checklist_items.join("; "))
false
end
def checklist_complete?
if (items = incomplete_checklist_items) && items.present?
errors.add(:base, items.join("; "))
end.blank?
end

def archive
Expand Down
7 changes: 3 additions & 4 deletions app/views/staff/events/info.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
- if current_user.organizer_for_event?(event)
.btn-nav
= link_to "Edit Info", event_staff_edit_path(event), class: "btn btn-primary"
= link_to "Change Status", '#', class: "btn btn-primary status-button"
- if event.checklist_complete?
= link_to "Change Status", '#', class: "btn btn-primary status-button"
.status-dropdown.pull-right
- event_status_messages(event).each do |message|
.message= "Note: #{message}"
= form_for(event, url: event_staff_update_status_path(event)) do |f|
= f.select(:state, event_status_options(event))
= f.select(:state, options_for_select(Event::STATUSES.values, f.object.state))
= link_to "Cancel", '#', {:class=>"cancel-status-change btn btn-danger"}
= f.submit "Update Status", class: "btn btn-success"
%h1 Event Info
Expand Down
2 changes: 1 addition & 1 deletion app/views/staff/events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
%h3 CFP
.widget-content
%strong.text-primary No CFP Statistics
- if event.incomplete_checklist_items.empty?
- if event.checklist_complete?
- if current_user.organizer_for_event?(current_event)
= link_to "Open CFP", event_staff_open_cfp_path(current_event), method: :patch,
class: "btn btn-success btn-lg cfp-button",
Expand Down

0 comments on commit f6e090f

Please sign in to comment.