osem-fcy/app/controllers/proposals_controller.rb

180 lines
6.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class ProposalsController < ApplicationController
before_action :authenticate_user!, except: [:show, :new, :create]
2014-08-12 11:51:59 +03:00
load_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event, parent: false, through: :program
# We authorize manually in these actions
skip_authorize_resource :event, only: [:confirm, :restart, :withdraw]
2013-01-07 09:04:09 +01:00
def index
@event = @program.events.new
@event.event_users.new(user: current_user, event_role: 'submitter')
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
@event_schedule = @event.event_schedules.find_by(schedule_id: @program.selected_schedule_id)
@speakers_ordered = @event.speakers_ordered
2018-02-23 11:52:27 +02:00
@surveys_after_event = @event.surveys.after_event.select(&:active?)
2013-01-07 09:04:09 +01:00
end
def new
@user = User.new
@url = conference_program_proposals_path(@conference.short_title)
2013-01-07 09:04:09 +01:00
end
def edit
@url = conference_program_proposal_path(@conference.short_title, params[:id])
2013-01-07 09:04:09 +01:00
end
2014-07-23 16:24:05 +02:00
def create
@url = conference_program_proposals_path(@conference.short_title)
2013-01-07 09:04:09 +01:00
# We allow proposal submission and sign up on same page.
# If user is not signed in then first create new user and then sign them in
unless current_user
2015-10-28 18:05:15 +02:00
@user = User.new(user_params)
authorize! :create, @user
if @user.save
sign_in(@user)
else
flash.now[:error] = "Could not save user: #{@user.errors.full_messages.join(', ')}"
render action: 'new'
return
end
end
# User which creates the proposal is both `submitter` and `speaker` of proposal
# by default.
@event.speakers = [current_user]
@event.submitter = current_user
Implement track scheduling Add track association to schedule Show schedules in admin sidebar to track organizers Allow track organizers to manage the schedules of their tracks Don't allow self-organized track events to be dragged or unscheduled in a conference schedule Make scheduled events of self-organized tracks appear semitransparent in conference schedules Make the rooms of confirmed self_organized tracks appear semitransparent and don't allow events to be scheduled to it in the conference schedules during the dates of its track Create admin/SchedulesController#new action Add a button in admin/Schedules#index to create schedules for tracks Add self_organized scope to Track Modify Schedules#show to handle track schedules and show a unified schedule Allow track organizers to create new schedules for their tracks Correctly identify scheduled and unscheduled events in Schedules#events Fix Event#room and Event#time for when the event is scheduled in a track schedule Modify Program#selected_event_schedules to include the event_schedules of selected track schedules Modify Track#revoke_role_and_cleanup to destroy the track's schedules and revert its events' state to new Add tabs for conference and track schedules in admin/Schedules#index Add button to Create/Show a tracks schedule in Tracks#index and #show Fix concurrent_events in application_helper because of changes in Program#selected_event_schedules Do not take into account cfp_active in Event#valid_track Modify EventsController#get_tracks accordingly Enforce cfp_active of track to be enabled for proposals in ProposalsController#create and #update Add support for multiple schedules per track Add selected_schedule_id to Track Load EventSchedules of selected track schedules for conference schedules in admin/SchedulesController#show Modify SchedulesController#show to take into account only the selected track schedules Create Event#selected_schedule_id and use it in Event#scheduled? and Event#time Validate that an EventSchedule for an event of a self-organized track belongs to one of the track's schedules Add 'Manage' button in Tracks#index, #show that sends you to the admin side of things Add admin/TracksController#update_selected_schedule to update the selected_schedule_id of tracks
2017-08-09 18:12:20 +03:00
track = Track.find_by(id: params[:event][:track_id])
if track && !track.cfp_active
Implement track scheduling Add track association to schedule Show schedules in admin sidebar to track organizers Allow track organizers to manage the schedules of their tracks Don't allow self-organized track events to be dragged or unscheduled in a conference schedule Make scheduled events of self-organized tracks appear semitransparent in conference schedules Make the rooms of confirmed self_organized tracks appear semitransparent and don't allow events to be scheduled to it in the conference schedules during the dates of its track Create admin/SchedulesController#new action Add a button in admin/Schedules#index to create schedules for tracks Add self_organized scope to Track Modify Schedules#show to handle track schedules and show a unified schedule Allow track organizers to create new schedules for their tracks Correctly identify scheduled and unscheduled events in Schedules#events Fix Event#room and Event#time for when the event is scheduled in a track schedule Modify Program#selected_event_schedules to include the event_schedules of selected track schedules Modify Track#revoke_role_and_cleanup to destroy the track's schedules and revert its events' state to new Add tabs for conference and track schedules in admin/Schedules#index Add button to Create/Show a tracks schedule in Tracks#index and #show Fix concurrent_events in application_helper because of changes in Program#selected_event_schedules Do not take into account cfp_active in Event#valid_track Modify EventsController#get_tracks accordingly Enforce cfp_active of track to be enabled for proposals in ProposalsController#create and #update Add support for multiple schedules per track Add selected_schedule_id to Track Load EventSchedules of selected track schedules for conference schedules in admin/SchedulesController#show Modify SchedulesController#show to take into account only the selected track schedules Create Event#selected_schedule_id and use it in Event#scheduled? and Event#time Validate that an EventSchedule for an event of a self-organized track belongs to one of the track's schedules Add 'Manage' button in Tracks#index, #show that sends you to the admin side of things Add admin/TracksController#update_selected_schedule to update the selected_schedule_id of tracks
2017-08-09 18:12:20 +03:00
flash.now[:error] = 'You have selected a track that doesn\'t accept proposals'
render action: 'new'
return
end
if @event.save
2018-08-22 16:08:39 +03:00
Mailbot.submitted_proposal_mail(@event).deliver_later if @conference.email_settings.send_on_submitted_proposal
redirect_to conference_program_proposals_path(@conference.short_title), notice: 'Proposal was successfully submitted.'
else
flash.now[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}"
2014-07-23 16:24:05 +02:00
render action: 'new'
2013-01-07 09:04:09 +01:00
end
end
2014-07-23 16:24:05 +02:00
def update
@url = conference_program_proposal_path(@conference.short_title, params[:id])
2013-01-07 09:04:09 +01:00
track = Track.find_by(id: params[:event][:track_id])
if track && !track.cfp_active
Implement track scheduling Add track association to schedule Show schedules in admin sidebar to track organizers Allow track organizers to manage the schedules of their tracks Don't allow self-organized track events to be dragged or unscheduled in a conference schedule Make scheduled events of self-organized tracks appear semitransparent in conference schedules Make the rooms of confirmed self_organized tracks appear semitransparent and don't allow events to be scheduled to it in the conference schedules during the dates of its track Create admin/SchedulesController#new action Add a button in admin/Schedules#index to create schedules for tracks Add self_organized scope to Track Modify Schedules#show to handle track schedules and show a unified schedule Allow track organizers to create new schedules for their tracks Correctly identify scheduled and unscheduled events in Schedules#events Fix Event#room and Event#time for when the event is scheduled in a track schedule Modify Program#selected_event_schedules to include the event_schedules of selected track schedules Modify Track#revoke_role_and_cleanup to destroy the track's schedules and revert its events' state to new Add tabs for conference and track schedules in admin/Schedules#index Add button to Create/Show a tracks schedule in Tracks#index and #show Fix concurrent_events in application_helper because of changes in Program#selected_event_schedules Do not take into account cfp_active in Event#valid_track Modify EventsController#get_tracks accordingly Enforce cfp_active of track to be enabled for proposals in ProposalsController#create and #update Add support for multiple schedules per track Add selected_schedule_id to Track Load EventSchedules of selected track schedules for conference schedules in admin/SchedulesController#show Modify SchedulesController#show to take into account only the selected track schedules Create Event#selected_schedule_id and use it in Event#scheduled? and Event#time Validate that an EventSchedule for an event of a self-organized track belongs to one of the track's schedules Add 'Manage' button in Tracks#index, #show that sends you to the admin side of things Add admin/TracksController#update_selected_schedule to update the selected_schedule_id of tracks
2017-08-09 18:12:20 +03:00
flash.now[:error] = 'You have selected a track that doesn\'t accept proposals'
render action: 'edit'
return
end
if @event.update(event_params)
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
2016-03-24 17:49:34 +05:30
notice: 'Proposal was successfully updated.'
else
flash.now[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}"
render action: 'edit'
2013-01-16 08:22:20 +01:00
end
2014-07-23 16:24:05 +02:00
end
def withdraw
authorize! :update, @event
@url = conference_program_proposal_path(@conference.short_title, params[:id])
2014-07-23 16:24:05 +02:00
begin
@event.withdraw
selected_schedule = @event.program.selected_schedule
event_schedule = @event.event_schedules.find_by(schedule: selected_schedule) if selected_schedule
Rails.logger.debug "schedule: #{selected_schedule.inspect} and event_schedule #{event_schedule.inspect}"
if selected_schedule && event_schedule
event_schedule.enabled = false
event_schedule.save
else
@event.event_schedules.destroy_all
end
2014-07-23 16:24:05 +02:00
rescue Transitions::InvalidTransition
redirect_back(fallback_location: root_path, error: "Event can't be withdrawn")
2013-01-16 08:22:20 +01:00
return
end
if @event.save
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
notice: 'Proposal was successfully withdrawn.'
else
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
error: "Could not withdraw proposal: #{@event.errors.full_messages.join(', ')}"
end
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_program_proposal_path(@conference.short_title, params[:id])
2013-01-07 09:04:09 +01:00
begin
@event.confirm
2014-07-23 16:24:05 +02:00
rescue Transitions::InvalidTransition
redirect_back(fallback_location: root_path, error: "Event can't be confirmed")
2014-07-23 16:24:05 +02:00
return
end
2013-01-07 09:04:09 +01:00
if @event.save
if @conference.user_registered?(current_user)
redirect_to conference_program_proposals_path(@conference.short_title),
notice: 'The proposal was confirmed.'
else
redirect_to new_conference_conference_registration_path(conference_id: @conference.short_title),
alert: 'The proposal was confirmed. Please register to attend the conference.'
end
else
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
error: "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}"
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_program_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
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
error: "The proposal can't be re-submitted."
2014-07-23 16:24:05 +02:00
return
2013-01-08 08:51:34 +01:00
end
if @event.save
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
2016-03-24 17:49:34 +05:30
notice: "The proposal was re-submitted. The #{@conference.short_title} organizers will review it again."
else
redirect_to conference_program_proposals_path(conference_id: @conference.short_title),
error: "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}"
2014-06-06 10:23:01 +02:00
end
2014-07-23 16:24:05 +02:00
end
2015-10-28 18:05:15 +02:00
2016-04-22 18:18:46 +03:00
def registrations; end
2015-10-28 18:05:15 +02:00
private
def event_params
2016-04-22 18:18:46 +03:00
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
:title, :subtitle, :abstract, :description,
:require_registration, :max_attendees, :language,
speaker_ids: []
)
2015-10-28 18:05:15 +02:00
end
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :username)
end
2013-01-07 09:04:09 +01:00
end