From 51d569794f07d8568055c7e9c531c3e3248991a2 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Mon, 15 Aug 2016 16:42:12 +0530 Subject: [PATCH] Add conference specifc route to revision history page --- app/controllers/admin/versions_controller.rb | 11 +++++------ app/views/admin/versions/index.html.haml | 7 +++---- app/views/layouts/_admin_sidebar.html.haml | 5 +++++ config/routes.rb | 2 ++ spec/controllers/admin/versions_controller_spec.rb | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index 0020cf96..34aeffd1 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -1,15 +1,14 @@ module Admin class VersionsController < Admin::BaseController + load_resource :conference, find_by: :short_title load_and_authorize_resource class: PaperTrail::Version def index - authorize! :index, PaperTrail::Version.new(item_type: 'User') - @conf_ids_for_organizer = current_user.is_admin? ? Conference.pluck(:id) : Conference.with_role(:organizer, current_user).pluck(:id) - @conference_id = params[:conference_id].to_i unless params[:conference_id].nil? + @conf_ids_for_organizer = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role(:organizer, current_user).pluck(:short_title) - return unless @conference_id.present? - authorize! :index, PaperTrail::Version.new(conference_id: @conference_id) - @versions = @versions.where(conference_id: @conference_id) + return unless @conference.present? + authorize! :index, PaperTrail::Version.new(conference_id: @conference.id) + @versions = @versions.where(conference_id: @conference.id) end def revert_attribute diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index 456cda33..d7cc9798 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -4,13 +4,12 @@ .dropdown.pull-right %button.btn.btn-success.dropdown-toggle{'data-toggle' => 'dropdown', type: 'button'} - = @conference_id.nil? ? 'All Conferences & Users' : Conference.find(@conference_id).short_title + = @conference.nil? ? 'All Conferences & Users' : @conference.short_title %span.caret %ul.dropdown-menu %li= link_to 'All Conferences & Users', admin_revision_history_path - - @conf_ids_for_organizer.each do |conf_id| - - conference = Conference.find(conf_id) - %li= link_to conference.short_title, admin_revision_history_path(conference_id: conference.id) + - @conf_ids_for_organizer.each do |conference_short_title| + %li= link_to conference_short_title, admin_conference_revision_history_path(conference_id: conference_short_title) %h1 Revision History %p.text-muted diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 62645e0c..0d2fe3c0 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -136,3 +136,8 @@ = link_to(admin_conference_roles_path(@conference.short_title)) do %span.fa.fa-group Roles + - if can? :index, PaperTrail::Version.new(item_type: 'User') + %li{:class=> active_nav_li(admin_conference_revision_history_path(@conference.short_title))} + = link_to(admin_conference_revision_history_path(@conference.short_title)) do + %span.fa.fa-history + Revision History diff --git a/config/routes.rb b/config/routes.rb index 7bd331d9..6426b0d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -95,6 +95,8 @@ Osem::Application.routes.draw do patch :update_conference end end + + get '/revision_history' => 'versions#index' end get '/revision_history' => 'versions#index' diff --git a/spec/controllers/admin/versions_controller_spec.rb b/spec/controllers/admin/versions_controller_spec.rb index 6ebd3052..f1400e3b 100644 --- a/spec/controllers/admin/versions_controller_spec.rb +++ b/spec/controllers/admin/versions_controller_spec.rb @@ -102,7 +102,7 @@ describe Admin::VersionsController do it 'raises error if user is not an organizer of specified conference' do user = create(:user) sign_in user - get :index, conference_id: conference.id + get :index, conference_id: conference.short_title expect(flash[:alert]).to match('You are not authorized to access this area.') end end