infopark_fiona7 0.71.1.12 → 1.1.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/fiona7_ui.js +67 -0
  3. data/app/assets/stylesheets/fiona7_ui.css.scss +29 -0
  4. data/app/controllers/fiona7/release_controller.rb +37 -75
  5. data/app/controllers/scrivito/cms_dispatch_controller.rb +2 -12
  6. data/app/controllers/scrivito/objs_controller.rb +41 -13
  7. data/app/controllers/scrivito/webservice_controller.rb +4 -3
  8. data/app/views/fiona7/release/preview.html.erb +73 -0
  9. data/config/routes.rb +3 -1
  10. data/infopark_fiona7.gemspec +1 -1
  11. data/lib/fiona7/assert.rb +4 -0
  12. data/lib/fiona7/attribute_name_mangler.rb +19 -0
  13. data/lib/fiona7/attribute_names_from_cms.rb +17 -0
  14. data/lib/fiona7/attribute_names_from_queries.rb +17 -0
  15. data/lib/fiona7/builder/obj_builder.rb +3 -2
  16. data/lib/fiona7/builder/obj_updater.rb +2 -2
  17. data/lib/fiona7/builder/widget_builder.rb +1 -1
  18. data/lib/fiona7/builder/widget_updater.rb +2 -2
  19. data/lib/fiona7/complex_object.rb +24 -0
  20. data/lib/fiona7/controllers/rest_api/obj_controller.rb +96 -24
  21. data/lib/fiona7/controllers/rest_api/workspace_controller.rb +23 -2
  22. data/lib/fiona7/engine.rb +11 -23
  23. data/lib/fiona7/facet_builder.rb +136 -0
  24. data/lib/fiona7/json/reverse_obj_decorator.rb +2 -0
  25. data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk.rb +68 -10
  26. data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk_slave.rb +66 -14
  27. data/lib/fiona7/mode_switch/views.rb +2 -2
  28. data/lib/fiona7/naive_search_engine.rb +40 -5
  29. data/lib/fiona7/obj_class_name_demangler.rb +11 -0
  30. data/lib/fiona7/obj_class_name_mangler.rb +11 -0
  31. data/lib/fiona7/obj_classes_from_cms.rb +14 -0
  32. data/lib/fiona7/obj_classes_from_queries.rb +11 -0
  33. data/lib/fiona7/recursive_object_finder.rb +149 -0
  34. data/lib/fiona7/routers/rest_api.rb +14 -1
  35. data/lib/fiona7/routing_monkey_patch.rb +5 -2
  36. data/lib/fiona7/scrivito_patches/attribute_serializer.rb +1 -1
  37. data/lib/fiona7/scrivito_patches/basic_obj.rb +4 -9
  38. data/lib/fiona7/scrivito_patches/basic_widget.rb +0 -9
  39. data/lib/fiona7/scrivito_patches/cms_backend.rb +11 -16
  40. data/lib/fiona7/scrivito_patches/cms_rest_api.rb +1 -1
  41. data/lib/fiona7/scrivito_patches/cms_routing.rb +50 -33
  42. data/lib/fiona7/scrivito_patches/link_parser.rb +6 -13
  43. data/lib/fiona7/scrivito_patches/log_subscriber.rb +18 -0
  44. data/lib/fiona7/scrivito_patches/preset_routes.rb +47 -0
  45. data/lib/fiona7/scrivito_patches/routing_extensions.rb +48 -0
  46. data/lib/fiona7/search_engine.rb +4 -0
  47. data/lib/fiona7/type_loader.rb +5 -4
  48. data/lib/fiona7/type_register.rb +13 -27
  49. data/lib/fiona7/type_synchronizer.rb +8 -6
  50. data/lib/fiona7/verity_search_engine.rb +77 -30
  51. data/lib/fiona7/version.rb +1 -1
  52. metadata +18 -13
  53. data/app/models/rails_connector/abstract_obj.rb +0 -24
  54. data/lib/fiona7/controllers/content_service/obj_controller.rb +0 -121
  55. data/lib/fiona7/controllers/content_service/workspace_controller.rb +0 -19
  56. data/lib/fiona7/recursive_link_resolver.rb +0 -93
  57. data/lib/fiona7/routers/content_service.rb +0 -19
  58. data/lib/fiona7/scrivito_patches/client_config.rb +0 -0
  59. data/lib/fiona7/scrivito_patches/controller_actions.rb +0 -6
  60. data/lib/fiona7/scrivito_patches/obj_class.rb +0 -16
  61. data/lib/fiona7/scrivito_patches/obj_data_from_rest.rb +0 -30
