infopark_cloud_connector 6.9.5 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +8 -8
  2. data/app/controllers/rails_connector/default_cms_controller.rb +0 -1
  3. data/app/controllers/rails_connector/objs_controller.rb +31 -27
  4. data/app/helpers/rails_connector/cms_tag_helper.rb +20 -12
  5. data/app/views/rails_connector/objs/show_widget.html.erb +1 -0
  6. data/config/ca-bundle.crt +1 -1
  7. data/config/locales/de.rails_connector.views.yml +0 -3
  8. data/config/locales/en.rails_connector.views.yml +0 -3
  9. data/config/routes.rb +2 -1
  10. data/lib/assets/fonts/infopark_icons-webfont.eot +0 -0
  11. data/lib/assets/fonts/infopark_icons-webfont.ttf +0 -0
  12. data/lib/assets/fonts/infopark_icons-webfont.woff +0 -0
  13. data/lib/assets/javascripts/infopark_editing.js +84 -35
  14. data/lib/assets/stylesheets/infopark_editing.css +227 -33
  15. data/lib/generators/cms/migration/migration_generator.rb +1 -1
  16. data/lib/generators/cms/migration/templates/{migration.rb → migration.erb} +0 -0
  17. data/lib/rails_connector/attribute_content.rb +39 -40
  18. data/lib/rails_connector/basic_obj.rb +64 -56
  19. data/lib/rails_connector/basic_widget.rb +2 -0
  20. data/lib/rails_connector/cms_accessible.rb +0 -17
  21. data/lib/rails_connector/cms_backend.rb +2 -2
  22. data/lib/rails_connector/cms_env.rb +0 -5
  23. data/lib/rails_connector/cms_rest_api.rb +62 -30
  24. data/lib/rails_connector/configuration.rb +3 -3
  25. data/lib/rails_connector/connection_manager.rb +98 -0
  26. data/lib/rails_connector/content_service.rb +12 -94
  27. data/lib/rails_connector/content_state_caching.rb +3 -5
  28. data/lib/rails_connector/deprecation.rb +21 -0
  29. data/lib/rails_connector/link.rb +12 -22
  30. data/lib/rails_connector/migrations/cms_backend.rb +1 -1
  31. data/lib/rails_connector/migrations/migration.rb +1 -1
  32. data/lib/rails_connector/migrations/migration_dsl.rb +10 -101
  33. data/lib/rails_connector/named_link.rb +1 -1
  34. data/lib/rails_connector/obj_search_enumerator.rb +37 -49
  35. metadata +6 -5
  36. data/app/views/errors/410_gone.html.erb +0 -7
  37. data/app/views/rails_connector/objs/show.html.erb +0 -1
@@ -20,7 +20,7 @@ module RailsConnector
20
20
  @_type_computer = nil
21
21
  end
22
22
 
23
- # Create a new Obj instance with the given values and attributes.
23
+ # Create a new {BasicObj Obj} instance with the given values and attributes.
24
24
  # Normally this method should not be used.
25
25
  # Instead Objs should be loaded from the cms database.
26
26
  def initialize(obj_data = {})
@@ -38,7 +38,7 @@ module RailsConnector
38
38
 
39
39
  ### FINDERS ####################
40
40
 
41
- # Find an Obj by it's id.
41
+ # Find an {BasicObj Obj} by its id.
42
42
  # If the paremeter is an Array containing ids, return a list of corresponding Objs.
43
43
  # @param [String, Integer, Array<String, Integer>]id_or_list
44
44
  # @return [Obj, Array<Obj>]
@@ -71,15 +71,15 @@ module RailsConnector
71
71
  ObjSearchEnumerator.new(nil).and(field, operator, value, boost)
72
72
  end
73
73
 
74
- # Returns a {ObjSearchEnumerator} of all Objs.
75
- # If invoked on a subclass of Obj, the result will be restricted to Obj of that subclass.
74
+ # Returns a {ObjSearchEnumerator} of all {BasicObj Obj}s.
75
+ # If invoked on a subclass of Obj, the result will be restricted to instances of that subclass.
76
76
  # @return [ObjSearchEnumerator]
77
77
  # @api public
78
78
  def self.all
79
79
  if superclass == RailsConnector::BasicObj
