Commit b8b6b83

mokha <mokha@cisco.com>
2018-06-11 18:56:15
split controller hierarchy.
1 parent ce367f7
Changed files (2)
app/controllers/scim/v2/groups_controller.rb
@@ -1,4 +1,3 @@
-
 # frozen_string_literal: true
 
 module Scim
app/controllers/scim/controller.rb
@@ -1,12 +1,12 @@
 # frozen_string_literal: true
 
 module Scim
-  class Controller < ApplicationController
+  class Controller < ActionController::Base
     protect_from_forgery with: :null_session
-    rescue_from ActiveRecord::RecordNotFound, with: :not_found
     before_action :apply_scim_content_type
-
-    private
+    before_action :authenticate!
+    helper_method :current_user
+    rescue_from ActiveRecord::RecordNotFound, with: :not_found
 
     def current_user
       @current_user ||= authenticate_with_http_token do |token|
@@ -14,10 +14,12 @@ module Scim
       end
     end
 
-    def authenticate!
-      render plain: "Unauthorized", status: :unauthorized unless current_user?
+    def current_user?
+      current_user.present?
     end
 
+    protected
+
     def not_found
       render json: {
         schemas: [Scim::Shady::Messages::ERROR],
@@ -26,6 +28,12 @@ module Scim
       }.to_json, status: :not_found
     end
 
+    private
+
+    def authenticate!
+      render plain: "Unauthorized", status: :unauthorized unless current_user?
+    end
+
     def apply_scim_content_type
       response.headers['Content-Type'] = Mime[:scim].to_s
     end