Class: Decidim::DecidimAwesome::CurrentConfig

Inherits:
Object
  • Object
show all
Defined in:
app/middleware/decidim/decidim_awesome/current_config.rb

Overview

A middleware that stores the current awesome context by parsing the request

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CurrentConfig

Initializes the Rack Middleware.

app - The Rack application



10
11
12
# File 'app/middleware/decidim/decidim_awesome/current_config.rb', line 10

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Main entry point for a Rack Middleware.

env - A Hash.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/middleware/decidim/decidim_awesome/current_config.rb', line 17

def call(env)
  @request = Rack::Request.new(env)
  if @request.env["decidim.current_organization"] && processable_path?
    @config = awesome_config_instance
    env["decidim_awesome.current_config"] = @config
    tamper_user_model
    add_flash_message_from_request(env)

    # puts "requested path: #{env["PATH_INFO"]}"
    # puts "current_organization: #{@request.env["decidim.current_organization"]&.id}"
    # puts "potential_admins: #{Decidim::User.awesome_potential_admins}"
    # puts "scoped admins: #{Decidim::User.awesome_admins_for_current_scope}"
  else
    reset_user_model
  end

  @app.call(env)
end