Sha256: 7cce4e413d8c04e8d86aacd2b65c1f6548a4d092d48d6f90092f7a066b13e8b7

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_webhooks-2.0.0 app/models/webhook_template.rb
foreman_webhooks-1.1.0 app/models/webhook_template.rb
foreman_webhooks-1.0.0 app/models/webhook_template.rb
foreman_webhooks-0.0.3 app/models/webhook_template.rb
foreman_webhooks-0.0.2 app/models/webhook_template.rb
foreman_webhooks-0.0.1 app/models/webhook_template.rb