80
- ObjSearchEnumerator.new(nil)
80
+ search_for_all
81
81
  else
82
- find_all_by_obj_class(self.name)
82
+ find_all_by_obj_class(name)
83
83
  end
84
84
  end
85
85
 
@@ -88,12 +88,12 @@ module RailsConnector
88
88
  # @return [ObjSearchEnumerator]
89
89
  # @api public
90
90
  def self.find_all_by_obj_class(obj_class)
91
- where(:_obj_class, :equals, obj_class)
91
+ search_for_all.and(:_obj_class, :equals, obj_class)
92
92
  end
93
93
 
94
- # Find the Obj with the given path.
94
+ # Find the {BasicObj Obj} with the given path.
95
95
  # Returns +nil+ if no matching Obj exists.
96
- # @param [String] path Path of the {Obj}.
96
+ # @param [String] path Path of the {BasicObj Obj}.
97
97
  # @return [Obj]
98
98
  # @api public
99
99
  def self.find_by_path(path)
@@ -104,10 +104,10 @@ module RailsConnector
104
104
  find_objs_by(:path, pathes).map(&:first)
105
105
  end
106
106
 
107
- # Find an Obj with the given name.
107
+ # Find an {BasicObj Obj} with the given name.
108
108
  # If several Objs with the given name exist, an arbitrary one of these Objs is chosen and returned.
109
109
  # If no Obj with the name exits, +nil+ is returned.
110
- # @param [String] name Name of the {Obj}.
110
+ # @param [String] name Name of the {BasicObj Obj}.
111
111
  # @return [Obj]
112
112
  # @api public
113
113
  def self.find_by_name(name)
@@ -115,23 +115,23 @@ module RailsConnector
115
115
  end
116
116
 
117
117
  # Returns a {ObjSearchEnumerator} of all Objs with the given name.
118
- # @param [String] name Name of the {Obj}.
118
+ # @param [String] name Name of the {BasicObj Obj}.
119
119
  # @return [ObjSearchEnumerator]
120
120
  # @api public
121
121
  def self.find_all_by_name(name)
122
122
  where(:_name, :equals, name)
123
123
  end
124
124
 
125
- # Returns the Obj with the given permalink, or +nil+ if no matching Obj exists.
126
- # @param [String] permalink The permalink of the {Obj}.
125
+ # Returns the {BasicObj Obj} with the given permalink, or +nil+ if no matching Obj exists.
126
+ # @param [String] permalink The permalink of the {BasicObj Obj}.
127
127
  # @return [Obj]
128
128
  # @api public
129
129
  def self.find_by_permalink(permalink)
130
130
  find_objs_by(:permalink, [permalink]).first.first
131
131
  end
132
132
 
133
- # Returns the Obj with the given permalink, or raise ResourceNotFound if no matching Obj exists.
134
- # @param [String] permalink The permalink of the {Obj}.
133
+ # Returns the {BasicObj Obj} with the given permalink, or raise ResourceNotFound if no matching Obj exists.
134
+ # @param [String] permalink The permalink of the {BasicObj Obj}.
135
135
  # @return [Obj]
136
136
  # @api public
137
137
  def self.find_by_permalink!(permalink)
@@ -147,18 +147,18 @@ module RailsConnector
147
147
  end
148
148
  end
149
149
 
150
- # Hook method to control which page classes should be avaiable for a page with given path.
150
+ # Hook method to control which page classes should be available for a page with given path.
151
151
  # Override it to allow only certain classes or none.
152
- # Must return either {NilClass}, or {Array}.
152
+ # Must return either +NilClass+, or +Array+.
153
153
  #
154
154
  # Be aware that the given argument is a parent path.
155
155
  # E.g. when creating a page with path +/products/shoes+ then the argument will be +/products+.
156
156
  #
157
- # If {NilClass} is returned, then all possible classes will be available.
158
- # By default {NilClass} is returned.
157
+ # If +NilClass+ is returned, then all possible classes will be available.
158
+ # By default +NilClass+ is returned.
159
159
  #
160
- # If {Array} is returned, then it should include desired class names.
161
- # Each class name must be either a {String} or a {Symbol}.
160
+ # If +Array+ is returned, then it should include desired class names.
161
+ # Each class name must be either a +String+ or a +Symbol+.
162
162
  # Only this class names will be available. Order of the class names will be preserved.
