Add handling of PaperTrail.whodunnit to Registrant API controllers

This commit is contained in:
Maciej Szlosarczyk 2018-08-17 13:31:53 +03:00
parent 07072ec6cb
commit 3ee5291b57
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 23 additions and 12 deletions

View file

@ -6,6 +6,7 @@ module Api
module Registrant
class BaseController < ActionController::API
before_action :authenticate
before_action :set_paper_trail_whodunnit
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
error = {}
@ -41,6 +42,12 @@ module Api
render json: { errors: [{base: ['Not authorized']}] }, status: :unauthorized
end
end
# This controller does not inherit from ApplicationController,
# so user_for_paper_trail method is not usable.
def set_paper_trail_whodunnit
::PaperTrail.whodunnit = current_user.id_role_username
end
end
end
end