Introduce Program to include cfp/rooms/tracks/events/event_types/difficulty_levels

This commit is contained in:
Stella Rouzi 2015-10-25 13:29:02 +02:00 committed by Henne Vogelsang
parent 028b82fda8
commit 444356fbc7
117 changed files with 1812 additions and 905 deletions

View file

@ -0,0 +1,58 @@
module Admin
class CfpsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program, singleton: true
def show; end
def new
@cfp = @program.build_cfp
end
def edit; end
def create
@cfp = @program.build_cfp(cfp_params)
if @cfp.save
redirect_to admin_conference_program_cfp_path,
notice: 'Call for papers successfully created.'
else
flash[:error] = "Creating the call for papers failed. #{@cfp.errors.full_messages.join('. ')}."
render :new
end
end
def update
@cfp = @program.cfp
@cfp.assign_attributes(params[:cfp])
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
if @cfp.update_attributes(params[:cfp])
Mailbot.delay.send_on_cfps_dates_updates(@conference) if send_mail_on_cfp_dates_updates
redirect_to(admin_conference_program_cfp_path(@conference.short_title),
notice: 'Call for papers successfully updated.')
else
flash[:error] = "Updating call for papers failed. #{@cfp.errors.to_a.join('. ')}."
render :new
end
end
def destroy
if @cfp.destroy
redirect_to admin_conference_program_cfp_path, notice: 'Call for Papers was successfully deleted.'
else
redirect_to admin_conference_program_cfp_path, error: 'An error prohibited this Call for Papers from being destroyed: '\
"#{@cfp.errors.full_messages.join('. ')}."
end
end
private
def cfp_params
params[:cfp]
end
end
end

View file

@ -22,7 +22,7 @@ module Admin
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
def grouped_comments(remarks)
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
remarks.group_by{ |comment| comment.commentable.program.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
end
end
end

View file

@ -1,6 +1,7 @@
module Admin
class ConferenceController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true, except: :index
load_resource :user, only: [:remove_user]
def index
@ -94,14 +95,17 @@ module Admin
end
def show
@conference = Conference.find_by(short_title: params[:id])
@program = @conference.program
unless @conference.program
@program = Program.new(conference_id: @conference.id)
end
# Overview and since last login information
@total_reg = @conference.registrations.count
@new_reg = @conference.registrations.where('created_at > ?', current_user.last_sign_in_at).count
@total_submissions = @conference.events.count
@new_submissions = @conference.events.
@total_submissions = @program.events.count
@new_submissions = @program.events.
where('created_at > ?', current_user.last_sign_in_at).count
@program_length = @conference.current_program_hours
@ -141,7 +145,7 @@ module Admin
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)
# Recent actions information
@recent_events = @conference.events.limit(5).order(created_at: :desc)
@recent_events = @conference.program.events.limit(5).order(created_at: :desc)
@recent_registrations = @conference.registrations.limit(5).order(created_at: :desc)
@top_submitter = @conference.get_top_submitter

View file

@ -1,23 +1,24 @@
module Admin
class DifficultyLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :difficulty_level, through: :conference
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program
def index
authorize! :index, DifficultyLevel.new(conference_id: @conference.id)
# authorize! :index, DifficultyLevel.new(program_id: @program.id)
end
def edit; end
def new
@difficulty_level = @conference.difficulty_levels.new
@difficulty_level = @conference.program.difficulty_levels.new
end
def create
@difficulty_level = @conference.difficulty_levels.new(difficulty_level_params)
@difficulty_level = @conference.program.difficulty_levels.new(difficulty_level_params)
if @difficulty_level.save
flash[:notice] = 'Difficulty level successfully created.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title))
else
flash[:error] = "Creating difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}."
render :new
@ -27,7 +28,7 @@ module Admin
def update
if @difficulty_level.update_attributes(difficulty_level_params)
flash[:notice] = 'Difficulty level successfully updated.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title))
else
flash[:error] = "Update difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}."
render :edit
@ -37,11 +38,11 @@ module Admin
def destroy
if @difficulty_level.destroy
flash[:notice] = 'Difficulty level successfully deleted.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title))
else
flash[:error] = 'Deleting difficulty level type failed! ' \
"#{@difficulty_level.errors.full_messages.join('. ')}."
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_difficulty_levels_path(conference_id: @conference.short_title))
end
end

View file