163
163
  #
164
164
  # @param [String] parent_path Path of the parent obj
@@ -171,7 +171,7 @@ module RailsConnector
171
171
  id
172
172
  end
173
173
 
174
- # return the Obj that is the parent of this Obj.
174
+ # return the {BasicObj Obj} that is the parent of this Obj.
175
175
  # returns +nil+ for the root Obj.
176
176
  # @api public
177
177
  def parent
@@ -190,7 +190,7 @@ module RailsConnector
190
190
  BasicObj.find_many_by_paths(ancestor_paths)
191
191
  end
192
192
 
193
- # return a list of all child Objs.
193
+ # return a list of all child {BasicObj Obj}s.
194
194
  # @return [Array<Obj>]
195
195
  # @api public
196
196
  def children
@@ -199,13 +199,13 @@ module RailsConnector
199
199
 
200
200
  ### ATTRIBUTES #################
201
201
 
202
- # returns the Obj's path as a String.
202
+ # returns the {BasicObj Obj}'s path as a String.
203
203
  # @api public
204
204
  def path
205
205
  read_attribute('_path') or raise 'Obj without path'
206
206
  end
207
207
 
208
- # returns the Obj's name, i.e. the last component of the path.
208
+ # returns the {BasicObj Obj}'s name, i.e. the last component of the path.
209
209
  # @api public
210
210
  def name
211
211
  if root?
@@ -238,7 +238,7 @@ module RailsConnector
238
238
  end
239
239
  end
240
240
 
241
- # Returns the root Obj, i.e. the Obj with the path "/"
241
+ # Returns the root {BasicObj Obj}, i.e. the Obj with the path "/"
242
242
  # @return [Obj]
243
243
  # @api public
244
244
  def self.root
@@ -246,21 +246,26 @@ module RailsConnector
246
246
  "Obj.root not found: There is no Obj with path '/'."
247
247
  end
248
248
 
249
- # Returns the homepage object. This can be overwritten in your application's +Obj+.
250
- # Use <tt>Obj#homepage?</tt> to check if an object is the homepage.
249
+ # Returns the homepage obj. This can be overwritten in your application's +Obj+.
250
+ # Use {#homepage?} to check if an obj is the homepage.
251
251
  # @return [Obj]
252
252
  # @api public
253
253
  def self.homepage
254
254
  root
255
255
  end
256
256
 
257
+ # @api private
258
+ def self.generate_widget_pool_id
259
+ SecureRandom.hex(4)
260
+ end
261
+
257
262
  # returns the obj's permalink.
258
263
  # @api public
259
264
  def permalink
260
265
  read_attribute('_permalink')
261
266
  end
262
267
 
263
- # This method determines the controller that should be invoked when the Obj is requested.
268
+ # This method determines the controller that should be invoked when the +Obj+ is requested.
264
269
  # By default a controller matching the Obj's obj_class will be used.
265
270
  # If the controller does not exist, the CmsController will be used as a fallback.
266
271
  # Overwrite this method to force a different controller to be used.
@@ -270,7 +275,7 @@ module RailsConnector
270
275
  obj_class
271
276
  end
272
277
 
273
- # This method determines the action that should be invoked when the Obj is requested.
278
+ # This method determines the action that should be invoked when the +Obj+ is requested.
274
279
  # The default action is 'index'.
275
280
  # Overwrite this method to force a different action to be used.
276
281
  # @return [String]
@@ -279,20 +284,20 @@ module RailsConnector
279
284
  "index"
280
285
  end
281
286
 
282
- # Returns true if the current object is the homepage object.
287
+ # Returns true if the current obj is the {.homepage} obj.
283
288
  # @api public
284
289
  def homepage?
285
290
  self == self.class.homepage
286
291
  end
287
292
 
288
- # This method is used to calculate part a part of a URL of an obj.
293
+ # This method is used to calculate a part of a URL of this Obj.
289
294
  #
290
295
  # The routing schema: <code><em><obj.id></em>/<em><obj.slug></em></code>
291
296
  #
292
297
  # The default is {http://apidock.com/rails/ActiveSupport/Inflector/parameterize parameterize}
293
298
  # on +obj.title+.
