Sha256: cb0eaef3e777c1e8051131f2ea83d7b289dd2c75861cdb9e2225489bb6245076
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module Decidim module DecidimAwesome module Admin class CustomRedirectForm < Decidim::Form include Decidim::TranslatableAttributes attribute :origin, String attribute :destination, String attribute :active, Boolean attribute :pass_query, Boolean validates :origin, :destination, presence: true validate :different_origin_destination def to_params [ sanitize_url(origin), { destination: sanitize_url(destination, strip_host: false), active: active, pass_query: pass_query } ] end def sanitize_url(url, strip_host: true) url = url.strip parsed = Addressable::URI.parse(url) url = parsed.path if strip_host && parsed.host == current_organization.host url = "/#{url}" unless url.match?(%r{^https?://|^/}) url end private def different_origin_destination return if sanitize_url(origin) != sanitize_url(destination) errors.add(:destination, :invalid) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems