lib/bento/controllers/account_scopable.rb in bento-0.0.1 vs lib/bento/controllers/account_scopable.rb in bento-0.0.2

- old
+ new

@@ -5,14 +5,43 @@ inherit_resources(*args) include AccountScopable::InstanceMethods end module InstanceMethods + private + def begin_of_association_chain - current_user.account + @account ||= current_account end - private :begin_of_association_chain + def current_account + if not_responding_to_admin? or admin? + account_by_param_or_session + else + current_user.account + end + end + + def admin? + respond_to_admin? and current_user.admin? + end + + def not_responding_to_admin? + (not respond_to_admin?) + end + + def respond_to_admin? + current_user.respond_to?(:admin?) + end + + def account_by_param_or_session + if account_id then Account.find(account_id) else current_user.account end + end + + def account_id + key, value = params.find { |key, value| key.to_s.ends_with?("account_id") } + value + end end end end end \ No newline at end of file