294
299
  #
295
- # You can customize this part by overwriting +obj.slug+ in {Obj}.
300
+ # You can customize this part by overwriting {#slug}.
296
301
  # @return [String]
297
302
  # @api public
298
303
  def slug
@@ -343,37 +348,37 @@ module RailsConnector
343
348
 
344
349
  # Returns true if this object is active.
345
350
  # @api public
351
+ # @deprecated Active is deprecated without substitution.
346
352
  def active?
353
+ Deprecation.warn_method('Obj#active?')
347
354
  return false unless valid_from
348
355
  valid_from <= Time.now && (!valid_until || Time.now <= valid_until)
349
356
  end
350
357
 
351
358
  # compatibility with legacy apps.
352
359
  def suppress_export
360
+ Deprecation.warn_method('Obj#suppress_export?')
353
361
  suppressed? ? 1 : 0
354
362
  end
355
363
 
356
- # Returns true if the Obj is suppressed.
364
+ # Returns true if the {BasicObj Obj} is suppressed.
357
365
  # A suppressed Obj does not represent an entire web page, but only a part of a page
358
366
  # (for example a teaser) and will not be delivered by the rails application
359
367
  # as a standalone web page.
360
368
  def suppressed?
369
+ Deprecation.warn_method('Obj#suppressed?')
361
370
  read_attribute('_suppress_export') ? true : false
362
371
  end
363
372
 
364
373
  # Returns true if the export of the object is not suppressed and the content is active?
365
374
  def exportable?
375
+ Deprecation.warn_method('Obj#exportable?')
366
376
  !suppressed? && active?
367
377
  end
368
378
 
369
379
  # Returns the file name to which the Content.file_extension has been appended.
370
380
  def filename
371
- Rails.logger.warn(
372
- "DEPRECATION WARNING: "\
373
- "The Method Obj#filename is no longer supported. Please use Obj#name instead. "\
374
- "From: #{caller[0]}"
375
- )
376
-
381
+ Deprecation.warn_method('Obj#filename', 'Obj#name')
377
382
  name
378
383
  end
379
384
 
@@ -390,13 +395,13 @@ module RailsConnector
390
395
  path == "/"
391
396
  end
392
397
 
393
- # Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
398
+ # Returns a list of children excluding the binary? ones unless :all is specfied.
394
399
  # This is mainly used for navigations.
395
400
  # @return [Array<Obj>]
396
401
  # @api public
397
402
  def toclist(*args)
398
403
  return [] unless publication?
399
- toclist = children.select{ |toc| toc.exportable? }
404
+ toclist = children
400
405
  toclist = toclist.reject { |toc| toc.binary? } unless args.include?(:all)
401
406
  toclist
402
407
  end
@@ -470,8 +475,12 @@ module RailsConnector
470
475
  # @api public
471
476
  def find_nearest(name)
472
477
  obj = self.class.find_by_path(root? ? "/#{name}" : "#{path}/#{name}")
473
- return obj if obj and obj.active?
474
- parent.find_nearest(name) unless self.root?
478
+
479
+ if obj
480
+ obj
481
+ elsif !self.root?
482
+ parent.find_nearest(name)
483
+ end
475
484
  end
476
485
 
477
486
  # This should be a SET, because it's faster in this particular case.
@@ -523,10 +532,6 @@ module RailsConnector
523
532
  update_data(obj_data)
524
533
  end
525
534
 
526
- def text_links
527
- read_attribute('_text_links')
528
- end
529
-
530
535
  # @return [String]
531
536
  # @api public
532
537
  def obj_class
@@ -548,7 +553,7 @@ module RailsConnector
548
553
  read_attribute('_valid_until')
549
554
  end
550
555
 
551
- # For a binary Obj, the content_type is equal to the content_type of it's body (i.e. it's data).
556
+ # For a binary Obj, the content_type is equal to the content_type of its body (i.e. its data).
552
557
  # For non-binary Objs, a the default content_type is "text/html".
553
558
  # Override this method in subclasses to define a different content_type.
554
559
  # Note that only Objs with content_type "text/html"
@@ -635,12 +640,7 @@ module RailsConnector
635
640
  if children.any?
636
641
  raise ClientError.new(I18n.t('rails_connector.errors.models.basic_obj.has_children'), 412)
