From 4c84b6dcad0a3d432ee36e66b878bcd4a658bfa2 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 11 Jan 2020 03:21:52 -0600 Subject: move `monsterpit_api` helper to the application controller --- app/controllers/application_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 333082f68..84dc516fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,6 +126,16 @@ class ApplicationController < ActionController::Base @theme = resolve_pack(Themes.instance.flavour(current_flavour), pack_name, current_skin) end + def _monsterfork_api + return :basic if current_user.nil? + return current_user.monsterfork_api.to_sym unless doorkeeper_token && doorkeeper_token.application.present? + app = doorkeeper_token.application.name.downcase.strip.gsub(/ +/, '_').gsub(/[^\w.-]/, '') + return :vanilla if ENV.fetch('MONSTERFORK_API_FORCE_VANILLA', '').downcase.split.include?(app) + return :basic if ENV.fetch('MONSTERFORK_API_FORCE_BASIC', '').downcase.split.include?(app) + return :full if ENV.fetch('MONSTERFORK_API_FORCE_FULL', '').downcase.split.include?(app) + current_user.monsterfork_api.to_sym + end + protected def truthy_param?(key) @@ -230,4 +240,8 @@ class ApplicationController < ActionController::Base def mark_cacheable! expires_in 0, public: true end + + def monsterfork_api + @monsterfork_api ||= _monsterfork_api + end end -- cgit