PaperTrail: info_for_paper_trail in API controller after authentication method

111 Views Asked by At

I have api controller which is inherited from ActionController::API API authentication is performed with some organization key like

   api_key = request.headers["HTTP_AUTHORIZATION_TOKEN"]
   @organization = Organization.find_by(api_key: api_key)

later I need to set whodunnit & whodunnit_type with @organization there are multiple type of organizations

Question: How can I make call to paper_trail method info_for_paper_trail after authentication

Currently what's happening info_for_paper_trail method is being called before authentication and at that time there is no @organization

What I tried:

1- I tried before_action filter in controller after authentication BUT what happens

  • info_for_paper_trail method is called 2 times one by default (by PaperTrail) other one which I set by before_action. In first attempt there is no @organization but in second attempt via before_action it set whodunnit & whodunnit_type but not saved in db entry of version table.
  • Secondly called info_for_paper_trail method inside authentication method which also set whodunnit & whodunnit_type but it's not being saved in version table entry.
0

There are 0 best solutions below