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 end end # module Scrivito