Implement track request acceptance

Allow track submitter to request specific dates
Redirect to Tracks#edit if a track doesn't have a room or start/end date
before accepting it

Don't allow the submitter or the track organizers to edit the request
after it has been accepted or confirmed

Restrict track selection in proposals and move track selection from
Proposals form to events helper

Mark cfp_active of the tracks table as not null and fill in true if nil
This commit is contained in:
AEtherC0r3 2017-07-14 15:57:34 +03:00 committed by Stella Rouzi
parent 2f9eb04219
commit d9faffc96a
27 changed files with 909 additions and 62 deletions

View file

@ -20,6 +20,7 @@ module Admin
def create
@track = @program.tracks.new(track_params)
@track.state = 'confirmed'
@track.cfp_active = true
if @track.save
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully created.'
@ -60,10 +61,55 @@ module Admin
end
end
def restart
update_state(:restart, "Review for #{@track.name} started!")
end
def to_accept
update_state(:to_accept, "Track #{@track.name} marked as a possible acceptance!")
end
def accept
if @track.room && @track.start_date && @track.end_date
update_state(:accept, "Track #{@track.name} accepted!")
else
flash[:alert] = 'Please make sure that the track has a room and start/end dates before accepting it'
redirect_to edit_admin_conference_program_track_path(@conference.short_title, @track)
end
end
def confirm
update_state(:confirm, "Track #{@track.name} confirmed!")
end
def to_reject
update_state(:to_reject, "Track #{@track.name} marked as a possible rejection!")
end
def reject
update_state(:reject, "Track #{@track.name} rejected!")
end
def cancel
update_state(:cancel, "Track #{@track.name} canceled!")
end
private
def track_params
params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active, :start_date, :end_date, :room_id)
end
def update_state(transition, notice)
errors = @track.update_state(transition)
if errors.blank?
flash[:notice] = notice
else
flash[:error] = errors
end
redirect_back_or_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
end
end
end

View file

@ -4,7 +4,7 @@ class TracksController < ApplicationController
load_and_authorize_resource through: :program, find_by: :short_name
def index
@tracks = current_user.tracks.where(program: @program)
@tracks = @tracks.where(submitter: current_user)
end
def show; end
@ -38,9 +38,33 @@ class TracksController < ApplicationController
end
end
def restart
update_state(:restart, "Track #{@track.name} re-submitted.")
end
def confirm
update_state(:confirm, "Track #{@track.name} confirmed.")
end
def withdraw
update_state(:withdraw, "Track #{@track.name} withdrawn.")
end
private
def track_params
params.require(:track).permit(:name, :description, :color, :short_name)
params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date)
end
def update_state(transition, notice)
errors = @track.update_state(transition)
if errors.blank?
flash[:notice] = notice
else
flash[:error] = errors
end
redirect_back_or_to(conference_program_tracks_path(conference_id: @conference.short_title))
end
end

View file

@ -56,7 +56,7 @@ module ApplicationHelper
end
def tracks(conference)
all = conference.program.tracks.map { |t| t.name if !t.self_organized? || t.confirmed? && t.cfp_active }.compact
all = conference.program.tracks.where(state: 'confirmed', cfp_active: true).pluck(:name)
first = all[0...-1]
last = all[-1]
ts = ''

View file

@ -39,4 +39,12 @@ module EventsHelper
content_tag :span, 'REPLACEMENT', class: (['label', 'label-info'] + label_classes)
end
end
def track_selector_input(form)
if @program.tracks.any?
form.input :track_id, as: :select,
collection: @program.tracks.where(state: 'confirmed', cfp_active: true).pluck(:name, :id),
include_blank: true
end
end
end

View file

@ -100,8 +100,10 @@ class Ability
track.new_record? && track.program.cfps.for_tracks.try(:open?)
end
can [:index, :show, :edit, :update], Track do |track|
user == track.submitter
can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id
can [:edit, :update], Track do |track|
user == track.submitter && !(track.accepted? || track.confirmed?)
end
end

View file

@ -275,6 +275,10 @@ class AdminAbility
can :manage, Track, id: track_ids_for_track_organizer
cannot [:edit, :update], Track do |track|
track.self_organized_and_accepted_or_confirmed?
end
# Show Roles in the admin sidebar and allow authorization of the index action
can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track'

View file

