Browse Source

Maintenance: Move public collections to own function to make it more patchable.

Rolf Schmidt 2 years ago
parent
commit
d668b5d120
2 changed files with 12 additions and 9 deletions
  1. 1 9
      app/controllers/sessions_controller.rb
  2. 11 0
      lib/session_helper.rb

+ 1 - 9
app/controllers/sessions_controller.rb

@@ -12,15 +12,7 @@ class SessionsController < ApplicationController
     # return current session
     render json: SessionHelper.json_hash(user).merge(config: config_frontend)
   rescue Exceptions::NotAuthorized => e
-    render json: {
-      error:       e.message,
-      config:      config_frontend,
-      models:      SessionHelper.models,
-      collections: {
-        Locale.to_app_model     => Locale.where(active: true),
-        PublicLink.to_app_model => PublicLink.all,
-      }
-    }
+    render json: SessionHelper.json_hash_error(e).merge(config: config_frontend)
   end
 
   # "Create" a login, aka "log the user in"

+ 11 - 0
lib/session_helper.rb

@@ -11,6 +11,17 @@ module SessionHelper
     }
   end
 
+  def self.json_hash_error(error)
+    {
+      error:       error.message,
+      models:      models,
+      collections: {
+        Locale.to_app_model     => Locale.where(active: true),
+        PublicLink.to_app_model => PublicLink.all,
+      }
+    }
+  end
+
   def self.default_collections(user)
 
     # auto population collections, store all here