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,30 @@
1
+ require 'fiona7/json/obj_decorator'
2
+
3
+ module Fiona7
4
+ module JSON
5
+ class TypelessObjDecorator < ObjDecorator
6
+ def as_json(*args)
7
+ with_types = super()
8
+ without_types = {}
9
+
10
+ with_types.each do |attr, (value, type)|
11
+ without_types[attr] = value
12
+ end
13
+
14
+ if without_types[:_widget_pool] && !without_types[:_widget_pool].empty?
15
+ widgets_without_types = without_types[:_widget_pool].map do |id, values|
16
+ values_without_types = {}
17
+ values.each do |attr, (value, type)|
18
+ values_without_types[attr] = value
19
+ end
20
+ [id, values_without_types]
21
+ end
22
+
23
+ without_types[:_widget_pool] = Hash[widgets_without_types]
24
+ end
25
+
26
+ without_types.as_json(*args)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require 'fiona7/json/obj_decorator'
2
+
3
+ module Fiona7
4
+ module JSON
5
+ class WidgetDecorator < ObjDecorator
6
+ protected
7
+ def standard_attrs
8
+ attrs = {
9
+ _obj_class: [@obj.obj_class]
10
+ }
11
+ end
12
+
13
+ def replace_widget_pool(attrs, *args)
14
+ # NOP
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ module Fiona7
2
+ module LinkConverter
3
+ class FionaToScrivito
4
+ include ERB::Util
5
+
6
+ def initialize(obj)
7
+ @obj = obj
8
+ end
9
+
10
+ def convert(content)
11
+ return content unless content.present?
12
+ extend RailsConnector::DefaultCmsRoutingHelper unless kind_of?(RailsConnector::DefaultCmsRoutingHelper)
13
+ extend RailsConnector::DisplayHelper unless kind_of?(RailsConnector::DisplayHelper)
14
+
15
+ RailsConnector::StringTagging.tag_as_html(content, @obj.send(:attr_dict))
16
+ display_value(content)
17
+ end
18
+
19
+ def cms_id_path(options)
20
+ "objid:#{options[:id]}"
21
+ end
22
+
23
+ def root_path(*args)
24
+ "objid:2001"
25
+ end
26
+
27
+ def cms_permalink_path(options={})
28
+ obj = WriteObj.find_by_permalink(options[:permalink])
29
+ if obj
30
+ "objid:#{obj.id}"
31
+ else
32
+ ''
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ module Fiona7
2
+ module LinkConverter
3
+ class ScrivitoToFiona
4
+ def initialize(klass, value)
5
+ @klass, @value = klass, value.to_str
6
+ end
7
+
8
+ def convert
9
+ serialize_html
10
+ end
11
+
12
+ private
13
+ def serialize_html
14
+ # TODO: this an incomplete list of possible tags
15
+ link_expressions = [/(href|src)\s*=\s*"([^"]*)"/, /(href|src)\s*=\s*'([^']*)'/]
16
+ link_expressions.each do |expr|
17
+ @value.gsub!(expr) do |string|
18
+ target = $2
19
+ objid = objid_from_target(target)
20
+ if objid
21
+ "#{$1}=\"#{obj_path(objid)}\""
22
+ else
23
+ string
24
+ end
25
+ end
26
+ end
27
+ @value
28
+ end
29
+
30
+ def objid_from_target(target)
31
+ if (match = target.match(/\Aobjid:([0-9a-f]+)\Z/))
32
+ match[1]
33
+ end
34
+ end
35
+
36
+ def obj_path(id)
37
+ @klass.find(id).try(:path)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,7 @@
1
+ require 'fiona7/mode_switch/composite'
2
+
3
+ module Fiona7
4
+ module ModeSwitch
5
+
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Fiona7
2
+ module ModeSwitch
3
+ class AbstractModeSwitch
4
+ attr_reader :app
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def standalone
11
+ raise "Not implemented"
12
+ end
13
+
14
+ def legacy
15
+ raise "Not implemented"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'fiona7/mode_switch/abstract_mode_switch'
2
+
3
+ module Fiona7
4
+ module ModeSwitch
5
+ class CmsRoutes < AbstractModeSwitch
6
+ def standalone
7
+ self.load_cms_routes(self.scrivito_sdk_routes)
8
+ end
9
+
10
+ def legacy
11
+ self.load_cms_routes(self.scrivito_sdk_slave_routes)
12
+ self.load_cms_routes(self.fiona_connector_routes)
13
+ end
14
+
15
+ protected
16
+ def load_cms_routes(path)
17
+ self.app.routes_reloader.paths.push(path)
18
+ end
19
+
20
+ def scrivito_sdk_routes
21
+ File.expand_path("../cms_routes/scrivito_sdk.rb", __FILE__)
22
+ end
23
+
24
+ def scrivito_sdk_slave_routes
25
+ File.expand_path("../cms_routes/scrivito_sdk_slave.rb", __FILE__)
26
+ end
27
+
28
+ def fiona_connector_routes
29
+ File.expand_path("../cms_routes/fiona_connector.rb", __FILE__)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ Rails.application.routes.draw do
2
+ root to: 'rails_connector/cms_dispatch#index'
3
+ match ':id(/*slug)',
4
+ to: 'rails_connector/cms_dispatch#index',
5
+ constraints: { id: /\d+|[0-9a-f]{16}/ },
6
+ as: "cms_id",
7
+ via: :all
8
+ match 'toggle_markers/:id',
9
+ to: 'rails_connector/cms_dispatch#toggle_editmarkers',
10
+ as: "toggle_markers",
11
+ via: :all
12
+ match '/*permalink',
13
+ to: 'rails_connector/cms_dispatch#index',
14
+ as: 'cms_permalink',
15
+ format: false,
16
+ via: :all
17
+ end
@@ -0,0 +1,20 @@
1
+ Rails.application.routes.draw do
2
+ get '/' => 'scrivito/cms_dispatch#index', as: :scrivito_root
3
+
4
+ get '__scrivito/render_widget/:id/show_widget/:widget_id' => 'scrivito/cms_dispatch#show_widget'
5
+ get '__scrivito/render_widget/:id/widget_details/:widget_id' => 'scrivito/cms_dispatch#widget_details'
6
+
7
+ get '/__scrivito/details_page/:resource_id' => 'scrivito/cms_dispatch#details_page'
8
+
9
+ match ':id(/*slug)',
10
+ to: 'scrivito/cms_dispatch#index',
11
+ constraints: { id: /\d+|[0-9a-f]{16}/ },
12
+ as: 'scrivito_id',
13
+ via: :all
14
+
15
+ match '/*permalink',
16
+ to: 'scrivito/cms_dispatch#index',
17
+ as: :scrivito_permalink,
18
+ format: false,
19
+ via: :all
20
+ end
@@ -0,0 +1,20 @@
1
+ Rails.application.routes.draw do
2
+ get '/f7(/)' => 'scrivito/cms_dispatch#index', as: :scrivito_root
3
+
4
+ get '__scrivito/render_widget/:id/show_widget/:widget_id' => 'scrivito/cms_dispatch#show_widget'
5
+ get '__scrivito/render_widget/:id/widget_details/:widget_id' => 'scrivito/cms_dispatch#widget_details'
6
+
7
+ get '/__scrivito/details_page/:resource_id' => 'scrivito/cms_dispatch#details_page'
8
+
9
+ match '/f7/:id(/*slug)',
10
+ to: 'scrivito/cms_dispatch#index',
11
+ constraints: { id: /\d+|[0-9a-f]{16}/ },
12
+ as: 'scrivito_id',
13
+ via: :all
14
+
15
+ match '/f7/*permalink',
16
+ to: 'scrivito/cms_dispatch#index',
17
+ as: :scrivito_permalink,
18
+ format: false,
19
+ via: :all
20
+ end
@@ -0,0 +1,33 @@
1
+ require 'fiona7/mode_switch/abstract_mode_switch'
2
+ require 'fiona7/mode_switch/views'
3
+ require 'fiona7/mode_switch/cms_routes'
4
+ require 'fiona7/mode_switch/constants'
5
+
6
+ module Fiona7
7
+ module ModeSwitch
8
+ class Composite < AbstractModeSwitch
9
+ def initialize(app)
10
+ super
11
+
12
+ @views = Views.new(self.app)
13
+ @cms_routes = CmsRoutes.new(self.app)
14
+ @constants = Constants.new(self.app)
15
+ end
16
+
17
+ def standalone
18
+ self.switches.each(&:standalone)
19
+ end
20
+
21
+ def legacy
22
+ self.switches.each(&:legacy)
23
+ end
24
+
25
+ protected
26
+ attr_reader :views, :cms_routes, :constants
27
+
28
+ def switches
29
+ [self.views, self.cms_routes, self.constants]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,86 @@
1
+ require 'fiona7/mode_switch/abstract_mode_switch'
2
+
3
+ module Fiona7
4
+ module ModeSwitch
5
+ class Constants < AbstractModeSwitch
6
+ def standalone
7
+ self.common_const_manipulation
8
+ self.set_root_obj_to(::Scrivito::Obj)
9
+ end
10
+
11
+ def legacy
12
+ self.common_const_manipulation
13
+ self.set_root_obj_to(::RailsConnector::Obj)
14
+ end
15
+
16
+ protected
17
+ def set_rails_connector_obj
18
+ if self.obj_defined_in_app?
19
+ if self.rails_connector_app_obj?
20
+ ::RailsConnector.const_set('Obj', ::Object.const_get('Obj'))
21
+ else
22
+ ::RailsConnector.const_set('Obj', ::RailsConnector::AbstractObj)
23
+ end
24
+ else
25
+ ::RailsConnector.const_set('Obj', ::RailsConnector::AbstractObj)
26
+ end
27
+ end
28
+
29
+ def set_scrivito_obj
30
+ if self.obj_defined_in_app?
31
+ if self.scrivito_app_obj?
32
+ ::Scrivito.const_set('Obj', ::Object.const_get('Obj'))
33
+ elsif Fiona7.mode == :legacy && self.scrivito_legacy_app_obj?
34
+ # nop
35
+ else
36
+ ::Scrivito.const_set('Obj', Class.new(::Scrivito::BasicObj))
37
+ end
38
+ else
39
+ ::Scrivito.const_set('Obj', Class.new(::Scrivito::BasicObj))
40
+ end
41
+ end
42
+
43
+ def common_const_manipulation
44
+ self.reset_global_obj
45
+
46
+ self.set_rails_connector_obj
47
+ self.set_scrivito_obj
48
+ end
49
+
50
+ def reset_global_obj
51
+ return if self.obj_defined_in_app?
52
+
53
+ # load global obj
54
+ ::Object.const_get('Obj')
55
+ # since both want it, nobody gets it. (at first)
56
+ ::Object.send(:remove_const, 'Obj')
57
+ end
58
+
59
+ def set_root_obj_to(klass)
60
+ return if self.obj_defined_in_app?
61
+
62
+ ::Object.const_set('Obj', klass)
63
+ end
64
+
65
+ def obj_defined_in_app?
66
+ # NOTE: this is not bullet-proof but a good-enough heuristic
67
+ @obj_defined_in_app ||= ::File.exists?(self.app.paths["app/models"].first + "/obj.rb")
68
+ end
69
+
70
+ def rails_connector_app_obj?
71
+ obj_klass = ::Object.const_get('Obj')
72
+ obj_klass == ::RailsConnector::BasicObj || obj_klass < ::RailsConnector::BasicObj
73
+ end
74
+
75
+ def scrivito_app_obj?
76
+ obj_klass = ::Object.const_get('Obj')
77
+ obj_klass == ::Scrivito::BasicObj || obj_klass < ::Scrivito::BasicObj
78
+ end
79
+
80
+ def scrivito_legacy_app_obj?
81
+ obj_klass = ::Scrivito::Obj rescue Object
82
+ obj_klass == ::Scrivito::BasicObj || obj_klass < ::Scrivito::BasicObj
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,37 @@
1
+ require 'fiona7/mode_switch/abstract_mode_switch'
2
+
3
+ module Fiona7
4
+ module ModeSwitch
5
+ class Views < AbstractModeSwitch
6
+ def standalone
7
+ self.reorder_view_paths(self.scrivito_sdk_path, self.fiona_connector_path)
8
+ end
9
+
10
+ def legacy
11
+ self.reorder_view_paths(self.fiona_connector_path, self.scrivito_sdk_path)
12
+ end
13
+
14
+ protected
15
+ def scrivito_sdk_path
16
+ Gem.loaded_specs['scrivito_sdk'].full_gem_path
17
+ end
18
+
19
+ def fiona_connector_path
20
+ Gem.loaded_specs['infopark_fiona_connector'].full_gem_path
21
+ end
22
+
23
+ def reorder_view_paths(first, second)
24
+ view_paths = ActionController::Base.view_paths
25
+ paths = view_paths.map(&:to_s)
26
+ internal_paths = view_paths.send(:paths)
27
+
28
+ first_index = paths.index {|path| path =~ /#{Regexp.escape first}\/app\/views/ }
29
+ second_index = paths.index {|path| path =~ /#{Regexp.escape second}\/app\/views/ }
30
+
31
+ if first_index > second_index
32
+ internal_paths[first_index], internal_paths[second_index] = internal_paths[second_index], internal_paths[first_index]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,111 @@
1
+ require "fiona7/search_engine"
2
+
3
+ module Fiona7
4
+ class NaiveSearchEngine < SearchEngine
5
+ def results
6
+ fetch_all
7
+ apply_filters
8
+ exclude_widgets
9
+ order_results
10
+ limit_size
11
+ end
12
+
13
+ protected
14
+ def fetch_all
15
+ obj_class_filter = @query.find {|q| q[:field] == :_obj_class && q[:operator] == :equal }
16
+ if obj_class_filter
17
+ @all = @klass.where(obj_class: obj_class_filter[:value])
18
+ @query.delete(obj_class_filter)
19
+ else
20
+ # FIXME: this is deprecated
21
+ @all = @klass.all
22
+ end
23
+ end
24
+
25
+ def apply_filters
26
+ @query.each do |filter|
27
+ apply_filter(filter)
28
+ end
29
+ end
30
+
31
+ def exclude_widgets
32
+ widget_regexp = /\/_widgets\/([0-9]+\/){0,1}[^\/]+\Z/
33
+ @all.to_a.delete_if {|o| o.path =~ widget_regexp }
34
+ end
35
+
36
+ def order_results
37
+ sort_field = resolve_field_name(@sort)
38
+ @all = @all.to_a
39
+ @all.sort_by! {|o| o.send(:[], sort_field) }
40
+ @all.reverse! if @order == :desc
41
+ end
42
+
43
+ def limit_size
44
+ @count = @all.length
45
+ @all[@offset, @limit] || []
46
+ end
47
+
48
+ protected
49
+ def apply_filter(filter)
50
+ field = resolve_field_name(filter[:field])
51
+ operator = filter[:operator].to_sym
52
+ value = filter[:value]
53
+
54
+ case filter[:operator]
55
+ when :equal
56
+ if field == :modification
57
+ if value != ["new", "edited", "deleted"]
58
+ raise "Unsupported modification values: #{value.inspect}. Only #{["new", "edited", "deleted"].inspect} are supported"
59
+ else
60
+ # TODO: this can be solved with AR, faster
61
+ @all = @all.to_a.select {|o| o.edited? }
62
+ end
63
+ else
64
+ if value.is_a?(Array)
65
+ @all = @all.to_a.select do |o|
66
+ field_value = o.send(:[], field)
67
+ # FIXME: linklist, referencelist unsupported
68
+ if field_value.is_a?(Array)
69
+ !(value & field_value).empty?
70
+ else
71
+ value.include?(o.send(:[], field))
72
+ end
73
+ end
74
+ else
75
+ @all = @all.to_a.select {|o| o.send(:[], field) == value }
76
+ end
77
+ end
78
+ when :prefix
79
+ @all = @all.to_a.select {|o| o.send(:[], field).to_s.start_with?(value) }
80
+ when :greater_than
81
+ @all = @all.to_a.select {|o| o.send(:[], field).to_s > (value) }
82
+ when :less_than
83
+ @all = @all.to_a.select {|o| o.send(:[], field).to_s < (value) }
84
+ else
85
+ raise "Operator: #{filter[:operator]} not supported"
86
+ end
87
+ end
88
+
89
+ def resolve_field_name(field)
90
+ field = field.to_sym
91
+ case field
92
+ when :_obj_class
93
+ :obj_class
94
+ when :_path
95
+ :path
96
+ when :_modification
97
+ :modification
98
+ when :id
99
+ :obj_id
100
+ when :_permalink
101
+ :permalink
102
+ when :_last_changed
103
+ :last_changed
104
+ when :_name
105
+ :name
106
+ else
107
+ field
108
+ end
109
+ end
110
+ end
111
+ end