Skip to content

Commit

Permalink
feat: allow register webhooks to be controlled via config
Browse files Browse the repository at this point in the history
Also adds ability to reset global error.
  • Loading branch information
macite committed Jul 15, 2024
1 parent 2fcb477 commit e01ed19
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/helpers/turn_it_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ def self.enabled?
Doubtfire::Application.config.tii_enabled
end

def self.register_webhooks?
Doubtfire::Application.config.tii_register_webhook
end

def self.load_config(config)
config.tii_enabled = ENV['TII_ENABLED'].present? && (ENV['TII_ENABLED'].to_s.downcase == "true" || ENV['TII_ENABLED'].to_i == 1)

config.tii_add_submissions_to_index = ENV['TII_INDEX_SUBMISSIONS'].present? && (ENV['TII_INDEX_SUBMISSIONS'].to_s.downcase == "true" || ENV['TII_INDEX_SUBMISSIONS'].to_i == 1)

if config.tii_enabled
config.tii_add_submissions_to_index = ENV['TII_INDEX_SUBMISSIONS'].present? && (ENV['TII_INDEX_SUBMISSIONS'].to_s.downcase == "true" || ENV['TII_INDEX_SUBMISSIONS'].to_i == 1)
config.tii_register_webhook = ENV['TII_REGISTER_WEBHOOK'].present? && (ENV['TII_REGISTER_WEBHOOK'].to_s.downcase == "true" || ENV['TII_REGISTER_WEBHOOK'].to_i == 1)

# Turn-it-in TII configuration
require 'tca_client'

Expand All @@ -40,7 +45,7 @@ def self.load_config(config)

# Launch the tii background jobs
def self.launch_tii(with_webhooks: true)
TiiRegisterWebHookJob.perform_async if with_webhooks
TiiRegisterWebHookJob.perform_async if with_webhooks && TurnItIn.register_webhooks?
load_tii_features
load_tii_eula
rescue StandardError => e
Expand Down Expand Up @@ -89,6 +94,12 @@ def self.global_error?
Rails.cache.exist?("tii.global_error") || @@global_error.present?
end

# Clear a global error
def self.clear_global_error
@@global_error = nil
Rails.cache.delete("tii.global_error")
end

# Indicates that tii can be called, that it is configured and there are no global errors
def self.functional?
TurnItIn.enabled? && !TurnItIn.global_error?
Expand Down

0 comments on commit e01ed19

Please sign in to comment.