diff --git a/app/controllers/scim_v2/errors_controller.rb b/app/controllers/scim_v2/errors_controller.rb new file mode 100644 index 0000000..25165a0 --- /dev/null +++ b/app/controllers/scim_v2/errors_controller.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "scimitar" + +module Scim + class ScimV2::ErrorsController < Scimitar::ApplicationController + protect_from_forgery with: :null_session + + # We check for the plugin here manually as we do not inherit from Discourse's ApplicationController + # and do not have access to requires_plugin + before_action do + if plugin = Discourse.plugins_by_name[DiscourseScim::PLUGIN_NAME] + raise PluginDisabled.new if !plugin.enabled? + elsif Rails.env.test? + raise "Required plugin '#{DiscourseScim::PLUGIN_NAME}' not found. The string passed to requires_plugin should match the plugin's name at the top of plugin.rb" + else + Rails.logger.warn("Required plugin '#{DiscourseScim::PLUGIN_NAME}' not found") + end + end + + def not_found + handle_scim_error(Scimitar::NotFoundError.new(params["path"])) + end + end +end diff --git a/app/controllers/scim_v2/groups_controller.rb b/app/controllers/scim_v2/groups_controller.rb index 211b8b5..23990da 100644 --- a/app/controllers/scim_v2/groups_controller.rb +++ b/app/controllers/scim_v2/groups_controller.rb @@ -25,7 +25,7 @@ module Scim end def storage_scope - Group.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require + Group.all end end end \ No newline at end of file diff --git a/app/controllers/scim_v2/users_controller.rb b/app/controllers/scim_v2/users_controller.rb index 1f59809..6dab273 100644 --- a/app/controllers/scim_v2/users_controller.rb +++ b/app/controllers/scim_v2/users_controller.rb @@ -25,7 +25,7 @@ module Scim end def storage_scope - User.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require + User.all end end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0ffd60a..f37c702 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,6 @@ Discourse::Application.routes.draw { patch 'Groups/:id', to: 'groups#update' delete 'Groups/:id', to: 'groups#destroy' - # TODO: Add catchall that sends a not available - #get '*unmatched_route', to: 'application#raise_not_found!' + get '*path', to: 'errors#not_found' end }