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 a1a3ff8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 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

0 comments on commit a1a3ff8

Please sign in to comment.