@@ -0,0 +1,11 @@
1
+ module Fiona7
2
+ class ObjClassesFromQueries
3
+ def initialize(queries)
4
+ @queries = queries
5
+ end
6
+
7
+ def obj_classes
8
+ @queries.map {|q| q[:value] if q[:operator] == :equal && q[:field] == :_obj_class }.flatten.compact.uniq.presence if @queries
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,149 @@
1
+ require 'set'
2
+
3
+ module Fiona7
4
+ class RecursiveObjectFinder
5
+ attr_reader :starting_obj, :widgets, :images, :downloads, :referenced, :linked
6
+
7
+ def initialize(starting_obj, max_levels=3)
8
+ @starting_obj = starting_obj
9
+ @max_levels = max_levels
10
+
11
+ @widgets = []
12
+ @images = []
13
+ @downloads = []
14
+ @referenced = []
15
+ @linked = []
16
+
17
+ recursive_compute(@starting_obj, Set[@starting_obj], @max_levels)
18
+ end
19
+
20
+ protected
21
+ def recursive_compute(obj, already_encountered, levels)
22
+ return if levels <= 0
23
+
24
+ new_widgets = find_widgets(obj) - already_encountered
25
+ already_encountered.merge(new_widgets)
26
+
27
+ new_images = find_images(obj) - already_encountered
28
+ already_encountered.merge(new_images)
29
+
30
+ new_downloads = find_downloads(obj) - already_encountered
31
+ already_encountered.merge(new_downloads)
32
+
33
+ new_referenced = find_referenced(obj) - already_encountered
34
+ already_encountered.merge(new_referenced)
35
+
36
+ new_linked = find_linked(obj) - already_encountered
37
+ already_encountered.merge(new_linked)
38
+
39
+
40
+ new_widgets.each do |new_obj|
41
+ @widgets << new_obj
42
+ end
43
+
44
+ new_images.each do |new_obj|
45
+ @images << new_obj
46
+ end
47
+
48
+ new_downloads.each do |new_obj|
49
+ @downloads << new_obj
50
+ end
51
+
52
+ new_referenced.each do |new_obj|
53
+ @referenced << new_obj
54
+ end
55
+
56
+ new_linked.each do |new_obj|
57
+ @linked << new_obj
58
+ end
59
+
60
+
61
+ new_objs = new_widgets
62
+ new_widgets.each do |new_obj|
63
+ recursive_compute(new_obj, already_encountered, levels-1)
64
+ end
65
+
66
+ end
67
+
68
+ def find_widgets(obj)
69
+ # TODO: optimize this through attr_values
70
+ links = obj[:X_widget_pool] || []
71
+ WriteObj.where(obj_id: links.map {|l| l.destination_object_id }).to_a.to_set
72
+ end
73
+
74
+ def find_images(obj)
75
+ find_selected(obj) do |link, attribute|
76
+ if link.internal?
77
+ destination_object = link.destination_object
78
+ if destination_object && destination_object.image?
79
+ true
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def find_downloads(obj)
86
+ find_selected(obj) do |link, attribute|
87
+ if link.internal?
88
+ destination_object = link.destination_object
89
+ if destination_object && destination_object.generic?
90
+ true
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ def find_referenced(obj)
97
+ find_selected(obj) do |link, attribute|
98
+ if link.internal? && attribute && (attribute.type == :reference || attribute.type == :referencelist)
99
+ destination_object = link.destination_object
100
+ if destination_object && !(destination_object.image? || destination_object.generic?)
101
+ true
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def find_linked(obj)
108
+ find_selected(obj) do |link, attribute|
109
+ if link.internal? && (!attribute || (attribute.type == :link || attribute.type == :linklist))
110
+ destination_object = link.destination_object
111
+ if destination_object && !(destination_object.image? || destination_object.generic?)
112
+ true
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ def find_selected(obj)
119
+ referenced = Set.new
120
+
121
+ # TODO: optimize this through attr_values
122
+ type_definition = Fiona7::TypeRegister.instance.read_mangled(obj.obj_class)
123
+ type_definition.attrs.each do |attribute|
124
+ if attribute.type == :reference || attribute.type == :referencelist && attribute.name != "child_order"
125
+ (obj[attribute.real_name] || []).each do |link|
126
+ if yield(link, attribute)
127
+ referenced << link.destination_object
128
+ end
129
+ end
130
+ elsif attribute.type == :link || attribute.type == :linklist
131
+ (obj[attribute.real_name] || []).each do |link|
132
+ if yield(link, attribute)
133
+ referenced << link.destination_object
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ obj.text_links.each do |link|
140
+ if yield(link, nil)
141
+ referenced << link.destination_object
142
+ end
143
+ end
144
+
145
+ referenced
146
+ end
147
+
148
+ end
149
+ end
@@ -29,8 +29,12 @@ class Scrivito::CmsRestApi
29
29
  resource_path = '/' + resource_path
