Sha256: b71058b62606a838214531bf7d41dfc288007968a32a450b09deecc16cad61da

Contents?: true

Size: 1.39 KB

Versions: 32

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Decidim
  # Shared behaviour for signed_in users that require the latest TOS accepted
  module HasStoredPath
    extend ActiveSupport::Concern

    included do
      # Saves the location before loading each page so we can return to the
      # right page.
      before_action :store_current_location
    end

    # Stores the url where the user will be redirected after login.
    #
    # Uses the `redirect_url` param or the current url if there's no param.
    # In Devise controllers we only store the URL if it's from the params, we don't
    # want to overwrite the stored URL for a Devise one.
    def store_current_location
      return if skip_store_location?

      value = redirect_url || request.url
      store_location_for(:user, value)
    end

    def skip_store_location?
      # Skip if Devise already handles the redirection
      return true if devise_controller? && redirect_url.blank?
      # Skip for all non-HTML requests"
      return true unless request.format.html?
      # Skip if a signed in user requests the TOS page without having agreed to
      # the TOS. Most of the times this is because of a redirect to the TOS
      # page (in which case the desired location is somewhere else after the
      # TOS is agreed).
      return true if current_user && !current_user.tos_accepted? && request.path == URI(tos_path).path

      false
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.8 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.7 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.6 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.10 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.9 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.5 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.8 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.4 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.3 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.7 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.5 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.2 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.1 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.4 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.0 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.3 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.0.rc2 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.27.0.rc1 app/controllers/concerns/decidim/has_stored_path.rb
decidim-core-0.26.2 app/controllers/concerns/decidim/has_stored_path.rb