check_feature_enabled.rb 581 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::CheckFeatureEnabled < Service::Base
  3. include Service::Concerns::HandlesSetting
  4. attr_reader :name, :exception
  5. def initialize(name: nil, exception: true)
  6. super()
  7. @name = name
  8. @exception = exception
  9. end
  10. def execute
  11. enabled = setting_enabled?(@name)
  12. return enabled if !@exception
  13. raise FeatureDisabledError if !enabled
  14. end
  15. class FeatureDisabledError < StandardError
  16. def initialize
  17. super(__('This feature is not enabled.'))
  18. end
  19. end
  20. end