From 529b8eb71023fde621effee07f967ba29c09cb00 Mon Sep 17 00:00:00 2001 From: divyanshumehta Date: Sat, 11 Feb 2017 16:45:27 +0530 Subject: [PATCH] Solved Issue 1259 --- app/controllers/conferences_controller.rb | 7 ++++++- app/models/ability.rb | 2 +- config/routes.rb | 5 ++++- lib/root_route_constraint.rb | 10 ++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 lib/root_route_constraint.rb diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 53e5bd6d..5a502f94 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -2,7 +2,7 @@ class ConferencesController < ApplicationController protect_from_forgery with: :null_session before_action :respond_to_options load_and_authorize_resource find_by: :short_title - load_resource :program, through: :conference, singleton: true, except: :index + load_resource :program, through: :conference, singleton: true, except: [:index, :current] def index @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) @@ -11,6 +11,11 @@ class ConferencesController < ApplicationController def show; end + def current + current = Conference.first + redirect_to conference_path(current.short_title) + end + private def respond_to_options diff --git a/app/models/ability.rb b/app/models/ability.rb index 14913e75..ca979c94 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -29,7 +29,7 @@ class Ability # Abilities for not signed in users (guests) def not_signed_in - can [:index], Conference + can [:index, :current], Conference can [:show], Conference do |conference| conference.splashpage && conference.splashpage.public == true end diff --git a/config/routes.rb b/config/routes.rb index 9fa1c29a..3e88876e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ +require "root_route_constraint" Osem::Application.routes.draw do if ENV['OSEM_ICHAIN_ENABLED'] == 'true' @@ -147,6 +148,8 @@ Osem::Application.routes.draw do end get '/admin' => redirect('/admin/conferences') - + constraints RootRouteConstraint.new do + get '/' => 'conferences#current' + end root to: 'conferences#index', via: [:get, :options] end diff --git a/lib/root_route_constraint.rb b/lib/root_route_constraint.rb new file mode 100644 index 00000000..197fdffc --- /dev/null +++ b/lib/root_route_constraint.rb @@ -0,0 +1,10 @@ +class RootRouteConstraint + def initialize + @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) + end + + def matches?(*) + return unless @current.present? && @current.first.splashpage.present? + @current.count == 1 && @current.first.splashpage.public? + end +end