infopark_fiona7 0.30.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -0
  3. data/Rakefile +21 -0
  4. data/app/assets/images/fiona7-logo.png +0 -0
  5. data/app/assets/images/fiona7-marker.png +0 -0
  6. data/app/assets/javascripts/fiona7.js +284 -0
  7. data/app/assets/stylesheets/fiona7-login.css.scss +15 -0
  8. data/app/assets/stylesheets/fiona7.css.scss +83 -0
  9. data/app/controllers/fiona7/blobs_controller.rb +35 -0
  10. data/app/controllers/fiona7/default_scrivito_cms_controller.rb +16 -0
  11. data/app/controllers/fiona7/release_controller.rb +24 -0
  12. data/app/controllers/fiona7/sessions_controller.rb +49 -0
  13. data/app/controllers/fiona7_login_page_controller.rb +27 -0
  14. data/app/helpers/fiona7_login_helper.rb +18 -0
  15. data/app/helpers/fiona7_override_helper.rb +47 -0
  16. data/app/models/fiona7/edited_obj.rb +15 -0
  17. data/app/models/fiona7/internal_released_obj.rb +18 -0
  18. data/app/models/fiona7/released_obj.rb +18 -0
  19. data/app/models/fiona7/write_obj.rb +63 -0
  20. data/app/models/fiona7_login_page.rb +5 -0
  21. data/app/models/x_container.rb +5 -0
  22. data/app/models/x_generic.rb +5 -0
  23. data/app/models/x_image.rb +5 -0
  24. data/app/views/fiona7_login_page/index.html.erb +14 -0
  25. data/app/views/layouts/fiona7_login_page_layout.html.erb +23 -0
  26. data/config/locales/login.yml +19 -0
  27. data/config/locales/permissions.yml +7 -0
  28. data/config/routes.rb +9 -0
  29. data/lib/fiona7/assert.rb +17 -0
  30. data/lib/fiona7/builder/batch_widget_writer.rb +107 -0
  31. data/lib/fiona7/builder/obj_builder.rb +297 -0
  32. data/lib/fiona7/builder/obj_class_builder.rb +111 -0
  33. data/lib/fiona7/builder/obj_class_updater.rb +69 -0
  34. data/lib/fiona7/builder/obj_updater.rb +25 -0
  35. data/lib/fiona7/builder/widget_builder.rb +13 -0
  36. data/lib/fiona7/builder/widget_building.rb +35 -0
  37. data/lib/fiona7/builder/widget_updater.rb +13 -0
  38. data/lib/fiona7/controllers/content_service/obj_controller.rb +125 -0
  39. data/lib/fiona7/controllers/content_service/workspace_controller.rb +19 -0
  40. data/lib/fiona7/controllers/rest_api/blob_controller.rb +11 -0
  41. data/lib/fiona7/controllers/rest_api/obj_class_controller.rb +39 -0
  42. data/lib/fiona7/controllers/rest_api/obj_controller.rb +175 -0
  43. data/lib/fiona7/controllers/rest_api/workspace_controller.rb +58 -0
  44. data/lib/fiona7/engine.rb +138 -0
  45. data/lib/fiona7/fiona_connector_patches/basic_obj.rb +9 -0
  46. data/lib/fiona7/initializer.rb +78 -0
  47. data/lib/fiona7/json/obj_class_decorator.rb +45 -0
  48. data/lib/fiona7/json/obj_decorator.rb +153 -0
  49. data/lib/fiona7/json/typeless_obj_decorator.rb +30 -0
  50. data/lib/fiona7/json/widget_decorator.rb +18 -0
  51. data/lib/fiona7/link_converter/fiona_to_scrivito.rb +37 -0
  52. data/lib/fiona7/link_converter/scrivito_to_fiona.rb +42 -0
  53. data/lib/fiona7/mode_switch.rb +7 -0
  54. data/lib/fiona7/mode_switch/abstract_mode_switch.rb +19 -0
  55. data/lib/fiona7/mode_switch/cms_routes.rb +33 -0
  56. data/lib/fiona7/mode_switch/cms_routes/fiona_connector.rb +17 -0
  57. data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk.rb +20 -0
  58. data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk_slave.rb +20 -0
  59. data/lib/fiona7/mode_switch/composite.rb +33 -0
  60. data/lib/fiona7/mode_switch/constants.rb +86 -0
  61. data/lib/fiona7/mode_switch/views.rb +37 -0
  62. data/lib/fiona7/naive_search_engine.rb +111 -0
  63. data/lib/fiona7/recursive_link_resolver.rb +93 -0
  64. data/lib/fiona7/routers/content_service.rb +19 -0
  65. data/lib/fiona7/routers/rest_api.rb +135 -0
  66. data/lib/fiona7/routing_monkey_patch.rb +33 -0
  67. data/lib/fiona7/scrivito_patches/attribute_content.rb +19 -0
  68. data/lib/fiona7/scrivito_patches/basic_obj.rb +92 -0
  69. data/lib/fiona7/scrivito_patches/basic_widget.rb +14 -0
  70. data/lib/fiona7/scrivito_patches/binary.rb +55 -0
  71. data/lib/fiona7/scrivito_patches/client_config.rb +19 -0
  72. data/lib/fiona7/scrivito_patches/cms_dispatch_controller.rb +31 -0
  73. data/lib/fiona7/scrivito_patches/cms_rest_api.rb +11 -0
  74. data/lib/fiona7/scrivito_patches/cms_routing.rb +66 -0
  75. data/lib/fiona7/scrivito_patches/controller_actions.rb +14 -0
  76. data/lib/fiona7/scrivito_patches/link_parser.rb +22 -0
  77. data/lib/fiona7/scrivito_patches/migrator.rb +13 -0
  78. data/lib/fiona7/scrivito_patches/obj_class.rb +16 -0
  79. data/lib/fiona7/scrivito_patches/type_computer.rb +25 -0
  80. data/lib/fiona7/scrivito_patches/workspace.rb +12 -0
  81. data/lib/fiona7/scrivito_user.rb +44 -0
  82. data/lib/fiona7/search_engine.rb +20 -0
  83. data/lib/fiona7/type_register.rb +140 -0
  84. data/lib/fiona7/type_register_mixin.rb +9 -0
  85. data/lib/fiona7/version.rb +3 -0
  86. data/lib/fiona7/version_helper.rb +84 -0
  87. data/lib/fiona7/widget_resolver.rb +37 -0
  88. data/lib/fiona7/workspace.rb +76 -0
  89. data/lib/infopark_fiona7.rb +4 -0
  90. data/lib/tasks/fiona7_tasks.rake +13 -0
  91. metadata +216 -0