30
30
  end
31
31
 
32
- #$stdout.puts "DEBUG GET: #{resource_path}"
32
+ $stdout.puts "DEBUG GET: #{resource_path}"
33
+ pp payload
33
34
  case resource_path
35
+ when /\A\/?revisions\/[a-zA-Z0-9_-]+\/objs\/mget\Z/
36
+ _, _, revision_id, _, _ = *resource_path.split("/")
37
+ Fiona7::Controllers::RestAPI::ObjController.new.fetch_multiple(revision_id, payload)
34
38
  when /\A\/?revisions\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/
35
39
  _, _, revision_id, _, obj_id = *resource_path.split("/")
36
40
  Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id_from_revision(revision_id, obj_id)
@@ -46,12 +50,18 @@ class Scrivito::CmsRestApi
46
50
  when /\A\/?workspaces\/[a-zA-Z0-9_-]+\Z/
47
51
  _, _, workspace_id = *resource_path.split("/")
48
52
  Fiona7::Controllers::RestAPI::WorkspaceController.new.fetch(workspace_id)
53
+ when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/changes\Z/
54
+ _, _, workspace_id,_ = *resource_path.split("/")
55
+ Fiona7::Controllers::RestAPI::WorkspaceController.new.changes(workspace_id)
49
56
  when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/
50
57
  _, _, workspace_id, _, obj_id = *resource_path.split("/")
51
58
  Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id(workspace_id, obj_id)
52
59
  when /\A\/?blobs\/[a-zA-Z0-9_-]+\Z/
53
60
  _, _, blob_id = *resource_path.split("/")
54
61
  Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id)
62
+ when /\A\/?blobs\/[a-zA-Z0-9_-]+\/no_cache\Z/
63
+ _, _, blob_id = *resource_path.split("/")
64
+ Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id)
55
65
  when /\A\/?blobs\/[a-zA-Z0-9_-]+\/transform\Z/
56
66
  _, _, blob_id = *resource_path.split("/")
57
67
  Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id, payload[:transformation])
@@ -131,6 +141,9 @@ class Scrivito::CmsRestApi
131
141
  raise Scrivito::ScrivitoError, 'Rebase operation unsupported for workspaces'
132
142
  _, _, workspace_id = *resource_path.split("/")
133
143
  Fiona7::Controllers::RestAPI::WorkspaceController.new.publish(workspace_id)
144
+ when /\A\/?workspaces\/[a-zA-Z0-9]+/
145
+ _, _, workspace_id = *resource_path.split("/")
146
+ Fiona7::Controllers::RestAPI::WorkspaceController.new.update(workspace_id)
134
147
  else
135
148
  #$stdout.puts "PUT: #{resource_path}"
136
149
  original_put(resource_path, payload, options||{})
@@ -4,8 +4,11 @@ module ActionDispatch
4
4
  def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
5
5
  raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
6
6
 
7
- forbidden_paths = [::File.join(Gem.loaded_specs['scrivito_sdk'].full_name, "config/routes.rb"),
8
- ::File.join(Gem.loaded_specs['infopark_fiona_connector'].full_name, "config/cms_routes.rb")]
7
+ forbidden_paths = [
8
+ ::File.join(Gem.loaded_specs['scrivito_sdk'].full_gem_path, "config/routes.rb"),
9
+ ::File.join(Gem.loaded_specs['scrivito_sdk'].full_gem_path, "config/precedence_routes.rb"),
10
+ ::File.join(Gem.loaded_specs['infopark_fiona_connector'].full_gem_path, "config/cms_routes.rb")
11
+ ]
9
12
 
10
13
  if caller.any? {|path| forbidden_paths.any? {|fp| path.include?(fp) } }
11
14
  return # bad dog scrivito/fiona_connector, bad dog! no cms_routes for you
@@ -5,7 +5,7 @@ module Scrivito
5
5
  def serialize_binary_value(attribute_value, attribute_definition)
6
6
  case attribute_value
7
7
  when File then attribute_value
8
- when FutureBinary then attribute_value.file_to_be_uploaded
8
+ when FutureBinary then attribute_value.file_to_upload
9
9
  when UploadedBinary then attribute_value.params
10
10
  else