637
642
  end
638
- self.class.find_objs_by(:ppath, ["/_widgets/#{id}"]).first.map(&:destroy)
639
- CmsRestApi.delete("revisions/#{Workspace.current.revision_id}/objs/#{id}")
640
- end
641
-
642
- def widget_container
643
- @widget_container ||= self.class.find(parent_path.split('/').last)
643
+ CmsRestApi.delete("workspaces/#{Workspace.current.id}/objs/#{id}")
644
644
  end
645
645
 
646
646
  def edit_view_path
@@ -706,6 +706,14 @@ module RailsConnector
706
706
  def converted_sort_type(attribute)
707
707
  read_attribute(attribute) == 1 ? "numeric" : "alphaNumeric"
708
708
  end
709
+
710
+ class << self
711
+ private
712
+
713
+ def search_for_all
714
+ ObjSearchEnumerator.new(nil).batch_size(1000)
715
+ end
716
+ end
709
717
  end
710
718
 
711
719
  end
@@ -15,6 +15,8 @@ class BasicWidget
15
15
 
16
16
  alias_method :initialize, :update_data
17
17
 
18
+ delegate :widget_from_pool, to: :obj
19
+
18
20
  def obj_class
19
21
  data_from_cms.value_of('_obj_class')
20
22
  end
@@ -16,23 +16,6 @@ module RailsConnector
16
16
  @obj = loaded_obj
17
17
  end
18
18
 
19
- # Filter method to check if the already loaded object is active. If it is
20
- # not, a 410 Gone error message will be generate (by calling render_obj_error).
21
- #
22
- # To require the check for all actions, use this in your controllers:
23
- # before_filter :load_object
24
- # before_filter :ensure_object_is_active
25
- def ensure_object_is_active
26
- unless @obj.active?
27
- @valid_from = @obj.valid_from
28
- @valid_until = @obj.valid_until
29
- @obj = nil
30
- render_obj_error(410, "gone")
31
- return false
32
- end
33
- return true
34
- end
35
-
36
19
  # Filter method to check if access to the loaded object is permitted. If it is
37
20
  # not, a 403 Forbidden error message will be generated (by calling render_obj_error)
38
21
  #
@@ -155,7 +155,7 @@ module RailsConnector
155
155
  end
156
156
 
157
157
  def find_raw_data_from_cache_by(workspace_data, index, key)
158
- ContentStateCaching.find_obj_data(workspace_data, index, key) if caching?
158
+ ContentStateCaching.find_obj_data(workspace_data.content_state, index, key) if caching?
159
159
  end
160
160
 
161
161
  def find_raw_data_from_database_by(workspace_data, index, keys)
@@ -195,7 +195,7 @@ module RailsConnector
195
195
  end
196
196
 
197
197
  def store_item_in_cache(workspace_data, index, key, item)
198
- ContentStateCaching.store_obj_data(workspace_data, index, key, item)
198
+ ContentStateCaching.store_obj_data(workspace_data.content_state, index, key, item)
199
199
  end
200
200
 
201
201
  def find_blob_data_from_database_by(id)
@@ -46,11 +46,6 @@ module RailsConnector
46
46
  end
47
47
  end
48
48
 
49
- if found_obj.suppressed?
50
- raise RailsConnector::ResourceNotFound,
51
- "Tried to access Obj #{found_obj.inspect}, but it is suppressed (suppress_export is set)!"
52
- end
53
-
54
49
  found_obj
55
50
  end
56
51
 
@@ -28,6 +28,15 @@ module RailsConnector
28
28
  # RailsConnector::CmsRestApi.task_unaware_request(:put, 'workspace/rtc/publish', nil)
29
29
  #
30
30
  class CmsRestApi
31
+ DEFAULT_PROTOCOL = 'https'.freeze
32
+
33
+ METHOD_TO_NET_HTTP_CLASS = {
34
+ :get => Net::HTTP::Get,
35
+ :put => Net::HTTP::Put,
36
+ :post => Net::HTTP::Post,
37
+ :delete => Net::HTTP::Delete,
38
+ }.freeze
39
+
31
40
  class Configuration
32
41
  attr_accessor :url
33
42
  attr_accessor :login
