Merge pull request #907 from sonalkr132/proposal-test

Proposal controller improvements and test
This commit is contained in:
Henne Vogelsang 2016-04-01 14:49:50 +02:00
commit f56fc0052f
6 changed files with 617 additions and 43 deletions

View file

@ -24,15 +24,17 @@ 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)
authorize! :create, @user
if @user.save
sign_in(@user)
else
@ -47,39 +49,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 +90,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,24 +104,23 @@ 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'
return
end
if @conference.user_registered?(current_user)
redirect_to conference_program_proposal_index_path(@conference.short_title),
notice: 'The proposal was confirmed.'
if @event.save
if @conference.user_registered?(current_user)
redirect_to conference_program_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.'
end
else
redirect_to new_conference_conference_registrations_path(conference_id: @conference.short_title),
alert: 'The proposal was confirmed. Please register to attend the conference.'
redirect_to conference_program_proposal_index_path(conference_id: @conference.short_title),
error: "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}"
end
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!

View file

@ -44,7 +44,7 @@ class Ability
# can view Commercials of confirmed Events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
can :show, User
can [:show, :create], User
unless CONFIG['authentication']['ichain']['enabled']
can :show, Registration do |registration|
registration.new_record?

View file

@ -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'