Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track request acceptance and activation #1597

7 changes: 7 additions & 0 deletions .haml-lint_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ linters:
- "app/views/tracks/_form.html.haml"
- "app/views/tracks/index.html.haml"
- "app/views/tracks/show.html.haml"
- "app/views/conferences/_call_for_tracks.html.haml"
- "app/views/admin/tracks/_change_state_dropdown.html.haml"
- "app/views/proposals/_encouragement_text.html.haml"

# Offense count: 223
InstanceVariables:
Expand Down Expand Up @@ -242,6 +245,9 @@ linters:
- "app/views/schedules/_schedule_tabs.html.haml"
- "app/views/admin/cfps/_events_cfp.html.haml"
- "app/views/tracks/_form.html.haml"
- "app/views/admin/cfps/_tracks_cfp.html.haml"
- "app/views/conferences/_call_for_tracks.html.haml"
- "app/views/admin/tracks/_change_state_dropdown.html.haml"

# Offense count: 32
IdNames:
Expand All @@ -261,6 +267,7 @@ linters:
- "app/views/admin/users/show.html.haml"
- "app/views/users/edit.html.haml"
- "app/views/admin/cfps/_events_cfp.html.haml"
- "app/views/admin/cfps/_tracks_cfp.html.haml"

# Offense count: 4
UnnecessaryInterpolation:
Expand Down
5 changes: 5 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ Metrics/BlockLength:
# Offense count: 23
Metrics/CyclomaticComplexity:
Max: 12
Exclude:
- 'app/models/track.rb'

# Offense count: 2353
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
Expand All @@ -339,6 +341,8 @@ Metrics/ModuleLength:
# Offense count: 15
Metrics/PerceivedComplexity:
Max: 16
Exclude:
- 'app/models/track.rb'

# Offense count: 20
Style/AccessorMethodName:
Expand Down Expand Up @@ -565,6 +569,7 @@ Style/PercentLiteralDelimiters:
- 'app/models/subscription.rb'
- 'app/uploaders/picture_uploader.rb'
- 'spec/models/program_spec.rb'
- 'app/models/track.rb'

# Offense count: 2
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
Expand Down
24 changes: 10 additions & 14 deletions app/assets/javascripts/osem-datatables.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
$(function () {
$(document).ready(function() {
$('.datatable').DataTable({
// ajax: ...,
stateSave: true,
autoWidth: false,
pagingType: 'full_numbers',
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
});
$('.datatable').DataTable({
// ajax: ...,
stateSave: true,
autoWidth: false,
pagingType: 'full_numbers',
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
});

$('#versionstable').DataTable({
pagingType: 'full_numbers',
order: [[ 0, 'desc' ]]
});
$('#versionstable').DataTable({
pagingType: 'full_numbers',
order: [[ 0, 'desc' ]]
});
});


6 changes: 3 additions & 3 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def set_timezone_for_this_request(&block)

def index
@events = @program.events
@tracks = @program.tracks
@tracks = @program.tracks.confirmed.cfp_active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need the tracks to have cfp_active, so that we are able to move events from one track to another during evaluation period.
Let's look into that later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #1631

@difficulty_levels = @program.difficulty_levels
@event_types = @program.event_types
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)
Expand All @@ -43,7 +43,7 @@ def index
end

def show
@tracks = @program.tracks
@tracks = @program.tracks.confirmed.cfp_active
@event_types = @program.event_types
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
Expand All @@ -58,7 +58,7 @@ def show

def edit
@event_types = @program.event_types
@tracks = Track.all
@tracks = @program.tracks.confirmed.cfp_active
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
@user = @event.submitter
Expand Down
60 changes: 57 additions & 3 deletions app/controllers/admin/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class TracksController < Admin::BaseController
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program, find_by: :short_name

# Show flash message with ajax calls
after_action :prepare_unobtrusive_flash, only: :toggle_cfp_inclusion

def index; end

def show
Expand All @@ -19,6 +22,8 @@ def new

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.'
Expand Down Expand Up @@ -53,16 +58,65 @@ def destroy
def toggle_cfp_inclusion
@track.cfp_active = !@track.cfp_active
if @track.save
head :ok
flash[:notice] = "Successfully changed cfp inclusion of #{@track.name} to #{@track.cfp_active}"
else
head :unprocessable_entity
flash[:error] = "Failed to toggle cfp inclusion of #{@track.name} to #{@track.cfp_active}"
end

respond_to do |format|
format.js
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)
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
29 changes: 26 additions & 3 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,6 @@ def edit; end
def create
@track = @program.tracks.new(track_params)
@track.submitter = current_user
@track.state = 'new'
@track.cfp_active = false
if @track.save
redirect_to conference_program_tracks_path(conference_id: @conference.short_title),
Expand All @@ -39,9 +38,33 @@ def update
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, :relevance)
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
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def dynamic_association(association_name, title, form_builder, options = {})
end

def tracks(conference)
all = conference.program.tracks.map {|t| t.name}
all = conference.program.tracks.confirmed.cfp_active.pluck(:name)
first = all[0...-1]
last = all[-1]
ts = ''
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ def canceled_replacement_event_label(event, event_schedule, *label_classes)
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you using the scopes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have the scopes when I initially wrote that code, and then I forgot about it

include_blank: true
end
end
end
10 changes: 10 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def signed_in(user)
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)

can [:destroy], Openid

can [:new, :create], Track do |track|
track.new_record? && track.program.cfps.for_tracks.try(:open?)
end

can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should be able to access show action of confirmed tracks, to get their details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find the details of the track in admin/Tracks#show

Copy link
Contributor Author

@AEtherC0r3 AEtherC0r3 Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The users can see the name and description of every confirmed track included in the cfp in the conference's splashpage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also show them then the room and the dates of the track, when available.


can [:edit, :update], Track do |track|
user == track.submitter && !(track.accepted? || track.confirmed?)
end
end

# Abilities for users with roles wandering around in non-admin views.
Expand Down
4 changes: 4 additions & 0 deletions app/models/admin_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ def signed_in_with_track_organizer_role(user)

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'
Expand Down
22 changes: 19 additions & 3 deletions app/models/cfp.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# cannot delete program if there are events submitted

class Cfp < ActiveRecord::Base
TYPES = %w(events booths).freeze

scope :for_events, (-> { find_by(cfp_type: 'events') })
TYPES = %w(events booths tracks).freeze

has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
belongs_to :program
Expand Down Expand Up @@ -78,6 +76,24 @@ def open?
(start_date..end_date).cover?(Date.current)
end

##
# Finds the cfp for events if it exists
#
# ====Returns
# * +Cfp+ -> The cfp with type 'events'
def self.for_events
find_by(cfp_type: 'events')
end

##
# Finds the cfp for tracks if it exists
#
# ====Returns
# * +Cfp+ -> The cfp with type 'tracks'
def self.for_tracks
find_by(cfp_type: 'tracks')
end

private

def before_end_of_conference
Expand Down
8 changes: 8 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down Expand Up @@ -303,4 +304,11 @@ def before_end_of_conference
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
1 change: 1 addition & 0 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Room < ActiveRecord::Base
include RevisionCount
belongs_to :venue
has_many :event_schedules, dependent: :destroy
has_many :tracks

has_paper_trail ignore: [:guid], meta: { conference_id: :conference_id }

Expand Down
Loading