Sha256: cd52cde9db1914887d1a73f46d87dda5b6aa00d9a59f7adfd319826ec437e71c

Contents?: true

Size: 1.58 KB

Versions: 11

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

class WebhookTemplate < Template
  audited

  include Authorizable
  extend FriendlyId
  friendly_id :name
  include Parameterizable::ByIdName

  class << self
    # we have to override the base_class because polymorphic associations does not detect it correctly, more details at
    # http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many#1010-Polymorphic-has-many-within-inherited-class-gotcha
    def base_class
      self
    end
  end
  self.table_name = 'templates'

  before_destroy EnsureNotUsedBy.new(:webhooks)
  has_many :webhooks, foreign_key: :webhook_template_id

  validates :name, uniqueness: true

  include Taxonomix
  scoped_search on: :name,    complete_value: true, default_order: true
  scoped_search on: :locked,  complete_value: { true: true, false: false }
  scoped_search on: :snippet, complete_value: { true: true, false: false }
  scoped_search on: :template
  scoped_search on: :default, only_explicit: true, complete_value: { true: true, false: false }

  # with proc support, default_scope can no longer be chained
  # include all default scoping here
  default_scope lambda {
    with_taxonomy_scope do
      order("#{Template.table_name}.name")
    end
  }

  def self.default_render_scope_class
    ForemanWebhooks::Renderer::Scope::WebhookTemplate
  end

  def taxonomy_foreign_conditions
    { webhook_template_id: id }
  end

  def self.acceptable_template_input_types
    [:user]
  end

  def self.log_render_results?
    true
  end

  def support_single_host_render?
    false
  end

  def support_preview?
    false
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foreman_webhooks-3.1.1 app/models/webhook_template.rb
foreman_webhooks-3.1.0 app/models/webhook_template.rb
foreman_webhooks-3.0.5 app/models/webhook_template.rb
foreman_webhooks-2.0.3 app/models/webhook_template.rb
foreman_webhooks-3.0.4 app/models/webhook_template.rb
foreman_webhooks-2.0.2 app/models/webhook_template.rb
foreman_webhooks-3.0.3 app/models/webhook_template.rb
foreman_webhooks-3.0.2 app/models/webhook_template.rb
foreman_webhooks-3.0.1 app/models/webhook_template.rb
foreman_webhooks-2.0.1 app/models/webhook_template.rb
foreman_webhooks-3.0.0 app/models/webhook_template.rb