osem-fcy/app/controllers/proposal_controller.rb

146 lines
4.5 KiB
Ruby
Raw Normal View History

2013-01-07 09:04:09 +01:00
class ProposalController < ApplicationController
before_filter :authenticate_user!, except: [:show]
2014-08-12 11:51:59 +03:00
load_resource :conference, find_by: :short_title
load_and_authorize_resource :event, parent: false, through: :conference
2013-01-07 09:04:09 +01:00
def index
2014-07-23 16:24:05 +02:00
@events = current_user.proposals(@conference)
2013-01-07 09:04:09 +01:00
end
2014-07-23 16:24:05 +02:00
def show
# FIXME: We should show more than the first speaker
@speaker = @event.speakers.first || @event.submitter
2013-01-07 09:04:09 +01:00
end
def new
2014-07-23 16:24:05 +02:00
@url = conference_proposal_index_path(@conference.short_title)
2013-01-07 09:04:09 +01:00
end
def edit
2014-07-23 16:24:05 +02:00
authorize! :edit, @event
2013-01-07 09:04:09 +01:00
@url = conference_proposal_path(@conference.short_title, params[:id])
end
2014-07-23 16:24:05 +02:00
def create
@url = conference_proposal_index_path(@conference.short_title)
2013-01-07 09:04:09 +01:00
2014-06-23 19:07:50 +03:00
params[:event].delete :user
2014-07-23 16:24:05 +02:00
@event = Event.new(params[:event])
@event.conference = @conference
2013-01-07 09:04:09 +01:00
2014-07-23 16:24:05 +02:00
# First, update the submitter's info, if they've changed anything
current_user.assign_attributes(params[:user])
if current_user.changed?
current_user.save
end
2014-07-23 16:24:05 +02:00
@event.event_users.new(user: current_user,
event_role: 'submitter')
@event.event_users.new(user: current_user,
event_role: 'speaker')
2014-07-23 16:24:05 +02:00
if !@event.save
flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}"
render action: 'new'
return
2013-01-07 09:04:09 +01:00
end
2014-07-23 16:24:05 +02:00
ahoy.track 'Event submission', title: 'New submission'
if @conference.user_registered?(current_user)
redirect_to(conference_proposal_index_path(@conference.short_title),
2014-07-23 16:24:05 +02:00
notice: 'Event was successfully submitted.')
else
redirect_to(new_conference_conference_registrations_path(conference_id: @conference.short_title),
alert: 'Event was successfully submitted. You should register for the conference now.')
2013-01-07 09:04:09 +01:00
end
end
2014-07-23 16:24:05 +02:00
def update
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
2013-01-07 09:04:09 +01:00
2014-07-23 16:24:05 +02:00
# First, update the submitter's info, if they've changed anything
current_user.assign_attributes(params[:user])
if current_user.changed?
current_user.save
end
2013-01-07 09:04:09 +01:00
2014-07-23 16:24:05 +02:00
# FIXME: Hmmmmm
params[:event].delete :users_attributes
params[:event].delete :user
2013-01-16 08:22:20 +01:00
2014-07-23 16:24:05 +02:00
if !@event.update(params[:event])
flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}"
2014-06-23 19:07:50 +03:00
render action: 'new'
2013-01-16 08:22:20 +01:00
return
end
2014-07-23 16:24:05 +02:00
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
notice: 'Proposal was successfully updated.')
2014-07-23 16:24:05 +02:00
end
def destroy
authorize! :destroy, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
begin
@event.withdraw
rescue Transitions::InvalidTransition
redirect_to(:back, error: "Event can't be withdrawn")
2013-01-16 08:22:20 +01:00
return
end
2014-07-23 16:24:05 +02:00
@event.save(validate: false)
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
notice: 'Proposal was successfully withdrawn.')
2014-07-23 16:24:05 +02:00
end
2013-01-07 09:04:09 +01:00
2014-07-23 16:24:05 +02:00
def confirm
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
2013-01-07 09:04:09 +01:00
begin
2014-07-23 16:24:05 +02:00
@event.confirm!
rescue Transitions::InvalidTransition
redirect_to(:back, error: "Event can't be confirmed")
return
end
2013-01-07 09:04:09 +01:00
2014-07-23 16:24:05 +02:00
if !@event.save
flash[:error] = "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}"
2014-06-23 19:07:50 +03:00
render action: 'new'
2013-01-07 09:04:09 +01:00
return
end
if @conference.user_registered?(current_user)
redirect_to(conference_proposal_index_path(@conference.short_title),
notice: 'The proposal was confirmed.')
else
redirect_to(new_conference_conference_registrations_path(conference_id: @conference.short_title),
alert: 'The proposal was confirmed. Please register to attend the conference.')
2013-01-07 09:04:09 +01:00
end
end
2014-07-23 16:24:05 +02:00
def restart
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
2014-08-12 11:51:59 +03:00
2014-07-23 16:24:05 +02:00
begin
@event.restart
rescue Transitions::InvalidTransition
2014-06-23 19:07:50 +03:00
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
2014-07-23 16:24:05 +02:00
error: "The proposal can't be re-submitted.")
return
2013-01-08 08:51:34 +01:00
end
2014-07-23 16:24:05 +02:00
if !@event.save
flash[:error] = "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}"
render action: 'new'
return
2014-06-06 10:23:01 +02:00
end
2014-07-23 16:24:05 +02:00
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
notice: "The proposal was re-submitted. The #{@conference.short_title} organizers will review it again.")
end
2013-01-07 09:04:09 +01:00
end