spree/spree — pull request #5783 by HoyaBoya (2014-12-15 17:04:27+00:00)
Title: ThreadLocal the Current API User

This PR places the ```current_api_user``` into Thread Local storage to potentially use throughout Spree. I understand general pros/cons of leveraging ThreadLocal and this PR is intended to be a "dig your own grave" kinda thing, where it's there if you need it but to be used judiciously.

In this particular case, I need to understand which API user is making a POST /api/shipments call at the calculator level. If it is our 3PL, the calculator needs to change the prices from what an Admin or End User sees. I've thought about this a bunch of a different ways, i.e. making the 3Pl place an adjustment, trying to determine via the Order and Shipment States, Creating a 3PL Only Shipment With 3PL Calculator but these all encountered issues and for now, I'd like to have the option of adjusting the calculator's computation based on the current_api_user. Rather than change every single method signature to make this happen, ```Thread.current[:current_api_user]``` seems to be the smallest impact change possible, with the risk that the calculator's behavior is more opaque with how it works, per the general tradeoffs of a ThreadLocal pattern.