Class: Decidim::CurrentOrganization

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

Overview

A middleware that enhances the request with the current organization based on the hostname.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CurrentOrganization

Initializes the Rack Middleware.

app - The Rack application



10
11
12
# File 'app/middleware/decidim/current_organization.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
# File 'app/middleware/decidim/current_organization.rb', line 17

def call(env)
  organization = detect_current_organization(env)
  if organization
    env["decidim.current_organization"] = organization
    @app.call(env)
  else
    organization = find_secondary_host_org(env)
    return @app.call(env) unless organization

    location = new_location_for(env, organization.host)

    [301, { "Location" => location, "Content-Type" => "text/html", "Content-Length" => "0" }, []]
  end
end