DEV: Check if plugin is enabled

This commit is contained in:
Peter Bouda 2024-10-22 09:48:23 +01:00
parent 922ff50e06
commit 4b8d576b13
2 changed files with 24 additions and 6 deletions

View file

@ -4,10 +4,20 @@ require "scimitar"
module Scim module Scim
class ScimV2::GroupsController < Scimitar::ActiveRecordBackedResourcesController class ScimV2::GroupsController < Scimitar::ActiveRecordBackedResourcesController
# TODO: Check why requires_plugin is not available here
# requires_plugin PLUGIN_NAME
protect_from_forgery with: :null_session 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
protected protected
def storage_class def storage_class
@ -17,6 +27,5 @@ module Scim
def storage_scope def storage_scope
Group.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require Group.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require
end end
end end
end end

View file

@ -4,10 +4,20 @@ require "scimitar"
module Scim module Scim
class ScimV2::UsersController < Scimitar::ActiveRecordBackedResourcesController class ScimV2::UsersController < Scimitar::ActiveRecordBackedResourcesController
# TODO: Check why requires_plugin is not available here
# requires_plugin PLUGIN_NAME
protect_from_forgery with: :null_session 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
protected protected
def storage_class def storage_class
@ -17,6 +27,5 @@ module Scim
def storage_scope def storage_scope
User.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require User.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require
end end
end end
end end