From 3244bd4d6971e9cbe3dd27de95ddae02416e2a49 Mon Sep 17 00:00:00 2001 From: Aaron Frase Date: Fri, 1 Mar 2024 11:08:55 -0500 Subject: [PATCH 1/3] Configure load paths of controllers and models Autoload once the app/controllers and app/models directories to prevent the uninitialized constants error. Removed `require_dependency` since it's obsolete and not needed with autoloading. Removed the note in the readme about Rails 7 NameError. --- README.md | 9 --------- .../active_record_backed_resources_controller.rb | 2 -- app/controllers/scimitar/resource_types_controller.rb | 2 -- app/controllers/scimitar/resources_controller.rb | 2 -- app/controllers/scimitar/schemas_controller.rb | 2 -- .../service_provider_configurations_controller.rb | 1 - lib/scimitar/engine.rb | 8 +++++++- 7 files changed, 7 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a51af5f..e4424ff 100644 --- a/README.md +++ b/README.md @@ -79,15 +79,6 @@ Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({ When it comes to token access, Scimitar neither enforces nor presumes any kind of encoding for bearer tokens. You can use anything you like, including encoding/encrypting JWTs if you so wish - https://rubygems.org/gems/jwt may be useful. The way in which a client might integrate with your SCIM service varies by client and you will have to check documentation to see how a token gets conveyed to that client in the first place (e.g. a full OAuth flow with your application, or just a static token generated in some UI which an administrator copies and pastes into their client's SCIM configuration UI). -**Important:** Under Rails 7 or later, you may need to wrap any Scimitar configuration with `Rails.application.config.to_prepare do...` to avoid `NameError: uninitialized constant...` exceptions arising due to autoloader problems: - -```ruby -Rails.application.config.to_prepare do - Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({ - # ... - end -end -``` ### Routes diff --git a/app/controllers/scimitar/active_record_backed_resources_controller.rb b/app/controllers/scimitar/active_record_backed_resources_controller.rb index 9cab1bd..dc4a0d3 100644 --- a/app/controllers/scimitar/active_record_backed_resources_controller.rb +++ b/app/controllers/scimitar/active_record_backed_resources_controller.rb @@ -1,5 +1,3 @@ -require_dependency "scimitar/application_controller" - module Scimitar # An ActiveRecord-centric subclass of Scimitar::ResourcesController. See that diff --git a/app/controllers/scimitar/resource_types_controller.rb b/app/controllers/scimitar/resource_types_controller.rb index 154226b..7bdaf74 100644 --- a/app/controllers/scimitar/resource_types_controller.rb +++ b/app/controllers/scimitar/resource_types_controller.rb @@ -1,5 +1,3 @@ -require_dependency "scimitar/application_controller" - module Scimitar class ResourceTypesController < ApplicationController def index diff --git a/app/controllers/scimitar/resources_controller.rb b/app/controllers/scimitar/resources_controller.rb index 514db83..c39c32b 100644 --- a/app/controllers/scimitar/resources_controller.rb +++ b/app/controllers/scimitar/resources_controller.rb @@ -1,5 +1,3 @@ -require_dependency "scimitar/application_controller" - module Scimitar # A Rails controller which is mostly idiomatic, with #index, #show, #create diff --git a/app/controllers/scimitar/schemas_controller.rb b/app/controllers/scimitar/schemas_controller.rb index 946e8d6..36d173f 100644 --- a/app/controllers/scimitar/schemas_controller.rb +++ b/app/controllers/scimitar/schemas_controller.rb @@ -1,5 +1,3 @@ -require_dependency "scimitar/application_controller" - module Scimitar class SchemasController < ApplicationController def index diff --git a/app/controllers/scimitar/service_provider_configurations_controller.rb b/app/controllers/scimitar/service_provider_configurations_controller.rb index 28a6beb..f08a4b0 100644 --- a/app/controllers/scimitar/service_provider_configurations_controller.rb +++ b/app/controllers/scimitar/service_provider_configurations_controller.rb @@ -1,4 +1,3 @@ -require_dependency "scimitar/application_controller" module Scimitar class ServiceProviderConfigurationsController < ApplicationController def show diff --git a/lib/scimitar/engine.rb b/lib/scimitar/engine.rb index e72a6eb..501ad07 100644 --- a/lib/scimitar/engine.rb +++ b/lib/scimitar/engine.rb @@ -1,6 +1,12 @@ +require 'rails/engine' + module Scimitar - class Engine < ::Rails::Engine + class Engine < Rails::Engine isolate_namespace Scimitar + config.autoload_once_paths = %W( + #{root}/app/controllers + #{root}/app/models + ) Mime::Type.register 'application/scim+json', :scim From 04b66bb6a4b6d1c020045ad525665df6f36c83f7 Mon Sep 17 00:00:00 2001 From: Aaron Frase Date: Mon, 4 Mar 2024 12:31:40 -0500 Subject: [PATCH 2/3] Use a string for rescue_from to avoid undefined constant error --- .../scimitar/active_record_backed_resources_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/scimitar/active_record_backed_resources_controller.rb b/app/controllers/scimitar/active_record_backed_resources_controller.rb index dc4a0d3..af77941 100644 --- a/app/controllers/scimitar/active_record_backed_resources_controller.rb +++ b/app/controllers/scimitar/active_record_backed_resources_controller.rb @@ -17,7 +17,7 @@ module Scimitar # class ActiveRecordBackedResourcesController < ResourcesController - rescue_from ActiveRecord::RecordNotFound, with: :handle_resource_not_found # See Scimitar::ApplicationController + rescue_from 'ActiveRecord::RecordNotFound', with: :handle_resource_not_found # See Scimitar::ApplicationController before_action :obtain_id_column_name_from_attribute_map From 8ff9af6bffb355b59ec615983e09d97358d0c765 Mon Sep 17 00:00:00 2001 From: Andrew Hodgkinson Date: Thu, 28 Mar 2024 14:31:51 +1300 Subject: [PATCH 3/3] A bit of tidying after merging #106 --- README.md | 11 +++++++++++ lib/scimitar/engine.rb | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd23d80..3d4908c 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,17 @@ Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({ When it comes to token access, Scimitar neither enforces nor presumes any kind of encoding for bearer tokens. You can use anything you like, including encoding/encrypting JWTs if you so wish - https://rubygems.org/gems/jwt may be useful. The way in which a client might integrate with your SCIM service varies by client and you will have to check documentation to see how a token gets conveyed to that client in the first place (e.g. a full OAuth flow with your application, or just a static token generated in some UI which an administrator copies and pastes into their client's SCIM configuration UI). +**Strongly recommended:** You should wrap any Scimitar configuration with `Rails.application.config.to_prepare do...` so that any changes you make to configuration during local development are reflected via auto-reload, rather than requiring a server restart. + +```ruby +Rails.application.config.to_prepare do + Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({ + # ... + end +end +``` + +In general, Scimitar's own development and tests assume this approach. If you choose to put the configuration directly into an initializer file without the `to_prepare` wrapper, you will be at a _slightly_ higher risk of tripping over unrecognised Scimitar bugs; please make sure that your own application test coverage is reasonably comprehensive. ### Routes diff --git a/lib/scimitar/engine.rb b/lib/scimitar/engine.rb index 501ad07..24e2420 100644 --- a/lib/scimitar/engine.rb +++ b/lib/scimitar/engine.rb @@ -1,8 +1,9 @@ require 'rails/engine' module Scimitar - class Engine < Rails::Engine + class Engine < ::Rails::Engine isolate_namespace Scimitar + config.autoload_once_paths = %W( #{root}/app/controllers #{root}/app/models