module Decidim::Paddable

A concern with the components needed when you want a model to be able to create links from it to another resource.

Public Instance Methods

build_pad_url(id) click to toggle source
# File lib/decidim/paddable.rb, line 80
def build_pad_url(id)
  [
    Decidim.etherpad.fetch(:server),
    "p",
    id
  ].join("/")
end
etherpad() click to toggle source
# File lib/decidim/paddable.rb, line 58
def etherpad
  @etherpad ||= EtherpadLite.connect(
    Decidim.etherpad.fetch(:server),
    Decidim.etherpad.fetch(:api_key),
    Decidim.etherpad.fetch(:api_version, "1.2.1")
  )
end
pad() click to toggle source

Public: Returns a EtherpadLite::Pad instance if Etherpad is configured.

# File lib/decidim/paddable.rb, line 29
def pad
  return if Decidim.etherpad.blank?
  return unless component.settings.enable_pads_creation

  @pad ||= etherpad.pad(pad_id)
end
pad_id() click to toggle source
# File lib/decidim/paddable.rb, line 66
def pad_id
  @pad_id ||= [reference, token].join("-").slice(0, 50)
end
pad_is_visible?() click to toggle source

Public: Whether to show the pad or not.

True by default if a Pad exists.

This should be overwritten at the included model to customise the rules. Returns a Boolean.

# File lib/decidim/paddable.rb, line 42
def pad_is_visible?
  pad
end
pad_is_writable?() click to toggle source

Public: Whether the pad is writable or not.

True by default if a Pad exists.

This should be overwritten at the included model to customise the rules. Returns a Boolean.

# File lib/decidim/paddable.rb, line 52
def pad_is_writable?
  pad
end
pad_public_url() click to toggle source

Public: The String with the URL to access the pad with read/write permissions.

# File lib/decidim/paddable.rb, line 15
def pad_public_url
  return unless pad

  build_pad_url pad.id
end
pad_read_only_url() click to toggle source

Public: The String with the URL to access the pad with read permissions only.

# File lib/decidim/paddable.rb, line 22
def pad_read_only_url
  return unless pad

  build_pad_url pad.read_only_id
end
token() click to toggle source

compatibilize with old versions if no salt available (less secure)

# File lib/decidim/paddable.rb, line 71
def token
  if defined?(salt) && salt.present?
    tokenizer = Decidim::Tokenizer.new(salt: salt)
    return tokenizer.hex_digest(id)
  end

  Digest::MD5.hexdigest("#{id}-#{Rails.application.secrets.secret_key_base}")
end