Sha256: 69113f1bcf4df4e7c7e87ef791c936f572b5a05ce7e4af2c0672c101e586467d

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Decidim
  # Redirects users with short links to the correct location on the site.
  class ShortLinksController < Decidim::ApplicationController
    skip_before_action :store_current_location

    # The index action redirects the user to the application root in case
    # someone tries to request the short link URL without an identifier.
    def index
      redirect_to decidim.root_path, status: :moved_permanently
    end

    # Redirects the user to the target URL that the short link is set to
    # redirect to. Raises an ActionController::RoutingError in case a short link
    # does not exist with the given identifier.
    #
    # @raise [ActionController::RoutingError] if a short link does not exist
    #   with the given identifier
    def show
      raise ActionController::RoutingError, "Not Found" unless link

      redirect_to link.target_url, status: :moved_permanently
    end

    private

    # Fetches the link based on the provided identifier in the parameters.
    #
    # @return [Decidim::ShortLink] The short link matching the identifier
    def link
      @link ||= Decidim::ShortLink.find_by(identifier: params[:id], organization: current_organization)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.4 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.9 app/controllers/decidim/short_links_controller.rb
decidim-core-0.29.0 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.3 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.8 app/controllers/decidim/short_links_controller.rb
decidim-core-0.29.0.rc4 app/controllers/decidim/short_links_controller.rb
decidim-core-0.29.0.rc3 app/controllers/decidim/short_links_controller.rb
decidim-core-0.29.0.rc2 app/controllers/decidim/short_links_controller.rb
decidim-core-0.29.0.rc1 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.2 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.7 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.1 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.6 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.0 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.5 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.0.rc5 app/controllers/decidim/short_links_controller.rb
decidim-core-0.28.0.rc4 app/controllers/decidim/short_links_controller.rb
decidim-core-0.27.4 app/controllers/decidim/short_links_controller.rb