module Scrivito class WorkspaceSelectionMiddleware def initialize(app) @app = app end def call(env) Workspace.current = proc do editing_context = env[EditingContextMiddleware::ENVKEY] if editing_context.authenticated_editor? editing_context.visible_workspace else Workspace.published_with_fallback end end @app.call(env) end private def session(env) env[Rack::Session::Abstract::ENV_SESSION_KEY] end end end # module Scrivito