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/child_list_tag" require "fiona7/scrivito_patches/cms_backend" require "fiona7/scrivito_patches/cms_field_tag" # 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/log_subscriber" require "fiona7/scrivito_patches/link_parser" require "fiona7/scrivito_patches/migrator" require "fiona7/scrivito_patches/model_library" require "fiona7/scrivito_patches/obj_params_parser" require "fiona7/scrivito_patches/page_config" require "fiona7/scrivito_patches/preset_routes" require "fiona7/scrivito_patches/routing_extensions" 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" # components require "fiona7/recursive_object_finder" require "fiona7/complex_object" require "fiona7/routers/rest_api" require 'fiona7/scrivito_user' require 'fiona7/type_synchronizer' require 'fiona7/naive_search_engine' require 'fiona7/verity_search_engine' # tools require 'fiona7/tools/attribute_remover' module Fiona7 mattr_accessor :mode mattr_accessor :login mattr_accessor :root mattr_accessor :callbacks self.callbacks = { :create_obj => [], :update_obj => [], :release_obj => [] } # Allows to specify custom typing for virtual attribute types # Besides the built in mapping: # link: :linklist, # reference: :linklist, # referencelist: :linklist, # widgetlist: :linklist, # binary: :linklist, # number: :string, # stringlist: :text # # Following other options are supported: # reference: :string, # referencelist: :text # # Custom mappings can be specified per obj_class: # # custom_attribute_types = { # 'MyPage' => { # child_order: :text # } # } # # or per attribute: # # custom_attribute_types = { # child_order: :text # } # # or using a callable entity like a proc: # # custom_attribute_types = lambda do |obj_class, attribute| # :text if attribute == :child_order # end mattr_accessor :custom_attribute_types self.custom_attribute_types = {} mattr_accessor :search_engine self.search_engine = Fiona7::VeritySearchEngine def self.run_callbacks(callback, *params) (self.callbacks[callback] || []).each do |callback_proc| begin callback_proc.call(*params) rescue => e Rails.logger.error("An error occured when running a callback: #{callback} with #{params.inspect}") Rails.logger.error("#{e.class}: #{e.message}") Rails.logger.error(e.backtrace[0,30].join("\n")) end end end def self.workflows_enabled? true end class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode, :dont_yell_at_me_for_abusing_attributes) end mattr_accessor :config def self.configure(&block) self.config = 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.add_cms_routing_paths", :after => "scrivito.add_cms_routing_paths" do |app| precedence_route = File.expand_path("precedence_routes.rb", paths['config'].to_a.first) app.routes_reloader.paths.unshift(precedence_route) 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 else # This is interessting! We check for an existing rsession # and if we don't find any, we destroy rsession. Why? # Calling rsession.destroy first constructs the session # for the current user (root most likely), which is not # really a thing that we want - being root by default # should only happen in the root mode if !session[:rsession] rsession.destroy end 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 # Installs delayed, low-priority scrivito routes (primarily: permalink route) initializer "fiona7.add_cms_routing_paths", :after => :add_routing_paths do |app| cms_route = File.expand_path("delayed_routes.rb", paths['config'].to_a.first) app.routes_reloader.paths.push(cms_route) 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