Sha256: ecb2f5218071afdac48530bb9fe9a225bce4f03c7cb0b1805b58b65917f91976
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true module Decidim module DecidimAwesome module AdminNotFoundRedirect extend ActiveSupport::Concern included do # rubocop:disable Rails/LexicallyScopedActionFilter: before_action :redirect_unallowed_scoped_admins, only: :not_found # rubocop:enable Rails/LexicallyScopedActionFilter private def redirect_unallowed_scoped_admins return unless request.original_fullpath =~ %r{^(/+)admin} return unless Decidim::User.respond_to? :awesome_potential_admins return unless defined? current_user return unless Decidim::User.awesome_potential_admins.include? current_user.id # assiging a flash message here does not work after redirection due the order of middleware in Rails # as a workaround, send a message through a get parameter path = "/admin/?unauthorized" referer = request.headers["Referer"] if referer uri = URI(referer) params = Rack::Utils.parse_query uri.query unless request.params.has_key? "unauthorized" params["unauthorized"] = nil path = "#{uri.path}?#{Rack::Utils.build_query(params)}" end end redirect_to path end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-decidim_awesome-0.7.2 | app/controllers/concerns/decidim/decidim_awesome/admin_not_found_redirect.rb |