Add conference specifc route to revision history page

This commit is contained in:
Nishanth Vijayan 2016-08-15 16:42:12 +05:30
parent 5965bcf193
commit 51d569794f
5 changed files with 16 additions and 11 deletions

View file

@ -1,15 +1,14 @@
module Admin module Admin
class VersionsController < Admin::BaseController class VersionsController < Admin::BaseController
load_resource :conference, find_by: :short_title
load_and_authorize_resource class: PaperTrail::Version load_and_authorize_resource class: PaperTrail::Version
def index def index
authorize! :index, PaperTrail::Version.new(item_type: 'User') @conf_ids_for_organizer = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role(:organizer, current_user).pluck(:short_title)
@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?
return unless @conference_id.present? return unless @conference.present?
authorize! :index, PaperTrail::Version.new(conference_id: @conference_id) authorize! :index, PaperTrail::Version.new(conference_id: @conference.id)
@versions = @versions.where(conference_id: @conference_id) @versions = @versions.where(conference_id: @conference.id)
end end
def revert_attribute def revert_attribute

View file

@ -4,13 +4,12 @@
.dropdown.pull-right .dropdown.pull-right
%button.btn.btn-success.dropdown-toggle{'data-toggle' => 'dropdown', type: 'button'} %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 %span.caret
%ul.dropdown-menu %ul.dropdown-menu
%li= link_to 'All Conferences & Users', admin_revision_history_path %li= link_to 'All Conferences & Users', admin_revision_history_path
- @conf_ids_for_organizer.each do |conf_id| - @conf_ids_for_organizer.each do |conference_short_title|
- conference = Conference.find(conf_id) %li= link_to conference_short_title, admin_conference_revision_history_path(conference_id: conference_short_title)
%li= link_to conference.short_title, admin_revision_history_path(conference_id: conference.id)
%h1 Revision History %h1 Revision History
%p.text-muted %p.text-muted

View file

@ -136,3 +136,8 @@
= link_to(admin_conference_roles_path(@conference.short_title)) do = link_to(admin_conference_roles_path(@conference.short_title)) do
%span.fa.fa-group %span.fa.fa-group
Roles 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

View file

@ -95,6 +95,8 @@ Osem::Application.routes.draw do
patch :update_conference patch :update_conference
end end
end end
get '/revision_history' => 'versions#index'
end end
get '/revision_history' => 'versions#index' get '/revision_history' => 'versions#index'

View file

@ -102,7 +102,7 @@ describe Admin::VersionsController do
it 'raises error if user is not an organizer of specified conference' do it 'raises error if user is not an organizer of specified conference' do
user = create(:user) user = create(:user)
sign_in 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.') expect(flash[:alert]).to match('You are not authorized to access this area.')
end end
end end