owen2345 / camaleon_oauth

This is a plugin for Camaleon CMS that support oauth integration
MIT License
3 stars 3 forks source link

include CamaleonCms::SessionHelper in global scope is unhealthy #9

Open p-decoraid opened 8 years ago

p-decoraid commented 8 years ago

This:

https://github.com/owen2345/camaleon_oauth/blob/master/config/initializers/doorkeeper.rb#L1

makes methods like current_user available in the global scope.

However, current_user invokes cama_calc_api_current_user which invokes doorkeeper_token. doorkeeper_token is not available in the global scope, hence current_user fails.

Furthermore, cama_current_user has a cache for the current user value - @cama_current_user. This is an instance variable which again is not accessible from the global scope.

Instead of putting methods into the global scope, specific classes or modules should include CamaleonCms::SessionHelper etc.

owen2345 commented 8 years ago

This plugin was not updated since Camaleon_cms 1.x, if you can fix and update I will appreciate. I think this plugin can be very useful for angularjs integration. Regards,

p-decoraid commented 8 years ago

I am trying to do that, however running into current_user being nil right now. The impression I get is that camaleon-oauth is overwriting some global state set up by camaleon-cms because I am able to check out using a test camaleon-cms installation with camaleon-ecommerce but without camaleon-oauth.

Here is a stack trace:

 - draper (2.1.0) lib/draper/helper_proxy.rb:35:in `block in define_proxy'
 - /home/oleg/apps/backend/vendor/cache/camaleon-cms-1d25088e16b3/app/helpers/camaleon_cms/session_helper.rb:144:in `cama_calc_api_current_user'
 - /home/oleg/apps/backend/vendor/cache/camaleon-cms-1d25088e16b3/app/helpers/camaleon_cms/session_helper.rb:110:in `cama_current_user'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/decorators/plugins/ecommerce/product_decorator.rb:108:in `the_qty_real'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/decorators/plugins/ecommerce/product_item_decorator.rb:34:in `decrement_qty!'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/models/plugins/ecommerce/cart.rb:82:in `block in make_order!'
 - draper (2.1.0) lib/draper/delegation.rb:10:in `each'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/models/plugins/ecommerce/cart.rb:82:in `make_order!'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/models/plugins/ecommerce/cart.rb:148:in `make_paid!'
 - draper (2.1.0) lib/draper/delegation.rb:10:in `make_paid!'
 - draper (2.1.0) lib/draper/automatic_delegation.rb:10:in `method_missing'
 - /home/oleg/apps/backend/vendor/cache/camaleon-ecommerce-a8543f617be2/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb:5:in `mark_order_like_received'

How is mark_order_like_received/make_paid!/make_order! intended to make current_user work?

Here is something else related. prod is a Product instance in this mark_order_like_received etc. process:

(byebug) prod.current_user
#, @context={}>
(byebug) prod.cama_current_user
*** NoMethodError Exception: undefined method `cama_current_user' for #
nil

Where is the current_user method defined that ends up being on the product instance?