about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-11 03:21:52 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-11 03:21:52 -0600
commit4c84b6dcad0a3d432ee36e66b878bcd4a658bfa2 (patch)
tree78ef8f85be56e4b011923ad2f1f8c07605552165 /app/controllers
parent6ab6b6dd29c1f8fd9cd2d4371f664ed4432b1d19 (diff)
move `monsterpit_api` helper to the application controller
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/base_controller.rb16
-rw-r--r--app/controllers/application_controller.rb14
2 files changed, 14 insertions, 16 deletions
diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb
index 9e2efc938..eca558f42 100644
--- a/app/controllers/api/base_controller.rb
+++ b/app/controllers/api/base_controller.rb
@@ -94,20 +94,4 @@ class Api::BaseController < ApplicationController
   def set_cache_headers
     response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
   end
-
-  def monsterfork_api
-    @monsterfork_api ||= _monsterfork_api
-  end
-
-  private
-
-  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
 end
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