Browse Source

Set paper trail whodunnit

pull/17/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
c62723319b
  1. 36
      app/controllers/api/doctrines_controller.rb
  2. 15
      app/controllers/api/documents_controller.rb
  3. 2
      app/controllers/application_controller.rb

36
app/controllers/api/doctrines_controller.rb

@ -0,0 +1,36 @@
module Api
class DoctrinesController < BaseController
authorize_resource :doctrine, class: "Doctrine", only: %i[index]
def index
search = doctrine_search(search_params)
@doctrines = search.results
respond_with @doctrines
end
private
def doctrine_search(search_params)
search = Sunspot.search(Doctrine) do
with(:subject_ids).any_of(search_params[:subject_ids]) if search_params[:subject_ids].present?
with(:user_ids).any_of(search_params[:user_ids]) if search_params[:user_ids].present?
if search_params[:created_at].present?
with(:created_at).between(Date.parse(search_params[:created_at]..Time.zone.today.to_date)
end
end
search
end
def search_params
params.permit(subject_ids: [], user_ids: [], :created_at)
end
end
end

15
app/controllers/api/documents_controller.rb

@ -0,0 +1,15 @@
module Api
class DocumentsController < BaseController
include JurisprudenceSearch
authorize_resource :document, class: "Cdao::Document", only: %i[index]
def index
search = jurisprudence_search(search_params)
@jurisprudences = search.results
respond_with @jurisprudences
end
end
end

2
app/controllers/application_controller.rb

@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_paper_trail_whodunnit
rescue_from CanCan::AccessDenied do |exception| rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, notice: "You are not authorized to access this page." redirect_to root_url, notice: "You are not authorized to access this page."
end end

Loading…
Cancel
Save