diff --git a/app/controllers/proposal_controller.rb b/app/controllers/proposal_controller.rb index cac68d4a..9bfca93c 100644 --- a/app/controllers/proposal_controller.rb +++ b/app/controllers/proposal_controller.rb @@ -24,13 +24,14 @@ class ProposalController < ApplicationController end def edit - authorize! :edit, @event @url = conference_program_proposal_path(@conference.short_title, params[:id]) end def create @url = conference_program_proposal_index_path(@conference.short_title) + # 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 @user = User.new(user_params) if @user.save @@ -47,39 +48,38 @@ class ProposalController < ApplicationController @event = Event.new(event_params) @event.program = @program + # User which creates the proposal is both `submitter` and `speaker` of proposal + # by default. + # TODO: Allow submitter to add speakers to proposals @event.event_users.new(user: current_user, event_role: 'submitter') @event.event_users.new(user: current_user, event_role: 'speaker') authorize! :new, @event - unless @event.save + if @event.save + ahoy.track 'Event submission', title: 'New submission' + redirect_to conference_program_proposal_index_path(@conference.short_title), notice: 'Proposal was successfully submitted.' + else flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" render action: 'new' - return end - - ahoy.track 'Event submission', title: 'New submission' - - redirect_to conference_program_proposal_index_path(@conference.short_title), notice: 'Proposal was successfully submitted.' end def update - authorize! :update, @event @url = conference_program_proposal_path(@conference.short_title, params[:id]) - if !@event.update(event_params) + if @event.update(event_params) + redirect_to(conference_program_proposal_index_path(conference_id: @conference.short_title), + notice: 'Proposal was successfully updated.') + else flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' - return + render action: 'edit' end - - redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), - notice: 'Proposal was successfully updated.' end - def destroy - authorize! :destroy, @event + def withdraw + authorize! :update, @event @url = conference_program_proposal_path(@conference.short_title, params[:id]) begin @@ -89,9 +89,13 @@ class ProposalController < ApplicationController return end - @event.save(validate: false) - redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), - notice: 'Proposal was successfully withdrawn.' + if @event.save + redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), + notice: 'Proposal was successfully withdrawn.' + else + redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), + error: "Could not withdraw proposal: #{@event.errors.full_messages.join(', ')}" + end end def confirm @@ -99,15 +103,15 @@ class ProposalController < ApplicationController @url = conference_program_proposal_path(@conference.short_title, params[:id]) begin - @event.confirm! + @event.confirm rescue Transitions::InvalidTransition redirect_to :back, error: "Event can't be confirmed" return end - if !@event.save - flash[:error] = "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' + unless @event.save + redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), + error: "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}" return end @@ -132,14 +136,13 @@ class ProposalController < ApplicationController return end - if !@event.save - flash[:error] = "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' - return + if @event.save + redirect_to(conference_program_proposal_index_path(conference_id: @conference.short_title), + notice: "The proposal was re-submitted. The #{@conference.short_title} organizers will review it again.") + else + redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), + error: "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}" end - - redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title), - notice: "The proposal was re-submitted. The #{@conference.short_title} organizers will review it again." end private @@ -152,5 +155,3 @@ class ProposalController < ApplicationController params.require(:user).permit(:email, :password, :password_confirmation, :username) end end - -# FIXME: Introduce strong_parameters pronto! diff --git a/app/views/proposal/index.html.haml b/app/views/proposal/index.html.haml index f9afd688..007299c2 100644 --- a/app/views/proposal/index.html.haml +++ b/app/views/proposal/index.html.haml @@ -87,7 +87,7 @@ method: :patch, class: 'btn btn-mini btn-success', id: "confirm_proposal_#{event.id}" - if event.transition_possible? :withdraw - = link_to 'Withdraw', conference_program_proposal_path(@conference.short_title, event.id), method: :delete, + = link_to 'Withdraw', withdraw_conference_program_proposal_path(@conference.short_title, event.id), method: :patch, data: { confirm: 'Are you sure you want to withdraw this proposal?' }, class: 'btn btn-mini btn-warning', id: "delete_proposal_#{event.id}" - if event.state == 'withdrawn' || event.state == 'rejected' diff --git a/config/routes.rb b/config/routes.rb index b22775e5..1c4eb7c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -95,11 +95,12 @@ Osem::Application.routes.draw do resources :conference, only: [:index, :show] do resource :program, except: :destroy do - resources :proposal do + resources :proposal, except: :destroy do get 'commercials/render_commercial' => 'commercials#render_commercial' resources :commercials, only: [:create, :update, :destroy] resources :event_attachment, controller: 'event_attachments' member do + patch '/withdraw' => 'proposal#withdraw' patch '/confirm' => 'proposal#confirm' patch '/restart' => 'proposal#restart' end