@@ -0,0 +1,58 @@
1
+ require 'fiona7/workspace'
2
+ require 'fiona7/assert'
3
+
4
+ module Fiona7
5
+ module Controllers
6
+ module RestAPI
7
+ class WorkspaceController
8
+ def fetch(id)
9
+ id = id.to_sym
10
+ Assert.input(
11
+ id == :published || id == :rtc,
12
+ "Workspace does not exist"
13
+ )
14
+
15
+ w = Workspace.new(id)
16
+ return ::JSON.parse(::ActiveSupport::JSON.encode(w))
17
+ end
18
+
19
+ def publish(id)
20
+ raise "Unexpected workspace_id: #{id}" unless id.to_s == "rtc"
21
+ WriteObj.where(is_edited: 1).each do |obj|
22
+ begin
23
+ obj.release!
24
+ rescue => e
25
+ raise "Release impossible of: #{obj.path} because: #{e.message}"
26
+ end
27
+ end
28
+ {'task' => {'id' => '1', 'status' => 'success', 'result' => '1'}}
29
+ end
30
+
31
+ def delete(id)
32
+ Assert.contraint(false, "Workspaces cannot be deleted")
33
+ end
34
+
35
+ def create(values)
36
+ id = (values[:workspace][:id] || values[:workspace]["id"])
37
+ id = id.to_sym
38
+ Assert.constraint(
39
+ id == :rtc,
40
+ "Only rtc workspace can be created"
41
+ )
42
+ w = Workspace.rtc
43
+ # NOTE: this "creates" a rtc workspace
44
+ # and breaks publish checker spec ...
45
+ #WriteObj.root.take ; WriteObj.root.edit
46
+
47
+ ::JSON.parse(::ActiveSupport::JSON.encode(w))
48
+ end
49
+
50
+ def all
51
+ results = [Workspace.published, Workspace.rtc]
52
+ w = {'results' => results}
53
+ ::JSON.parse(::ActiveSupport::JSON.encode(w))
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,138 @@
1
+ require "fiona7/routing_monkey_patch"
2
+
3
+ #require "active_record/railtie"
4
+
5
+ require "scrivito"
6
+ require "scrivito_sdk"
7
+ require "scrivito_editors"
8
+
9
+ require "scrivito/sdk_engine"
10
+
11
+ require "infopark_fiona_connector"
12
+ #require "rails_connector/engine"
13
+ #require "rails_connector/fiona_engine"
14
+ require "infopark_reactor"
15
+
16
+ require "fiona7/mode_switch"
17
+ require "fiona7/scrivito_patches/attribute_content"
18
+ require "fiona7/scrivito_patches/basic_obj"
19
+ require "fiona7/scrivito_patches/basic_widget"
20
+ require "fiona7/scrivito_patches/binary"
21
+ require "fiona7/scrivito_patches/client_config"
22
+ require "fiona7/scrivito_patches/controller_actions"
23
+ require "fiona7/scrivito_patches/cms_dispatch_controller"
24
+ require "fiona7/scrivito_patches/cms_rest_api"
25
+ require "fiona7/scrivito_patches/cms_routing"
26
+ require "fiona7/scrivito_patches/link_parser"
27
+ require "fiona7/scrivito_patches/obj_class"
28
+ require "fiona7/scrivito_patches/migrator"
29
+ require "fiona7/scrivito_patches/type_computer"
30
+ require "fiona7/scrivito_patches/workspace"
31
+
32
+
33
+ require "fiona7/routers/content_service"
34
+ require "fiona7/routers/rest_api"
35
+
36
+ require 'fiona7/scrivito_user'
37
+
38
+ module Fiona7
39
+ mattr_accessor :mode
40
+ mattr_accessor :login
41
+
42
+ class Config < Struct.new("Config", :mode, :instance, :host, :port, :username, :secret, :root_mode)
43
+ end
44
+
45
+ def self.configure(&block)
46
+ Config.new.tap do |config|
47
+ yield config
48
+
49
+ Reactor::Configuration.xml_access = {
50
+ host: config.host,
51
+ port: config.port,
52
+ id: 'f7',
53
+ username: config.username,
54
+ secret: config.secret
55
+ }
56
+
57
+ Fiona7.mode = config.mode
58
+ if Fiona7.login = !config.root_mode
59
+ Scrivito.configure do |config|
60
+ config.editing_auth do |env|
61
+ request = ActionDispatch::Request.new(env)
62
+ session = request.session
63
+ rsession = session[:rsession]
64
+ if rsession && rsession.user?
65
+ Fiona7::ScrivitoUser.define(rsession.user)
66
+ end
67
+ end
68
+
69
+ config.find_user do |user_id|
70
+ user = Reactor::Cache::User.instance.get(user_id)
71
+
72
+ Fiona7::ScrivitoUser.define(user)
73
+ end
74
+ end
75
+ end
76
+
77
+ if config.mode == :standalone
78
+ RailsConnector::Configuration.mode = :editor
79
+ end
80
+
81
+ RailsConnector::Configuration.instance_name = config.instance
82
+ end
83
+ end
84
+
85
+ class Engine < ::Rails::Engine
86
+
87
+ initializer "fiona7.mode_switch" do |app|
88
+ mode = nil
89
+
90
+ if Fiona7.mode == :standalone
91
+ mode = :standalone
92
+ elsif Fiona7.mode == :legacy
93
+ mode = :legacy
94
+ else
95
+ raise "Invalid mode: #{Fiona7.mode}. Valid modes are :legacy and :standalone. Please refer to the documentation for more information"
96
+ end
97
+
98
+ ModeSwitch::Composite.new(app).public_send(mode)
99
+ end
100
+
101
+ initializer "fiona7.remove_scrivito_deprecations" do |app|
102
+ {
103
+ 'cms_image_tag' => 'scrivito_image_tag',
104
+ 'cms_path' => 'scrivito_path',
105
+ 'cms_tag' => 'scrivito_tag',
106
+ 'cms_tag_list' => 'scrivito_tag_list',
107
+ 'cms_url' => 'scrivito_url',
108
+ 'display_field' => 'scrivito_field',
109
+ 'display_value' => 'scrivito_value',
110
+ 'scrivito_after_content_tags' => 'scrivito_body_tags',
111
+ 'scrivito_header_tags' => 'scrivito_head_tags',
112
+ }.each_pair do |old_method_name, new_method_name|
113
+ ScrivitoHelper.send(:remove_method, old_method_name) if ScrivitoHelper.method_defined?(old_method_name)
114
+ end
115
+ end
116
+
117
+ initializer "fiona7.authorize_reactor" do |app|
118
+ ActionController::Base.__send__(:define_method, :rsession_auth) do
119
+ if !Fiona7.login
120
+ rsession.user_name = 'root' unless rsession.user_name == 'root'
121
+ end
122
+ end
123
+ end
124
+
125
+ initializer "fiona7.patch_assets" do |app|
126
+ app.config.assets.precompile += %w(fiona7.css fiona7.js fiona7-login.css)
127
+ end
128
+
129
+ initializer "fiona7.runtime_patches" do |app|
130
+ # delayed init, patching sooner breaks AR
131
+ require "fiona7/fiona_connector_patches/basic_obj"
132
+ end
133
+
134
+ # This ensures that reactor is loaded in the app
135
+ config.after_initialize { Fiona7::WriteObj }
136
+
137
+ end
138
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_connector/basic_obj'
2
+
3
+ module RailsConnector
4
+ class BasicObj
5
+ def scrivito_obj
6
+ Scrivito::Obj.find(self.id)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,78 @@
1
+ module Fiona7
2
+ class Initializer
3
+ CLASSES_MAP = {
4
+ 'X_Generic' => 'generic',
5
+ 'X_Image' => 'image',
6
+ 'X_Container' => 'publication'
7
+ }
8
+
9
+ ATTRIBUTES_MAP = {
10
+ 'X_widget_pool' => 'linklist'
11
+ }
12
+
13
+ def sanity_check
14
+ any_class_present = false
15
+ classes_present = CLASSES_MAP.all? do |name, type|
16
+ obj_class = RailsConnector::ObjClass.find_by_name(name)
17
+ any_class_present ||= obj_class && obj_class.obj_type == type
18
+ end
19
+
20
+ classes_present && raise("Initialization has already been performed, there is not need to perform it again.")
21
+ any_class_present && raise("Misconfiguration of obj classes detected")
22
+
23
+ any_attribute_present = false
24
+ attributes_present = ATTRIBUTES_MAP.all? do |name, type|
25
+ attribute = RailsConnector::Attribute.find_by_name(name)
26
+ any_attribute_present ||= attribute && attribute.attribute_type == type
27
+ end
28
+
29
+ any_class_present && raise("Misconfiguration of attributes detected")
30
+ end
31
+
32
+ def classes_and_attributes
33
+ CLASSES_MAP.each do |name, type|
34
+ Reactor::Cm::ObjClass.create(name, type)
35
+ end
36
+
37
+ ATTRIBUTES_MAP.each do |name, type|
38
+ Reactor::Cm::Attribute.create(name, type)
39
+ end
40
+ end
41
+
42
+ def set_valid_sub_obj_classes
43
+ RailsConnector::ObjClass.all.each do |obj_class|
44
+ valid_sub_obj_classes = read_valid_sub_obj_classes(obj_class)
45
+
46
+ # empty valid_sub_obj_classes = allow all
47
+ unless valid_sub_obj_classes.empty?
48
+ valid_sub_obj_classes += CLASSES_MAP.keys
49
+ cm_class = Reactor::Cm::ObjClass.get(obj_class.name)
50
+ cm_class.set(:validSubObjClasses, valid_sub_obj_classes)
51
+ cm_class.save!
52
+ end
53
+ end
54
+ end
55
+
56
+ def create_login_page
57
+ Scrivito::Workspace.current = Scrivito::Workspace.find('rtc')
58
+ Scrivito::ObjClass.create(
59
+ name: 'Fiona7LoginPage',
60
+ title: 'Login Page',
61
+ attributes: [
62
+ {name: "title", type: "string"},
63
+ {name: "body", type: "html"}
64
+ ]
65
+ )
66
+ Scrivito::Obj.create(_obj_class: 'Fiona7LoginPage', _path: '/_global/login_page', title: 'Log in')
67
+ Scrivito::ObjClass.find('Fiona7LoginPage').update(is_active: false)
68
+ end
69
+
70
+ protected
71
+ def read_valid_sub_obj_classes(obj_class)
72
+ # TODO: upgrade reactor to get rid of this crap
73
+ obj_class.send(:load_blob_data)
74
+ data = obj_class.instance_variable_get('@blob_data') || {}
75
+ data["validSubObjClasses"] || []
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,45 @@
1
+ require 'fiona7/type_register_mixin'
2
+
3
+ module Fiona7
4
+ module JSON
5
+ class ObjClassDecorator
6
+ include TypeRegisterMixin
7
+
8
+ attr_reader :cms_class
9
+
10
+ def initialize(cms_class)
11
+ @cms_class = cms_class
12
+ end
13
+
14
+ def name
15
+ cms_class.name
16
+ end
17
+
18
+ def as_json(*options)
19
+ result = {
20
+ id: cms_class.name,
21
+ name: cms_class.name,
22
+ title: cms_class.title(:de),
23
+ #type: cms_class.obj_type,
24
+ is_active: cms_class.enabled?,
25
+ attributes: []
26
+ }
27
+ type_register.annotated_attributes(cms_class.name).each do |attribute|
28
+ virtual_name = attribute.virtual_name
29
+ virtual_type = attribute.virtual_type
30
+
31
+ attr_hash = {
32
+ name: virtual_name.to_s,
33
+ type: virtual_type.to_s
34
+ }
35
+
36
+ attr_hash[:values] = attribute.values if attribute.values
37
+
38
+ result[:attributes] << attr_hash
39
+ end
40
+
41
+ result.as_json(*options)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,153 @@
1
+ module Fiona7
2
+ module JSON
3
+ class ObjDecorator
4
+ end
5
+ end
6
+ end
7
+
8
+ require 'fiona7/assert'
9
+ require 'fiona7/type_register_mixin'
10
+ require 'fiona7/link_converter/fiona_to_scrivito'
11
+ require 'fiona7/json/widget_decorator'
12
+ require 'fiona7/widget_resolver'
13
+
14
+ module Fiona7
15
+ module JSON
16
+ class ObjDecorator
17
+ include TypeRegisterMixin
18
+
19
+ def initialize(klass, obj)
20
+ @klass = klass
21
+ @obj = obj
22
+
23
+ @link_converter = LinkConverter::FionaToScrivito.new(obj)
24
+ end
25
+
26
+ def as_json(*args)
27
+ attrs = standard_attrs
28
+ add_custom_attributes(attrs, *args)
29
+ replace_widget_pool(attrs, *args)
30
+
31
+ attrs
32
+ end
33
+
34
+ protected
35
+ def standard_attrs
36
+ attrs = {
37
+ _id: [@obj.id],
38
+ _path: [@obj.path],
39
+ _obj_class: [@obj.obj_class],
40
+ _last_changed: [@obj.last_changed.try(:to_iso)],
41
+ _widget_pool: [{}]
42
+ }
43
+ attrs[:_permalink] = [@obj.permalink] if @obj.permalink.present?
44
+ attrs
45
+ end
46
+
47
+ def add_custom_attributes(attrs, *args)
48
+ type_register.annotated_attributes(@obj.obj_class).each do |attribute|
49
+ virtual_attribute_name = attribute.virtual_name
50
+ real_attribute_name = attribute.real_name
51
+ virtual_attribute_type = attribute.virtual_type
52
+
53
+ val = case virtual_attribute_type
54
+ when :link
55
+ deserialize_link(@obj[real_attribute_name].try(:first))
56
+ when :linklist
57
+ (@obj[real_attribute_name] || []).map {|link| deserialize_link(link) }
58
+ when :multienum
59
+ @obj[real_attribute_name] || []
60
+ when :reference
61
+ deserialize_reference(@obj[real_attribute_name].try(:first))
62
+ when :referencelist
63
+ (@obj[real_attribute_name] || []).map {|link| deserialize_reference(link) }.compact
64
+ when :date
65
+ @obj[real_attribute_name].try(:to_iso)
66
+ when :widget
67
+ deserialize_widget_field(@obj[real_attribute_name] || [])
68
+ when :html
69
+ deserialize_html(@obj[real_attribute_name])
70
+ when :binary
71
+ deserialize_binary(@obj[real_attribute_name].try(:first))
72
+ when :enum, :multienum, :text, :string
73
+ @obj[real_attribute_name]
74
+ else
75
+ Assert.success(
76
+ false,
77
+ "Unknown attribute type #{virtual_attribute_type} for attribute: #{virtual_attribute_name}"
78
+ )
79
+ end
80
+
81
+ attrs[virtual_attribute_name] = [val, virtual_attribute_type]
82
+ end
83
+ end
84
+
85
+ def deserialize_link(link)
86
+ if link
87
+ {
88
+ # remove possible external prefix for protcol-less urls
89
+ url: link.url.try(:gsub, /\Aexternal:/, ''),
90
+ title: link.title,
91
+ target: link.target,
92
+ # content service uses destination
93
+ destination: link.destination_object_id,
94
+ # rest api uses obj_id
95
+ obj_id: link.destination_object_id,
96
+ query: link.query,
97
+ fragment: link.fragment
98
+ }
99
+ end
100
+ end
101
+
102
+ def deserialize_reference(link)
103
+ if link && link.internal?
104
+ link.destination_object_id
105
+ end
106
+ end
107
+
108
+ def deserialize_widget_field(linklist)
109
+ if !linklist.empty?
110
+ widgets = linklist.map do |link|
111
+ widget_id = link.title
112
+ {widget: widget_id}
113
+ end
114
+
115
+ {list: widgets}
116
+ end
117
+ end
118
+
119
+ def deserialize_html(html)
120
+ @link_converter.convert(html)
121
+ end
122
+
123
+ def deserialize_binary(link)
124
+ if link
125
+ binary_id = link.title
126
+ if binary_id.length == 32 && binary_id =~ /0{16,}0*[0-9]+/
127
+ {id: binary_id}
128
+ end
129
+ end
130
+ end
131
+
132
+ def replace_widget_pool(attrs, *args)
133
+ if (widget_links = @obj[:X_widget_pool])
134
+
135
+ resolver = WidgetResolver.new(widget_links, @klass)
136
+
137
+ Assert.success(
138
+ resolver.instance_map.all? {|_, instance| !instance.nil?},
139
+ "Widget structure in object #{@obj.id} is broken, a widget could not be found"
140
+ )
141
+
142
+ result = Hash[
143
+ resolver.instance_map.map {|widget_id, widget|
144
+ [widget_id, WidgetDecorator.new(@klass, widget).as_json(*args)]
145
+ }
146
+ ]
147
+
148
+ attrs[:_widget_pool] = [result]
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end