Sha256: d0c9b9496a8a5b20d89c1f183ed808d90651e0b06b7e8a033711b2c8b1f13a0b

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

require "fiona7/table_switcher"

module Fiona7
  module Middleware
    class TableSwitchingMiddleware
      def initialize(app)
        @app = app
      end

      def call(env)
        if Fiona7.mode == :legacy
          editing_context = env[Scrivito::EditingContextMiddleware::ENVKEY]

          use_preview = editing_context.authenticated_editor? && selected_workspace_id(editing_context) == 'rtc'

          (Fiona7::WriteObj.base_class.descendants - [Fiona7::ReleasedObj, Fiona7::InternalReleasedObj, Fiona7::EditedObj] + [Fiona7::WriteObj.base_class]).each do |descendant|
            TableSwitcher.new(
              descendant,
              use_preview ? "preview_objs" : "objs"
            ).switch
          end
        end

        @app.call(env)
      end

      def selected_workspace_id(editing_context)
        # NOTE: this does not require workspace lookup/load_obj
        # and thus is potentially faster
        editing_context.instance_variable_get(:@selected_workspace_id).to_s
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.2.3 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.2.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.2.2 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.1.4 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.1.3 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.3.2.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.3.2.0.pre.beta1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.2.1.0.pre.beta1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.5.2.0.0 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.1.1 lib/fiona7/middleware/table_switching_middleware.rb
infopark_fiona7-1.2.0.0.1 lib/fiona7/middleware/table_switching_middleware.rb