@ -1,23 +1,22 @@
module Admin
class EventTypesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :event_type, through: :conference
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event_type, through: :program
def index
authorize! :index, EventType.new(conference_id: @conference.id)
end
def index; end
def edit; end
def new
@event_type = @conference.event_types.new
@event_type = @conference.program.event_types.new
end
def create
@event_type = @conference.event_types.new(event_type_params)
@event_type = @conference.program.event_types.new(event_type_params)
if @event_type.save
flash[:notice] = 'Event type successfully created.'
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title))
else
flash[:error] = "Creating event type failed: #{@event_type.errors.full_messages.join('. ')}."
render :new
@ -27,7 +26,7 @@ module Admin
def update
if @event_type.update_attributes(event_type_params)
flash[:notice] = 'Event type successfully updated.'
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title))
else
flash[:error] = "Update event type failed: #{@event_type.errors.full_messages.join('. ')}."
render :edit
@ -37,11 +36,11 @@ module Admin
def destroy
if @event_type.destroy
flash[:notice] = 'Event type successfully deleted.'
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title))
else
flash[:error] = 'Destroying event type failed! ' \
"#{@event_type.errors.full_messages.join('. ')}."
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_event_types_path(conference_id: @conference.short_title))
end
end

View file

@ -1,7 +1,8 @@
module Admin
class EventsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :event, through: :conference
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event, through: :program
before_action :get_event, except: [:index, :create]
@ -14,13 +15,11 @@ module Admin
end
def index
authorize! :index, @conference.events.build
@conference = Conference.find_by(short_title: params[:conference_id])
@events = @conference.events
@tracks = @conference.tracks
@difficulty_levels = @conference.difficulty_levels
@events = @program.events
@tracks = @program.tracks
@difficulty_levels = @program.difficulty_levels
@machine_states = @events.state_machine.states.map
@event_types = @conference.event_types
@event_types = @program.event_types
@mystates = []
@mytypes = []
@ -72,26 +71,26 @@ module Admin
respond_to do |format|
format.html
# Explicity call #to_json to avoid the use of EventSerializer
format.json { render json: Event.where(state: :confirmed, conference: @conference).to_json }
format.json { render json: Event.where(state: :confirmed, program: @program).to_json }
end
end
def show
@tracks = @conference.tracks
@event_types = @conference.event_types
@tracks = @program.tracks
@event_types = @program.event_types
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
@ratings = @event.votes.includes(:user)
@difficulty_levels = @conference.difficulty_levels
@difficulty_levels = @program.difficulty_levels
end
def edit
@event_types = @conference.event_types
@event_types = @program.event_types
@tracks = Track.all
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
@user = @event.submitter
@url = admin_conference_event_path(@conference.short_title, @event)
@url = admin_conference_program_event_path(@conference.short_title, @event)
end
def comment
@ -101,7 +100,7 @@ module Admin
comment.move_to_child_of(params[:parent])
end
redirect_to admin_conference_event_path(conference_id: @conference.short_title)
redirect_to admin_conference_program_event_path(@conference.short_title, @event)
end
def update
@ -111,10 +110,10 @@ module Admin
render js: 'index'
else
flash[:notice] = "Successfully updated event with ID #{@event.id}."
redirect_back_or_to(admin_conference_event_path(@conference.short_title, @event))
redirect_back_or_to(admin_conference_program_event_path(@conference.short_title, @event))
end
else
@url = admin_conference_event_path(@conference.short_title, @event)
@url = admin_conference_program_event_path(@conference.short_title, @event)
flash[:notice] = 'Update not successful. ' + @event.errors.full_messages.to_sentence
render :edit
end
@ -123,8 +122,8 @@ module Admin
def create; end
def accept
send_mail = @event.conference.email_settings.send_on_accepted
subject = @event.conference.email_settings.accepted_subject.blank?
send_mail = @event.program.conference.email_settings.send_on_accepted
subject = @event.program.conference.email_settings.accepted_subject.blank?
update_state(:accept, 'Event accepted!', true, subject, send_mail)
end
@ -137,8 +136,8 @@ module Admin
end
def reject
send_mail = @event.conference.email_settings.send_on_rejected
subject = @event.conference.email_settings.rejected_subject.blank?
send_mail = @event.program.conference.email_settings.send_on_rejected
subject = @event.program.conference.email_settings.rejected_subject.blank?
update_state(:reject, 'Event rejected!', true, subject, send_mail)
end
@ -159,7 +158,7 @@ module Admin
end
respond_to do |format|
format.html { redirect_to admin_conference_event_path(@conference.short_title, @event) }
format.html { redirect_to admin_conference_program_event_path(@conference.short_title, @event) }
format.js
end
end
@ -181,9 +180,9 @@ module Admin
end
def get_event
@event = @conference.events.find_by_id(params[:id])
@event = @conference.program.events.find(params[:id])
if !@event
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
redirect_to(admin_conference_program_events_path(conference_id: @conference.short_title),
alert: 'Error! Could not find event!') && return
end
@event
@ -194,10 +193,10 @@ module Admin
if alert.blank?
flash[:notice] = notice
redirect_back_or_to(admin_conference_events_path(conference_id: @conference.short_title)) && return
redirect_back_or_to(admin_conference_program_events_path(conference_id: @conference.short_title)) && return
else
flash[:error] = alert
return redirect_back_or_to(admin_conference_events_path(conference_id: @conference.short_title)) && return
return redirect_back_or_to(admin_conference_program_events_path(conference_id: @conference.short_title)) && return
end
end
end

