From 614da6003ba8ae6f77459f66ebcd3fa455949f34 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Sat, 6 Aug 2016 17:47:46 +0530 Subject: [PATCH] Display error if non existant conference's versions are queried --- app/controllers/admin/versions_controller.rb | 7 +++++-- app/views/admin/versions/index.html.haml | 7 +------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index b5eec406..16f38c15 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -8,9 +8,12 @@ module Admin @conference_id = params[:conference_id].to_i unless params[:conference_id].nil? if @conference_id.nil? @versions = PaperTrail::Version.where(["conference_id IN (?) OR item_type = 'User'", @conf_ids_for_organizer]) + elsif !Conference.exists?(id: @conference_id) + redirect_to admin_revision_history_path, error: "Conference with ID #{@conference_id} does not exist!" + return else - @versions = PaperTrail::Version.where(['conference_id IN (?)', (@conf_ids_for_organizer & [@conference_id])]). - where.not(item_type: 'User') + authorize! :index, PaperTrail::Version.new(conference_id: @conference_id) + @versions = PaperTrail::Version.where(conference_id: @conference_id) end end diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index 5408694d..456cda33 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -4,12 +4,7 @@ .dropdown.pull-right %button.btn.btn-success.dropdown-toggle{'data-toggle' => 'dropdown', type: 'button'} - - if @conference_id.nil? - All Conferences & Users - - elsif @conf_ids_for_organizer.include?(@conference_id) - = Conference.find(@conference_id).short_title - - else - Filter By Conference + = @conference_id.nil? ? 'All Conferences & Users' : Conference.find(@conference_id).short_title %span.caret %ul.dropdown-menu %li= link_to 'All Conferences & Users', admin_revision_history_path