@ -45,6 +45,7 @@ class Event < ActiveRecord::Base
validates :max_attendees, numericality: { only_integer: true, greater_than_or_equal_to: 1, allow_nil: true }
validate :max_attendees_no_more_than_room_size
validate :acceptable_track
scope :confirmed, -> { where(state: 'confirmed') }
scope :canceled, -> { where(state: 'canceled') }
@ -303,4 +304,11 @@ class Event < ActiveRecord::Base
def conference_id
program.conference_id
end
##
# Allow only confirmed tracks that belong to the same program and are included in the cfp
def acceptable_track
return unless track && track.program && program
errors.add(:track, 'is invalid') unless track.confirmed? && track.cfp_active && track.program == program
end
end

View file

@ -22,13 +22,13 @@ class Track < ActiveRecord::Base
}
validates :state,
presence: true,
inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) },
if: :self_organized?
validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized?
inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }
validates :cfp_active, inclusion: { in: [true, false] }
validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed?
validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed?
validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed?
validate :valid_dates, if: :self_organized_and_accepted_or_confirmed?
validate :valid_dates
validate :valid_room, if: :self_organized_and_accepted_or_confirmed?
before_validation :capitalize_color
@ -45,7 +45,7 @@ class Track < ActiveRecord::Base
event :restart do
transitions to: :new, from: [:rejected, :withdrawn, :canceled]
end
event :readiness_to_accept do
event :to_accept do
transitions to: :to_accept, from: [:new]
end
event :accept do
@ -54,7 +54,7 @@ class Track < ActiveRecord::Base
event :confirm do
transitions to: :confirmed, from: [:accepted], on_transition: :assign_role_to_submitter
end
event :readiness_to_reject do
event :to_reject do
transitions to: :to_reject, from: [:new]
end
event :reject do
@ -107,6 +107,7 @@ class Track < ActiveRecord::Base
events.each do |event|
event.track = nil
event.save!
end
end
@ -137,6 +138,19 @@ class Track < ActiveRecord::Base
self_organized? && (accepted? || confirmed?)
end
def update_state(transition)
error = ''
begin
send(transition)
rescue Transitions::InvalidTransition => e
error += "State update failed. #{e.message} "
end
error += errors.full_messages.join(', ') unless save
error
end
private
def generate_guid
@ -162,26 +176,32 @@ class Track < ActiveRecord::Base
end
def valid_dates
return unless start_date && end_date
if program && program.conference && program.conference.start_date && (start_date < program.conference.start_date)
errors.add(:start_date, "can't be before the conference start date (#{program.conference.end_date})")
if start_date && program && program.conference && program.conference.start_date && (start_date < program.conference.start_date)
errors.add(:start_date, "can't be before the conference start date (#{program.conference.start_date})")
end
if program && program.conference && program.conference.start_date && (end_date < program.conference.start_date)
errors.add(:end_date, "can't be before the conference start date (#{program.conference.end_date})")
if end_date && program && program.conference && program.conference.start_date && (end_date < program.conference.start_date)
errors.add(:end_date, "can't be before the conference start date (#{program.conference.start_date})")
end
if program && program.conference && program.conference.end_date && (start_date > program.conference.end_date)
if start_date && program && program.conference && program.conference.end_date && (start_date > program.conference.end_date)
errors.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})")
end
if program && program.conference && program.conference.end_date && (end_date > program.conference.end_date)
if end_date && program && program.conference && program.conference.end_date && (end_date > program.conference.end_date)
errors.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})")
end
if start_date > end_date
errors.add(:start_date, 'can\'t be after the end_date')
if start_date && end_date && (start_date > end_date)
errors.add(:start_date, 'can\'t be after the end date')
end
end
##
# Verify that the room is a room of the conference
def valid_room
if room && room.venue && room.venue.conference && program && program.conference && (program.conference != room.venue.conference)
errors.add(:room, "must be a room of #{program.conference.venue.name}")
end
end
end

View file

@ -0,0 +1,34 @@
- if track.transition_possible? :restart
%li= link_to 'Start review',
restart_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "restart_track_#{track.id}"
- if track.transition_possible? :to_accept
%li= link_to 'Mark as possible acceptance',
to_accept_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "to_accept_track_#{track.id}"
- if track.transition_possible? :accept
%li= link_to 'Accept track request',
accept_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "accept_track_#{track.id}"
- if track.transition_possible? :confirm
%li= link_to 'Confirm track',
confirm_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "confirm_track_#{track.id}"
- if track.transition_possible? :to_reject
%li= link_to 'Mark as possible rejection',
to_reject_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "to_reject_track_#{track.id}"
- if track.transition_possible? :reject
%li= link_to 'Reject track request',
reject_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, confirm: 'Are you sure?', id: "reject_track_#{track.id}"
- if track.transition_possible? :cancel
%li= link_to 'Cancel track request',
cancel_admin_conference_program_track_path(@conference.short_title, track),
method: :patch, id: "cancel_track_#{track.id}"