View file

@ -0,0 +1,32 @@
module Admin
class ProgramsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, singleton: true
def show; end
def edit; end
def update
authorize! :update, @conference.program
@program = @conference.program
@program.assign_attributes(params[:program])
# send_mail_on_schedule_public = @program.notify_on_schedule_public?
if @program.update_attributes(params[:program])
# Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
redirect_to(admin_conference_program_path(@conference.short_title),
notice: 'The program was successfully updated.')
else
flash[:error] = "Updating program failed. #{@program.errors.to_a.join('. ')}."
render :new
end
end
private
def program_params
params[:program]
end
end
end

View file

@ -1,23 +1,22 @@
module Admin
class RoomsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program
def index
authorize! :index, Room.new(conference_id: @conference.id)
end
def index; end
def edit; end
def new
@room = @conference.rooms.new
@room = @program.rooms.new
end
def create
@room = @conference.rooms.new(room_params)
@room = @program.rooms.new(room_params)
if @room.save
flash[:notice] = 'Room successfully created.'
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_rooms_path(conference_id: @conference.short_title))
else
flash[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
render :new
@ -27,7 +26,7 @@ module Admin
def update
if @room.update_attributes(room_params)
flash[:notice] = 'Room successfully updated.'
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_rooms_path(conference_id: @conference.short_title))
else
flash[:error] = "Update Room failed: #{@room.errors.full_messages.join('. ')}."
render :edit
@ -37,10 +36,10 @@ module Admin
def destroy
if @room.destroy
flash[:notice] = 'Room successfully deleted.'
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_rooms_path(conference_id: @conference.short_title))
else
flash[:error] = "Destroying room failed! #{@room.errors.full_messages.join('. ')}."
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_rooms_path(conference_id: @conference.short_title))
end
end

View file

@ -3,23 +3,24 @@ module Admin
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
# the schedule of a conference, which should not be accessed in the first place
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
skip_before_filter :verify_authenticity_token, only: [:update]
layout 'schedule'
def show
authorize! :update, @conference.events.new
authorize! :update, @program.events.new
if @conference.nil?
redirect_to admin_conference_index_path
return
end
@dates = @conference.start_date..@conference.end_date
@rooms = @conference.rooms
@rooms = @program.rooms
end
def update
authorize! :update, @conference.events.new
event = Event.where(guid: event_params).first
authorize! :update, @program.events.new
event = Event.where(guid: params[:event]).first
error_message = nil
if event.nil?
error_message = "Could not find event GUID: #{params[:event]}"

View file

@ -1,7 +1,8 @@
module Admin
class TracksController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :track, through: :conference
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program
def index; end
@ -13,14 +14,14 @@ module Admin
end
def new
@track = @conference.tracks.new
@track = @program.tracks.new
end
def create
@track = @conference.tracks.new(track_params)
@track = @program.tracks.new(track_params)
if @track.save
flash[:notice] = 'Track successfully created.'
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
else
flash[:error] = "Creating Track failed: #{@track.errors.full_messages.join('. ')}."
render :new
@ -32,7 +33,7 @@ module Admin
def update
if @track.update_attributes(track_params)
flash[:notice] = 'Track successfully updated.'
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
else
flash[:error] = "Track update failed: #{@track.errors.full_messages.join('. ')}."
render :edit
@ -42,10 +43,10 @@ module Admin
def destroy
if @track.destroy
flash[:notice] = 'Track successfully deleted.'
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
else
flash[:error] = "Track couldn't be deleted. #{@track.errors.full_messages.join('. ')}."
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title))
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
end
end

View file

