require "fiona7/routing_monkey_patch" #require "active_record/railtie" require "scrivito" require "scrivito_sdk" require "scrivito_editors" require "scrivito/sdk_engine" require "infopark_fiona_connector" #require "rails_connector/engine" #require "rails_connector/fiona_engine" require "infopark_reactor" require "fiona7/initializer" require "fiona7/mode_switch" require "fiona7/controller_helper" require "fiona7/scrivito_patches/attribute_content" require "fiona7/scrivito_patches/attribute_serializer" require "fiona7/scrivito_patches/basic_obj" require "fiona7/scrivito_patches/basic_widget" require "fiona7/scrivito_patches/binary" require "fiona7/scrivito_patches/cms_backend" require "fiona7/scrivito_patches/child_list_tag" require "fiona7/scrivito_patches/cms_field_tag" require "fiona7/scrivito_patches/controller_actions" # different load order !! #require "fiona7/scrivito_patches/cms_dispatch_controller" require "fiona7/scrivito_patches/cms_rest_api" require "fiona7/scrivito_patches/cms_routing" require "fiona7/scrivito_patches/layout_tags" require "fiona7/scrivito_patches/link_parser" require "fiona7/scrivito_patches/migrator" require "fiona7/scrivito_patches/obj_data_from_rest" require "fiona7/scrivito_patches/page_config" require "fiona7/scrivito_patches/type_computer" require "fiona7/scrivito_patches/workspace" require "fiona7/fiona_connector_patches/cms_accessible" require "fiona7/middleware/table_switching_middleware" require "fiona7/middleware/server_detection_middleware" module Scrivito class LogSubscriber < ActiveSupport::LogSubscriber def backend_request(event) self.class.runtime += event.duration return unless logger.debug? duration = '(%.1fms)' % [event.duration] param = event.payload[:params] param_text = " #{param}" if param verb_text = event.payload[:verb].upcase path_text = event.payload[:path] debug " Fiona7 #{verb_text} #{path_text}#{param_text} #{duration}" end end end require "fiona7/routers/content_service" require "fiona7/routers/rest_api" require 'fiona7/scrivito_user' require 'fiona7/type_synchronizer' module Fiona7 mattr_accessor :mode mattr_accessor :login mattr_accessor :root class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode) end def self.configure(&block) Config.new.tap do |config| yield config Reactor::Configuration.xml_access = { host: config.host, port: config.port, id: 'f7', username: config.username, secret: config.secret } Fiona7::VeritySearchEngine::VeritySearchRequest.configured_host = config.host Fiona7::VeritySearchEngine::VeritySearchRequest.configured_port = config.port.to_i + 3 Fiona7.root = config.username Fiona7.mode = config.mode if Fiona7.login = !config.root_mode Scrivito.configure do |config| config.editing_auth do |env| request = ActionDispatch::Request.new(env) session = request.session rsession = session[:rsession] if rsession && rsession.user? Fiona7::ScrivitoUser.define(rsession.user) end end config.find_user do |user_id| user = Reactor::Cache::User.instance.get(user_id) Fiona7::ScrivitoUser.define(user) end end end if config.mode == :standalone RailsConnector::Configuration.mode = :editor end RailsConnector::Configuration.instance_name = config.instance end end class Engine < ::Rails::Engine config.to_prepare do # TODO: do some smart optimizations initializer = Fiona7::Initializer.new initializer.initialize_system end initializer "fiona7.mode_switch" do |app| mode = nil if Fiona7.mode == :standalone mode = :standalone elsif Fiona7.mode == :legacy mode = :legacy else raise "Invalid mode: #{Fiona7.mode}. Valid modes are :legacy and :standalone. Please refer to the documentation for more information" end # delayed init, patching sooner breaks AR # later and it breaks Obj require "fiona7/fiona_connector_patches/basic_obj" ModeSwitch::Composite.new(app).public_send(mode) end initializer "fiona7.remove_scrivito_deprecations" do |app| { 'cms_image_tag' => 'scrivito_image_tag', 'cms_path' => 'scrivito_path', 'cms_tag' => 'scrivito_tag', 'cms_tag_list' => 'scrivito_tag_list', 'cms_url' => 'scrivito_url', 'display_field' => 'scrivito_field', 'display_value' => 'scrivito_value', 'scrivito_after_content_tags' => 'scrivito_body_tags', 'scrivito_header_tags' => 'scrivito_head_tags', }.each_pair do |old_method_name, new_method_name| ScrivitoHelper.send(:remove_method, old_method_name) if ScrivitoHelper.method_defined?(old_method_name) end end initializer "fiona7.authorize_reactor" do |app| ActionController::Base.__send__(:define_method, :rsession_auth) do if !Fiona7.login rsession.user_name = Fiona7.root unless rsession.user_name == Fiona7.root end end end initializer "fiona7.patch_assets" do |app| app.config.assets.precompile += %w(fiona7_ui.css fiona7_ui.js fiona7.css fiona7.js fiona7-login.css) end initializer "fiona7.runtime_patches" do |app| end initializer "fiona7.preload_cms_type_defs" do |app| type_register = Fiona7::TypeRegister.instance RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |_, obj_class| type_register.read_mangled(obj_class.name) end end # This ensures that reactor is loaded in the app config.after_initialize { Fiona7::WriteObj } config.app_middleware.use "Fiona7::Middleware::TableSwitchingMiddleware" config.app_middleware.use "Fiona7::Middleware::ServerDetectionMiddleware" end end