Commit ef74358

mo <mo.khan@gmail.com>
2019-01-13 20:57:33
load resource types into configuration
1 parent 4178df9
Changed files (2)
app
controllers
config
initializers
app/controllers/scim/v2/resource_types_controller.rb
@@ -6,45 +6,19 @@ module Scim
       skip_before_action :authenticate!
 
       def index
-        render status: :ok, json: [user_resource, group_resource].to_json
+        render status: :ok, json: resource_types.values.to_json
       end
 
       def show
+        current_resource = resource_types[params[:id]]
+        raise ActiveRecord::RecordNotFound unless current_resource
         render status: :ok, json: current_resource.to_json
       end
 
       private
 
-      def current_resource(id = params[:id])
-        if id == 'User'
-          user_resource
-        elsif id == 'Group'
-          group_resource
-        else
-          raise ActiveRecord::RecordNotFound
-        end
-      end
-
-      def user_resource
-        location = scim_v2_resource_type_url(id: 'User')
-        Scim::Kit::V2::ResourceType.build(location: location) do |x|
-          x.id = 'User'
-          x.name = 'User'
-          x.schema = Scim::Kit::V2::Schemas::USER
-          x.description = 'User Account'
-          x.endpoint = scim_v2_users_url
-        end
-      end
-
-      def group_resource
-        location = scim_v2_resource_type_url(id: 'Group')
-        Scim::Kit::V2::ResourceType.build(location: location) do |x|
-          x.id = 'Group'
-          x.name = 'Group'
-          x.schema = Scim::Kit::V2::Schemas::GROUP
-          x.description = 'Group'
-          x.endpoint = scim_v2_groups_url
-        end
+      def resource_types
+        Scim::Kit::V2.configuration.resource_types
       end
     end
   end
config/initializers/scim_kit.rb
@@ -7,5 +7,15 @@ ActiveSupport::Notifications.subscribe 'proof.routes_loaded' do
       x.documentation_uri = url_helpers.documentation_url
       x.add_authentication(:oauthbearertoken, primary: true)
     end
+    config.resource_type(id: 'User', location: url_helpers.scim_v2_resource_type_url(id: 'User')) do |x|
+      x.name = 'User'
+      x.schema = Scim::Kit::V2::Schemas::USER
+      x.endpoint = url_helpers.scim_v2_users_url
+    end
+    config.resource_type(id: 'Group', location: url_helpers.scim_v2_resource_type_url(id: 'Group')) do |x|
+      x.name = 'Group'
+      x.schema = Scim::Kit::V2::Schemas::GROUP
+      x.endpoint = url_helpers.scim_v2_groups_url
+    end
   end
 end