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/mode_switch" require "fiona7/scrivito_patches/attribute_content" require "fiona7/scrivito_patches/basic_obj" require "fiona7/scrivito_patches/basic_widget" require "fiona7/scrivito_patches/binary" require "fiona7/scrivito_patches/client_config" require "fiona7/scrivito_patches/controller_actions" require "fiona7/scrivito_patches/cms_dispatch_controller" require "fiona7/scrivito_patches/cms_rest_api" require "fiona7/scrivito_patches/cms_routing" require "fiona7/scrivito_patches/link_parser" require "fiona7/scrivito_patches/obj_class" require "fiona7/scrivito_patches/migrator" require "fiona7/scrivito_patches/type_computer" require "fiona7/scrivito_patches/workspace" require "fiona7/routers/content_service" require "fiona7/routers/rest_api" require 'fiona7/scrivito_user' module Fiona7 mattr_accessor :mode mattr_accessor :login 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.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 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 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 = 'root' unless rsession.user_name == 'root' end end end initializer "fiona7.patch_assets" do |app| app.config.assets.precompile += %w(fiona7.css fiona7.js fiona7-login.css) end initializer "fiona7.runtime_patches" do |app| # delayed init, patching sooner breaks AR require "fiona7/fiona_connector_patches/basic_obj" end # This ensures that reactor is loaded in the app config.after_initialize { Fiona7::WriteObj } end end