@@ -71,11 +80,18 @@ module RailsConnector
71
80
  response_for_request_cms_api(method, resource_path, payload)
72
81
  end
73
82
 
83
+ # This method is mainly for tests
84
+ def self.reset!
85
+ @connection_manager = nil
86
+ end
87
+
74
88
  class << self
75
89
 
76
90
  private
77
91
 
78
92
  def request_cms_api(action, resource_path, payload, options)
93
+ reset_connection_manager if connection_manager.uri != uri
94
+
79
95
  decoded = response_for_request_cms_api(action, resource_path, payload)
80
96
  return decoded unless Hash === decoded
81
97
  return decoded unless decoded.keys == ["task"]
@@ -85,26 +101,30 @@ module RailsConnector
85
101
  final_response(task_path, options)
86
102
  end
87
103
 
88
- def response_for_request_cms_api(action, resource_path, payload)
89
- request_params = basic_request_params
90
- request_params[:method] = action
91
- request_params[:url] = url(resource_path)
92
- request_params[:payload] = MultiJson.encode(payload) if payload.present?
93
- MultiJson.decode(RestClient::Request.execute(request_params))
94
- rescue RestClient::ExceptionWithResponse => e
95
- http_code = e.http_code
96
- if http_code == 403
97
- raise AccessDenied.new(e.http_body)
98
- elsif 400 <= http_code && http_code < 500
104
+ def response_for_request_cms_api(method, resource_path, payload = nil)
105
+ request = method_to_net_http_class(method).new(path(resource_path))
106
+ set_headers(request)
107
+ request.body = MultiJson.encode(payload) if payload.present?
108
+
109
+ handle_response(connection_manager.request(request))
110
+ end
111
+
112
+ def handle_response(response)
113
+ code = response.code.to_i
114
+ if code.to_s.start_with?('2')
115
+ MultiJson.load(response.body)
116
+ elsif response.code == '403'
117
+ raise AccessDenied.new(response.body)
118
+ elsif (400...500).include?(code)
99
119
  begin
100
- specific_output = MultiJson.decode(e.http_body)['error']
120
+ specific_output = MultiJson.decode(response.body)['error']
121
+ raise ClientError.new(specific_output, code)
101
122
  rescue MultiJson::DecodeError
102
- # fall through
103
- else
104
- raise ClientError.new(specific_output, http_code)
123
+ raise BackendNotAvailable.new(response.body, code)
105
124
  end
125
+ else
126
+ raise BackendNotAvailable.new(response.body, code)
106
127
  end
107
- raise BackendNotAvailable.new(e.http_body, http_code)
108
128
  end
109
129
 
110
130
  def final_response(task_path, options)
@@ -121,22 +141,34 @@ module RailsConnector
121
141
  raise ClientError.new(message, 400)
122
142
  end
123
143
 
124
- def basic_request_params
125
- headers = {
126
- :content_type => :json,
127
- :accept => :json,
128
- }
129
- headers[:host] = configuration.http_host if configuration.http_host.present?
130
-
131
- {
132
- :user => configuration.login,
133
- :password => configuration.api_key,
134
- :headers => headers,
135
- }
144
+ def set_headers(request)
145
+ request.basic_auth(configuration.login, configuration.api_key)
146
+ request['Content-type'] = 'application/json'
147
+ request['Accept'] = 'application/json'
148
+
149
+ request['Host'] = configuration.http_host if configuration.http_host.present?
150
+ end
151
+
152
+ def path(path)
153
+ "/#{path}".squeeze('/')
154
+ end
155
+
156
+ def connection_manager
157
+ @connection_manager ||= ConnectionManager.new(uri)
158
+ end
159
+
160
+ def uri
161
+ url = configuration.url
162
+ url = "#{DEFAULT_PROTOCOL}://#{url}" unless url.match /^http/
163
+ URI.parse(url)
164
+ end
165
+
166
+ def method_to_net_http_class(method)
167
+ METHOD_TO_NET_HTTP_CLASS.fetch(method)
136
168
  end
137
169
 
138
- def url(resource_path)
139
- "#{configuration.url}/#{resource_path}"
170
+ def reset_connection_manager
171
+ @connection_manager = ConnectionManager.new(uri)
140
172
  end
141
173
  end
142
174
  end