@ -8,7 +8,7 @@ class CommercialsController < ApplicationController
authorize! :create, @commercial
if @commercial.save
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
notice: 'Commercial was successfully created.'
else
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
@ -18,7 +18,7 @@ class CommercialsController < ApplicationController
def update
if @commercial.update(commercial_params)
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
notice: 'Commercial was successfully updated.'
else
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
@ -28,7 +28,7 @@ class CommercialsController < ApplicationController
def destroy
@commercial.destroy
redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'),
redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id),
notice: 'Commercial was successfully destroyed.'
end
@ -44,7 +44,7 @@ class CommercialsController < ApplicationController
private
def set_event
@event = @conference.events.find(params[:proposal_id])
@event = @conference.program.events.find(params[:proposal_id])
end
def commercial_params

View file

@ -1,6 +1,7 @@
class ConferenceController < ApplicationController
before_filter :respond_to_options
load_and_authorize_resource find_by: :short_title
load_resource :program, through: :conference, singleton: true, except: :index
def index
@current = Conference.where('end_date >= ?', Date.current).order('start_date ASC')
@ -10,8 +11,8 @@ class ConferenceController < ApplicationController
def show; end
def schedule
@rooms = @conference.rooms
@events = @conference.events
@rooms = @conference.program.rooms
@events = @conference.program.events
@dates = @conference.start_date..@conference.end_date
if @dates == Date.current

View file

@ -1,7 +1,8 @@
class ProposalController < ApplicationController
before_filter :authenticate_user!, except: [:show, :new, :create]
load_resource :conference, find_by: :short_title
load_and_authorize_resource :event, parent: false, through: :conference
load_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event, parent: false, through: :program
def index
@events = current_user.proposals(@conference)
@ -14,16 +15,16 @@ class ProposalController < ApplicationController
def new
@user = User.new
@url = conference_proposal_index_path(@conference.short_title)
@url = conference_program_proposal_index_path(@conference.short_title)
end
def edit
authorize! :edit, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@url = conference_program_proposal_path(@conference.short_title, params[:id])
end
def create
@url = conference_proposal_index_path(@conference.short_title)
@url = conference_program_proposal_index_path(@conference.short_title)
unless current_user
@user = User.new(user_params)
@ -38,8 +39,8 @@ class ProposalController < ApplicationController
params[:event].delete :user
@event = Event.new(event_params)
@event.conference = @conference
@event = Event.new(params[:event])
@event.program = @program
@event.event_users.new(user: current_user,
event_role: 'submitter')
@ -55,12 +56,12 @@ class ProposalController < ApplicationController
ahoy.track 'Event submission', title: 'New submission'
flash[:notice] = 'Proposal was successfully submitted.'
redirect_to conference_proposal_index_path(@conference.short_title)
redirect_to conference_program_proposal_index_path(@conference.short_title)
end
def update
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@url = conference_program_proposal_path(@conference.short_title, params[:id])
if !@event.update(event_params)
flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}"
@ -68,13 +69,13 @@ class ProposalController < ApplicationController
return
end
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
redirect_to(conference_program_proposal_index_path(conference_id: @conference.short_title),
notice: 'Proposal was successfully updated.')
end
def destroy
authorize! :destroy, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@url = conference_program_proposal_path(@conference.short_title, params[:id])
begin
@event.withdraw
@ -84,13 +85,13 @@ class ProposalController < ApplicationController
end
@event.save(validate: false)
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
redirect_to(conference_program_proposal_index_path(conference_id: @conference.short_title),
notice: 'Proposal was successfully withdrawn.')
end
def confirm
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@url = conference_program_proposal_path(@conference.short_title, params[:id])
begin
@event.confirm!
@ -106,7 +107,7 @@ class ProposalController < ApplicationController
end
if @conference.user_registered?(current_user)
redirect_to(conference_proposal_index_path(@conference.short_title),
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),
@ -116,12 +117,12 @@ class ProposalController < ApplicationController
def restart
authorize! :update, @event
@url = conference_proposal_path(@conference.short_title, params[:id])
@url = conference_program_proposal_path(@conference.short_title, params[:id])
begin
@event.restart
rescue Transitions::InvalidTransition
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
redirect_to(conference_program_proposal_index_path(conference_id: @conference.short_title),
error: "The proposal can't be re-submitted.")
return
end
@ -132,7 +133,7 @@ class ProposalController < ApplicationController
return
end
redirect_to(conference_proposal_index_path(conference_id: @conference.short_title),
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