11
11
  raise_validation_error(attribute_definition.name,
@@ -9,11 +9,6 @@ module Scrivito
9
9
  @_type_computer ||= TypeComputer.new(Scrivito::BasicObj, Obj)
10
10
  end
11
11
 
12
- # to_param should only return strings and our ids are numbers
13
- def to_param
14
- id.to_s
15
- end
16
-
17
12
  # optimized away
18
13
  def outdated?
19
14
  false
@@ -68,10 +63,10 @@ module Scrivito
68
63
  # and does not support shadow classes
69
64
  def self.where(field, operator, value, boost = nil)
70
65
  assert_not_basic_obj('.where')
71
- if self == Obj || self == ::Obj
66
+ if self == ::Obj || self == Obj
72
67
  Workspace.current.objs.where(field, operator, value, boost)
73
68
  else
74
- Workspace.current.objs.where(:_obj_class, :equals, to_s)
69
+ Workspace.current.objs.where(:_obj_class, :equals, name)
75
70
  .and(field, operator, value, boost)
76
71
  end
77
72
  end
@@ -80,10 +75,10 @@ module Scrivito
80
75
  # and does not support shadow classes
81
76
  def self.all
82
77
  assert_not_basic_obj('.all')
83
- if self == Obj || self == ::Obj
78
+ if self == ::Obj || self == Obj
84
79
  Workspace.current.objs.all
85
80
  else
86
- find_all_by_obj_class(to_s)
81
+ find_all_by_obj_class(name)
87
82
  end
88
83
  end
89
84
 
@@ -2,15 +2,6 @@ require 'scrivito/basic_widget'
2
2
 
3
3
  module Scrivito
4
4
  class BasicWidget
5
- # patch hash to handle numeric ids
6
- def hash
7
- if @obj && @id
8
- (id.to_s + obj.id.to_s).hash
9
- else
10
- super
11
- end
12
- end
13
-
14
5
  def self.widget_class
15
6
  self
16
7
  end
@@ -2,11 +2,6 @@ require 'scrivito/cms_backend'
2
2
 
3
3
  module Scrivito
4
4
  class CmsBackend
5
- def die_content_service
6
- # TODO: remove this
7
- false
8
- end
9
-
10
5
  # prevent the use of local URLs (localhost:7104) from cache
11
6
  # when running under a server
12
7
  def find_blob_data_from_cache(id, access, verb, transformation_definition)
@@ -27,22 +22,22 @@ module Scrivito
27
22
  end
28
23
 
29
24
  # prevent real get requests since we run everything locally
30
- def request_blob_metadata_from_s3(url)
31
- @query_counter += 1
25
+ # def request_blob_metadata_from_s3(url)
26
+ # @query_counter += 1
32
27
 
33
- blob_id = /\/_b\/([0-9]+)/.match(url)[1]
28
+ # blob_id = /\/_b\/([0-9]+)/.match(url)[1]
34
29
 
35
- raise ScrivitoError, "Unexpected 's3' url: #{url}" unless blob_id.present?
30
+ # raise ScrivitoError, "Unexpected 's3' url: #{url}" unless blob_id.present?
36
31
 
37
- rest_api_meta_data = Fiona7::Controllers::RestAPI::BlobController.new.metadata(blob_id)
32
+ # rest_api_meta_data = Fiona7::Controllers::RestAPI::BlobController.new.metadata(blob_id)
38
33
 
39
- meta_data = {}
40
- meta_data[:content_type] = rest_api_meta_data['meta_data']['content_type'].last
41
- meta_data[:content_length] = rest_api_meta_data['meta_data']['content_length'].last
42
- meta_data[:cache_control] = 'no-transform,public,max-age=300,s-maxage=900'
34
+ # meta_data = {}
35
+ # meta_data[:content_type] = rest_api_meta_data['meta_data']['content_type'].last
36
+ # meta_data[:content_length] = rest_api_meta_data['meta_data']['content_length'].last
37
+ # meta_data[:cache_control] = 'no-transform,public,max-age=300,s-maxage=900'
43
38
 
44
- meta_data
45
- end
39
+ # meta_data
40
+ # end
46
41
 
47
42
  end
48
43
  end
@@ -4,7 +4,7 @@ module Scrivito
4
4
  class CmsRestApi
5
5
  # Stub upload_future_binary since the uploads are handled directly in ruby.
6
6
  def self.upload_future_binary(future_binary, obj_id)
7
- file = future_binary.file_to_be_uploaded
7
+ file = future_binary.file_to_upload
8
8
  # TODO: code deduplication with obj builder
9
9
  parent = Fiona7::WriteObj.find(obj_id.to_i)
10
10
  ext = ::File.extname(file.path).to_s[1..-1]
@@ -4,7 +4,7 @@ module Scrivito
4
4
  class CmsRouting
5
5
  def convert_links(html)
6
6
  if html
7
- html.to_str.gsub(%r{\bobjid:([a-f0-9]{4,16})\b([^"']*)}) do
7
+ html.to_str.gsub(%r{\bobjid:([a-f0-9]{4,})\b([^"']*)}) do
8
8
  if obj = Obj.find_by_id($1)
9
9
  options = {}
10
10
 
@@ -12,13 +12,14 @@ module Scrivito
12
12
  begin
13
13
  uri = URI.parse($2)
14
14
  options.merge!(extract_query(uri))
15
- options['anchor'] = uri.fragment
15
+ options[:anchor] = uri.fragment
16
16
  rescue
17
17
  end
18
18
  end
19
19
 
20
20
  if editing_context.display_mode == 'editing'
21
- id_path_or_url_for_objs(obj, :path, options)
21
+ options[:id] = obj.id
22
+ scrivito_engine.base_id_path(options)
22
23
  else
23
24
  path_or_url(obj, :path, options)
24
25
  end
@@ -29,46 +30,62 @@ module Scrivito
29
30
  end
30
31
  end
31
32
 
32
- # do not reference global Obj
33
- def path_or_url_without_editing_context(target, path_or_url, options)
34
- if target.is_a?(Link)
35
- path_or_url_for_links(target, path_or_url, options)
36
- elsif target.is_a?(Obj) || target.is_a?(BasicObj)
37
- path_or_url_for_objs(target, path_or_url, options)
38
- elsif target.respond_to?(:first)
39
- if target.first.is_a?(Link)
40
- path_or_url_for_links(target.first, path_or_url, options)
41
- else
42
- return LINK_TO_EMPTY_LINKLIST
43
- end
44
- elsif target.is_a?(Binary)
45
- binary_url(target)
46
- else
47
- raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+
48
- "It must only be called with an Obj or a Link or a non-empty LinkList."
49
- end
50
- end
51
-
52
- # use rails connector permalinks in legacy mode
33
+ # Use fiona connector permalinks in legacy mode
53
34
  def path_or_url_for_objs(obj, path_or_url, options)
54
35
  permalink = obj.permalink
55
- if permalink
36
+ if permalink && route_defined?(:permalink)
37
+
56
38
  if Fiona7.mode == :legacy
57
- main_app
58
- .public_send("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
39
+ context.public_send("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
59
40
  else
60
- main_app
61
- .public_send("scrivito_permalink_#{path_or_url}", options.merge(:permalink => permalink))
41
+ use_route(:permalink, path_or_url, options.merge(:permalink => permalink))
62
42
  end
63
- elsif homepage?(obj)
64
- main_app.public_send("scrivito_root_#{path_or_url}", options)
43
+ elsif homepage?(obj) && route_defined?(:homepage)
44
+ use_route(:homepage, path_or_url, options)
65
45
  elsif obj.binary?
66
- binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
67
- else
46
+ # use fiona connector routes when possible
47
+ if Fiona7.mode == :legacy
48
+ if binary = obj.binary
49
+ obj_id = obj.id
50
+
51
+ context.public_send("cms_id_#{path_or_url}", {id: obj_id, slug: binary.filename})
52
+ else
53
+ LINK_TO_EMPTY_BLOB
54
+ end
55
+ else
56
+ binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
57
+ end
58
+ elsif route_defined?(:slug_id)
68
59
  slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
69
60
  id_path_or_url_for_objs(obj, path_or_url, options.merge(slug: slug))
61
+ else
62
+ raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\
63
+ "Please add a 'slug_id' definition to your routes.rb. See the documentation"\
64
+ " of 'scrivito_route' for further details."
65
+ end
66
+ end
67
+
68
+ # use fiona connector routes when possible
69
+ def id_path_or_url_for_objs(obj, path_or_url, options)
70
+ if Fiona7.mode == :standalone
71
+ options[:id] = obj.id
72
+
73
+ # Options must have the key slug.
74
+ # Otherwise Rails will use the slug from current request params.
75
+ options[:slug] ||= nil
76
+
77
+ use_route(:slug_id, path_or_url, options)
78
+ else
79
+ options[:id] = obj.id
80
+
81
+ # Options must have the key slug.
82
+ # Otherwise Rails will use the slug from current request params.
83
+ options[:slug] ||= nil
84
+
85
+ context.public_send("cms_id_#{path_or_url}", options)
70
86
  end
71
87
  end
88
+
72
89
  end
73
90
  end
74
91