about summary refs log tree commit diff
path: root/app/controllers/api/base_controller.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-11 02:41:35 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-11 02:41:35 -0600
commitff67dbed2b2878ba0d8032bdde08e06bc0eead3e (patch)
tree805919a162596e67dc8803f9db7892eefc289ea4 /app/controllers/api/base_controller.rb
parentd9a9a18afae94ec0a2160e746265e47d7b639eaf (diff)
pass monsterfork api exposure setting to all serializers + add `MONSTERFORK_API_FORCE_*` env vars to set api compatability modes for clients/apps
Diffstat (limited to 'app/controllers/api/base_controller.rb')
-rw-r--r--app/controllers/api/base_controller.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb
index eca558f42..dd81b09e5 100644
--- a/app/controllers/api/base_controller.rb
+++ b/app/controllers/api/base_controller.rb
@@ -94,4 +94,20 @@ 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 :full 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(/ +/, '_')
+    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