View file

@ -19,6 +19,5 @@
- else
Please add a venue with rooms, if you want to select a room for the track.
= f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint
- if @track.self_organized?
= f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal'
= f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal'
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -40,21 +40,24 @@
= track.color
%td
- if track.self_organized?
= track.state
.btn-group
%button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' }
= track.state.humanize
%span.caret
%ul.dropdown-menu{ role: 'menu' }
= render 'change_state_dropdown', track: track
- else
= track.state.humanize
%td
- if track.self_organized?
= check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active,
class: 'switch-checkbox', method: :patch,
url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=",
data: { size: 'small',
on_color: 'success',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }
- else
%i.fa.fa-check
= check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active,
class: 'switch-checkbox', method: :patch,
url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=",
data: { size: 'small',
on_color: 'success',
off_color: 'warning',
on_text: 'Yes',
off_text: 'No' }
%td
- if track.room
= link_to track.room.name, admin_conference_venue_room_path(@conference.short_title, track.room.id)
@ -72,8 +75,9 @@
N/A
%td
.btn-group{role: "group"}
= link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary'
- if can? :edit, track
= link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary'
- if can? :destroy, track
= link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track),
method: :delete, class: 'btn btn-danger',

View file

@ -6,10 +6,7 @@
= speaker_selector_input f
- if @program.tracks.any?
= f.input :track_id, as: :select,
collection: @program.tracks.map {|track| ["#{track.name}", track.id] },
include_blank: true
= track_selector_input f
= f.input :event_type_id, as: :select,
collection: @conference.program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id,

View file

@ -9,9 +9,11 @@
Track
.row
.col-md-12
= semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path : conference_program_track_path(@conference.short_title, @track))) do |f|
= semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path(@conference.short_title) : conference_program_track_path(@conference.short_title, @track))) do |f|
= f.input :name
= f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }
= f.input :color, input_html: {size: 6, type: 'color'}, required: true
= f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' }
= f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' }
= f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: markdown_hint
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -16,6 +16,8 @@
%th Description
%th Color
%th State
%th Start Date
%th End Date
%th Actions
%tbody
- @tracks.each do |track|
@ -34,10 +36,31 @@
%td
= track.state.humanize
%td
= link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary'
- if track.start_date
= track.start_date.strftime('%A, %B %-d. %Y')
- else
N/A
%td
- if track.end_date
= track.end_date.strftime('%A, %B %-d. %Y')
- else
N/A
%td
- if track.transition_possible? :confirm
= link_to 'Confirm', confirm_conference_program_track_path(@conference.short_title, track),
method: :patch, class: 'btn btn-mini btn-success', id: "confirm_track_#{track.id}"
- if track.transition_possible? :withdraw
= link_to 'Withdraw', withdraw_conference_program_track_path(@conference.short_title, track),
method: :patch, data: { confirm: 'Are you sure you want to withdraw this track request?' },
class: 'btn btn-mini btn-warning', id: "withdraw_track_request_#{track.id}"
- if track.transition_possible? :restart
= link_to 'Re-Submit', restart_conference_program_track_path(@conference.short_title, track),
method: :patch, class: 'btn btn-mini btn-success', id: "resubmit_track_request_#{track.id}"
- if can? :edit, track
= link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary'
.row
.col-md-12
- if can? :create, @track
- if can? :new, @program.tracks.new
= link_to "New Track request", new_conference_program_track_path(@conference.short_title), class: 'btn btn-success pull-right'

View file

@ -17,10 +17,25 @@
State:
%dd
= @track.state.humanize
%dt
Start date:
%dd
- if @track.start_date
= @track.start_date.strftime('%A, %B %-d. %Y')
- else
N/A
%dt
End date:
%dd
- if @track.end_date
= @track.end_date.strftime('%A, %B %-d. %Y')
- else
N/A
%dt
Description
%dd
= @track.description
.row
.col-md-12.text-right
= link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary'
- if can? :edit, @track
= link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary'