scrivito_sdk 0.66.0 → 0.70.0.rc1
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.
- checksums.yaml +4 -4
- data/app/controllers/scrivito/blobs_controller.rb +5 -0
- data/app/controllers/scrivito/objs_controller.rb +2 -1
- data/app/controllers/scrivito/ui_controller.rb +33 -3
- data/app/helpers/scrivito_helper.rb +14 -20
- data/app/views/scrivito/objs/update.json.jbuilder +1 -1
- data/app/views/scrivito/ui/index.html.erb +1 -1
- data/app/views/scrivito/webservice/_workspace.json.jbuilder +2 -1
- data/config/ca-bundle.crt +1 -1
- data/config/precedence_routes.rb +3 -2
- data/lib/assets/javascripts/scrivito.js +46 -0
- data/lib/assets/javascripts/scrivito_ui.js +931 -501
- data/lib/assets/stylesheets/scrivito.css +1 -0
- data/lib/assets/stylesheets/scrivito_ui.css +1 -1
- data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +3 -3
- data/lib/generators/scrivito/page/page_generator.rb +3 -0
- data/lib/generators/scrivito/page/templates/model.erb +3 -0
- data/lib/generators/scrivito/widget/templates/model.erb +3 -0
- data/lib/generators/scrivito/widget/widget_generator.rb +3 -0
- data/lib/scrivito/attribute_content.rb +93 -60
- data/lib/scrivito/attribute_definition.rb +3 -3
- data/lib/scrivito/attribute_serializer.rb +2 -2
- data/lib/scrivito/backend/obj_data_cache.rb +22 -9
- data/lib/scrivito/basic_obj.rb +238 -130
- data/lib/scrivito/basic_widget.rb +32 -20
- data/lib/scrivito/binary.rb +74 -45
- data/lib/scrivito/binary_routing.rb +52 -0
- data/lib/scrivito/cache_middleware.rb +0 -5
- data/lib/scrivito/client_attribute_serializer.rb +134 -0
- data/lib/scrivito/cms_backend.rb +51 -33
- data/lib/scrivito/cms_data_cache.rb +1 -0
- data/lib/scrivito/cms_dispatch_controller.rb +1 -1
- data/lib/scrivito/cms_env.rb +1 -11
- data/lib/scrivito/cms_field_tag.rb +10 -7
- data/lib/scrivito/cms_rest_api/rate_limit.rb +5 -5
- data/lib/scrivito/cms_rest_api/request_timer.rb +27 -0
- data/lib/scrivito/cms_rest_api/widget_extractor.rb +8 -6
- data/lib/scrivito/cms_rest_api.rb +107 -54
- data/lib/scrivito/cms_routing.rb +13 -25
- data/lib/scrivito/configuration.rb +5 -2
- data/lib/scrivito/controller_actions.rb +68 -7
- data/lib/scrivito/controller_runtime.rb +8 -0
- data/lib/scrivito/date_attribute.rb +8 -0
- data/lib/scrivito/errors.rb +6 -3
- data/lib/scrivito/generator_helper.rb +13 -0
- data/lib/scrivito/image_tag.rb +24 -30
- data/lib/scrivito/layout_tags.rb +12 -6
- data/lib/scrivito/link.rb +46 -30
- data/lib/scrivito/log_subscriber.rb +15 -0
- data/lib/scrivito/membership.rb +3 -3
- data/lib/scrivito/membership_collection.rb +10 -10
- data/lib/scrivito/meta_data_collection.rb +22 -0
- data/lib/scrivito/model_library.rb +7 -1
- data/lib/scrivito/obj_collection.rb +18 -16
- data/lib/scrivito/obj_params_parser.rb +1 -1
- data/lib/scrivito/obj_search_enumerator.rb +35 -35
- data/lib/scrivito/page_config.rb +55 -0
- data/lib/scrivito/request_homepage.rb +23 -0
- data/lib/scrivito/routing_helper.rb +8 -8
- data/lib/scrivito/sdk_engine.rb +2 -3
- data/lib/scrivito/ui_config.rb +85 -0
- data/lib/scrivito/user.rb +30 -23
- data/lib/scrivito/user_definition.rb +48 -47
- data/lib/scrivito/widget_tag.rb +11 -0
- data/lib/scrivito/workspace.rb +93 -35
- data/lib/scrivito/workspace_selection_middleware.rb +8 -1
- data/lib/scrivito_sdk.rb +24 -24
- metadata +24 -33
- data/lib/assets/javascripts/scrivito_sdk.js +0 -57
- data/lib/assets/stylesheets/scrivito_sdk.css +0 -1
- data/lib/scrivito/client_config.rb +0 -113
- data/lib/scrivito/editing_context_helper.rb +0 -19
- data/lib/scrivito/named_link.rb +0 -39
@@ -1,13 +1,13 @@
|
|
1
1
|
<div>
|
2
|
-
<p><%= link_to 'Home', scrivito_path(Obj.
|
2
|
+
<p><%= link_to 'Home', scrivito_path(Obj.root) %></p>
|
3
3
|
|
4
|
-
<%= scrivito_tag_list :ul, Obj.
|
4
|
+
<%= scrivito_tag_list :ul, Obj.root, :toclist do |list, page| %>
|
5
5
|
<%= list.tag :li do %>
|
6
6
|
<%= link_to page.display_title, scrivito_path(page) %>
|
7
7
|
<% end %>
|
8
8
|
<% end %>
|
9
9
|
|
10
|
-
<% if Obj.
|
10
|
+
<% if Obj.root.toclist.empty? && scrivito_in_editable_view? %>
|
11
11
|
<p>(Hint: Click on the Scrivito icon to the right to create the first subpage.)</p>
|
12
12
|
<% end %>
|
13
13
|
</div>
|
@@ -3,6 +3,9 @@ module Scrivito
|
|
3
3
|
class PageGenerator < ::Rails::Generators::NamedBase
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
|
6
|
+
argument :name, type: :string
|
7
|
+
argument :attributes, type: :array, default: [], banner: 'attribute:type attribute:type'
|
8
|
+
|
6
9
|
def create_model
|
7
10
|
template 'model.erb', "app/models/#{file_name}.rb"
|
8
11
|
end
|
@@ -3,6 +3,9 @@ module Scrivito
|
|
3
3
|
class WidgetGenerator < ::Rails::Generators::NamedBase
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
|
6
|
+
argument :name, type: :string
|
7
|
+
argument :attributes, type: :array, default: [], banner: 'attribute:type attribute:type'
|
8
|
+
|
6
9
|
def create_model
|
7
10
|
template 'model.erb', "app/models/#{file_name}.rb"
|
8
11
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Scrivito
|
2
2
|
|
3
|
-
#
|
3
|
+
# This class is for handling attributes: setting and accessing their values, providing
|
4
|
+
# default values, restricting the types of widgets that may be added to a +widgetlist+
|
5
|
+
# attribute, plus a couple of convenience methods.
|
4
6
|
# @api public
|
7
|
+
# @see http://scrivito.com/attribute-types Attributes and their type
|
5
8
|
#
|
6
9
|
module AttributeContent
|
7
10
|
ATTRIBUTE_TYPES = %w[
|
@@ -24,8 +27,6 @@ module AttributeContent
|
|
24
27
|
%w[html string],
|
25
28
|
%w[multienum stringlist],
|
26
29
|
%w[string html],
|
27
|
-
%w[string],
|
28
|
-
%w[widgetlist],
|
29
30
|
]
|
30
31
|
|
31
32
|
#
|
@@ -79,11 +80,11 @@ module AttributeContent
|
|
79
80
|
|
80
81
|
#
|
81
82
|
# Returns the value of an attribute specified by its name.
|
82
|
-
# Passing an invalid key will not raise an error
|
83
|
+
# Passing an invalid key will not raise an error but return +nil+.
|
83
84
|
#
|
84
85
|
# @api public
|
85
86
|
# @param [Symbol, String] attribute_name the name of the attribute.
|
86
|
-
# @return the value of the attribute if it defined or +nil+ otherwise.
|
87
|
+
# @return the value of the attribute if it's defined or +nil+ otherwise.
|
87
88
|
#
|
88
89
|
def [](attribute_name)
|
89
90
|
attribute_name = attribute_name.to_s
|
@@ -91,19 +92,21 @@ module AttributeContent
|
|
91
92
|
end
|
92
93
|
|
93
94
|
#
|
94
|
-
# Hook method
|
95
|
-
# or widget. Override it to allow only
|
95
|
+
# Hook method that lets you control the widget classes that are made available for adding
|
96
|
+
# instances of them to this page or widget. Override it to allow only specific classes
|
97
|
+
# or none at all.
|
96
98
|
# Must return either +NilClass+, or +Array+.
|
97
99
|
#
|
98
|
-
# If +nil+ is returned (default),
|
100
|
+
# If +nil+ is returned (default), all widget classes will be available for this page
|
101
|
+
# or widget.
|
99
102
|
#
|
100
|
-
# If an +Array+ is returned,
|
101
|
-
#
|
102
|
-
# Only these classes will be available and their order will be preserved.
|
103
|
+
# If an +Array+ is returned, it is expected to include the permitted classes.
|
104
|
+
# Their order is preserved as they are offered to the user via the widget browser.
|
103
105
|
#
|
104
106
|
# @api public
|
105
|
-
# @param [String] field_name Name of the widget
|
107
|
+
# @param [String] field_name Name of the widget attribute.
|
106
108
|
# @return [nil, Array<Class>]
|
109
|
+
# @see http://scrivito.com/limiting-widget-and-page-types Limiting available widget and page types
|
107
110
|
#
|
108
111
|
def valid_widget_classes_for(field_name)
|
109
112
|
end
|
@@ -142,7 +145,7 @@ module AttributeContent
|
|
142
145
|
end
|
143
146
|
|
144
147
|
#
|
145
|
-
# Returns the
|
148
|
+
# Returns the object class name of this CMS object.
|
146
149
|
# @api public
|
147
150
|
# @return [String]
|
148
151
|
#
|
@@ -201,6 +204,18 @@ module AttributeContent
|
|
201
204
|
end
|
202
205
|
end
|
203
206
|
|
207
|
+
#
|
208
|
+
# Returns a hash to be used for the JSON serialization.
|
209
|
+
# @api public
|
210
|
+
# @note Override it in subclasses to fit your needs.
|
211
|
+
# @param [Hash] options
|
212
|
+
# @return [Hash]
|
213
|
+
# @see http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
|
214
|
+
#
|
215
|
+
def as_json(options = nil)
|
216
|
+
{id: id}
|
217
|
+
end
|
218
|
+
|
204
219
|
private
|
205
220
|
|
206
221
|
attr_writer :data_from_cms
|
@@ -249,9 +264,9 @@ module AttributeContent
|
|
249
264
|
#
|
250
265
|
module ClassMethods
|
251
266
|
#
|
252
|
-
# Instantiate an Obj or Widget instance from obj_data
|
253
|
-
# If a subclass of Obj or Widget with the same name as the
|
254
|
-
# the instantiated Obj or Widget will be an instance of that subclass.
|
267
|
+
# Instantiate an {BasicObj Obj} or {BasicWidget Widget} instance from +obj_data+.
|
268
|
+
# If a subclass of +Obj+ or +Widget+ with the same name as the +_obj_class+ property exists,
|
269
|
+
# the instantiated +Obj+ or +Widget+ will be an instance of that subclass.
|
255
270
|
#
|
256
271
|
def instantiate(obj_data)
|
257
272
|
obj_class = obj_data.value_of('_obj_class')
|
@@ -279,33 +294,35 @@ module AttributeContent
|
|
279
294
|
#
|
280
295
|
# @api public
|
281
296
|
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
297
|
+
# For the purpose of persisting model data in the CMS, the attributes of the model need
|
298
|
+
# to be defined. When defining an attribute, you specify the name under which Scrivito
|
299
|
+
# should persist its value as well as the type of content it is meant to contain, and,
|
300
|
+
# for the +enum+ and +multienum+ types, the selectable values.
|
285
301
|
#
|
286
|
-
# Attributes are inherited,
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
302
|
+
# Attributes are inherited. If, for example, the +Page+ model defines a +title+ attribute
|
303
|
+
# of the +string+ type, the +SpecialPage+ model, which inherits from +Page+, is also equipped
|
304
|
+
# with +title+. Inherited attributes can be overridden, i.e. you may redefine +title+ in
|
305
|
+
# +SpecialPage+ if you want its type to be +html+, for example.
|
290
306
|
#
|
291
307
|
# @param [Symbol, String] name name of the attribute.
|
292
|
-
# @param [Symbol, String] type type of the attribute. Scrivito supports following types:
|
308
|
+
# @param [Symbol, String] type type of the attribute. Scrivito supports the following types:
|
293
309
|
# +string+, +stringlist+, +html+, +enum+, +multienum+, +widgetlist+, +reference+,
|
294
|
-
# +referencelist+, +link+, +linklist
|
310
|
+
# +referencelist+, +link+, +linklist+, and +binary+.
|
295
311
|
# @param [Hash] options definition options.
|
296
312
|
#
|
297
|
-
# @option options [Symbol, String] :values
|
298
|
-
# If no values are
|
313
|
+
# @option options [Symbol, String] :values selectable values for +enum+ and +multienum+ attributes.
|
314
|
+
# If no values are provided for attributes of these types, the resulting array of selectable
|
315
|
+
# values is empty.
|
299
316
|
# @option options [Symbol, String] :default custom default value.
|
300
317
|
# See {Scrivito::AttributeContent::DEFAULT_ATTRIBUTE_VALUES} for factory defaults.
|
301
|
-
# See {Scrivito::AttributeContent::ClassMethods#default_for} for more advanced
|
318
|
+
# See {Scrivito::AttributeContent::ClassMethods#default_for} for more advanced defaults.
|
302
319
|
#
|
303
320
|
# @return nil
|
304
321
|
# @raise [Scrivito::ScrivitoError] if the +type+ is unknown
|
305
322
|
# @see Scrivito::AttributeContent::DEFAULT_ATTRIBUTE_VALUES
|
306
323
|
# @see Scrivito::AttributeContent::ClassMethods#default_for
|
307
324
|
#
|
308
|
-
# @example Defining attributes
|
325
|
+
# @example Defining attributes:
|
309
326
|
# class Page < ::Obj
|
310
327
|
# attribute :my_string, :string
|
311
328
|
# attribute 'my_html', 'my_html'
|
@@ -335,7 +352,7 @@ module AttributeContent
|
|
335
352
|
# Page.attribute_definitions[:my_multienum].values
|
336
353
|
# #=> []
|
337
354
|
#
|
338
|
-
# @example Inheriting attributes
|
355
|
+
# @example Inheriting attributes:
|
339
356
|
# class Page < ::Obj
|
340
357
|
# attribute :title, :string
|
341
358
|
# end
|
@@ -346,7 +363,7 @@ module AttributeContent
|
|
346
363
|
# SpecialPage.attribute_definitions[:title].type
|
347
364
|
# #=> "string"
|
348
365
|
#
|
349
|
-
# @example Overriding inherited attributes
|
366
|
+
# @example Overriding inherited attributes:
|
350
367
|
# class Page < ::Obj
|
351
368
|
# attribute :title, :string
|
352
369
|
# end
|
@@ -361,46 +378,51 @@ module AttributeContent
|
|
361
378
|
# SpecialPage.attribute_definitions[:title].type
|
362
379
|
# #=> "html"
|
363
380
|
#
|
381
|
+
# @see http://scrivito.com/default-attribute-values Specifying default attribute values
|
382
|
+
#
|
364
383
|
def attribute(name, type, options = {})
|
365
|
-
name, type, options = name, type, options
|
366
|
-
assert_valid_attribute_name(name
|
367
|
-
assert_valid_attribute_type(type
|
384
|
+
name, type, options = name.to_s, type.to_s, options
|
385
|
+
assert_valid_attribute_name(name)
|
386
|
+
assert_valid_attribute_type(type)
|
368
387
|
default = options.delete(:default) || options.delete('default')
|
369
|
-
|
370
|
-
|
388
|
+
if default
|
389
|
+
assert_valid_attribute_default(name, type, default)
|
390
|
+
default_for(name) { default }
|
391
|
+
end
|
392
|
+
own_attribute_definitions[name] = AttributeDefinition.new(name, type, options)
|
371
393
|
nil
|
372
394
|
end
|
373
395
|
|
374
396
|
#
|
375
|
-
# Sets
|
397
|
+
# Sets the default value of an attribute.
|
376
398
|
#
|
377
399
|
# @api public
|
378
400
|
#
|
379
401
|
# If {Scrivito::BasicObj.create Obj.create} or {Scrivito::BasicWidget.new Widget.new} are called
|
380
|
-
#
|
381
|
-
# return value
|
402
|
+
# without providing a value for a specific custom attribute, the +block+ is called, and its
|
403
|
+
# return value is used as the initial value of this attribute.
|
382
404
|
#
|
383
|
-
# The +block+
|
405
|
+
# The +block+ is called with two parameters.
|
384
406
|
#
|
385
|
-
# The first parameter is an +ActiveSupport::HashWithIndifferentAccess+ containing attributes
|
386
|
-
#
|
407
|
+
# The first parameter is an +ActiveSupport::HashWithIndifferentAccess+ containing the attributes
|
408
|
+
# that were passed to {Scrivito::BasicObj.create Obj.create} or
|
387
409
|
# {Scrivito::BasicWidget.new Widget.new}.
|
388
410
|
#
|
389
|
-
# The second parameter is a +Hash+ containing the context
|
390
|
-
# {Scrivito::BasicObj.create Obj.create} or {Scrivito::BasicWidget.new Widget.new}. If
|
391
|
-
#
|
392
|
-
# +:scrivito_user+ in the provided context.
|
411
|
+
# The second parameter is a +Hash+ containing the context that was handed over to
|
412
|
+
# {Scrivito::BasicObj.create Obj.create} or {Scrivito::BasicWidget.new Widget.new}. If the
|
413
|
+
# current visitor is a {Scrivito::User}, this user can be accessed by means of the
|
414
|
+
# +:scrivito_user+ key contained in the provided context.
|
393
415
|
#
|
394
416
|
# @param [Symbol, String] attribute_name the name of the attribute.
|
395
417
|
# @param [Proc] block that returns the default value.
|
396
|
-
# @raise [Scrivito::ScrivitoError] if no block
|
418
|
+
# @raise [Scrivito::ScrivitoError] if no block is present
|
397
419
|
# @return nil
|
398
420
|
#
|
399
421
|
# @see Scrivito::BasicObj.create
|
400
422
|
# @see Scrivito::BasicWidget.new
|
401
423
|
# @see Scrivito::Configuration.editing_auth
|
402
424
|
#
|
403
|
-
# @example
|
425
|
+
# @example Setting a simple default:
|
404
426
|
# class MyPage < Obj
|
405
427
|
# attribute :title, :string
|
406
428
|
# default_for(:title) { 'Spam' }
|
@@ -409,7 +431,7 @@ module AttributeContent
|
|
409
431
|
# my_page = MyPage.create
|
410
432
|
# my_page.title # => 'Spam'
|
411
433
|
#
|
412
|
-
# @example A default depending on the given attributes
|
434
|
+
# @example A default depending on the given attributes:
|
413
435
|
# class MyPage < Obj
|
414
436
|
# attribute :title, :string
|
415
437
|
#
|
@@ -428,7 +450,7 @@ module AttributeContent
|
|
428
450
|
# my_page = MyPage.create(_path: '/de/test')
|
429
451
|
# my_page.title # => 'Hier den Titel eingeben'
|
430
452
|
#
|
431
|
-
# @example A more complex default depending on the given attributes and the current user
|
453
|
+
# @example A more complex default, depending on the given attributes and the current user:
|
432
454
|
# class MyPage < Obj
|
433
455
|
# attribute :title, :string
|
434
456
|
#
|
@@ -443,8 +465,8 @@ module AttributeContent
|
|
443
465
|
# private
|
444
466
|
#
|
445
467
|
# #
|
446
|
-
# # Assuming there is a
|
447
|
-
# # of the current user.
|
468
|
+
# # Assuming there is a +MyUser+ model equipped with a +preferences+ method which
|
469
|
+
# # returns the preferences of the current user.
|
448
470
|
# # The +email+ of a +MyUser+ is the +id+ of the corresponding +Scrivito::User+ as set in
|
449
471
|
# # +Scrivito::Configuration.editing_auth+.
|
450
472
|
# #
|
@@ -466,6 +488,8 @@ module AttributeContent
|
|
466
488
|
# my_page = MyPage.create({_path: '/en/test'}, bob)
|
467
489
|
# my_page.title # => 'Hier den Titel eingeben'
|
468
490
|
#
|
491
|
+
# @see http://scrivito.com/default-attribute-values Specifying default attribute values
|
492
|
+
#
|
469
493
|
def default_for(attribute_name, &block)
|
470
494
|
attribute_name = attribute_name.to_s
|
471
495
|
raise ScrivitoError, 'No block given' unless block_given?
|
@@ -480,9 +504,9 @@ module AttributeContent
|
|
480
504
|
# widget or object instance is available. If there is, the +BasicObj#description_for_editor+
|
481
505
|
# and, respectively, +BasicWidget#description_for_editor+ instance methods are used instead.
|
482
506
|
#
|
483
|
-
# This method can be overridden to customize the description displayed to
|
507
|
+
# This method can be overridden to customize the description displayed to editors.
|
484
508
|
#
|
485
|
-
# @return [String] the
|
509
|
+
# @return [String] the +Class+ name
|
486
510
|
def description_for_editor
|
487
511
|
name
|
488
512
|
end
|
@@ -498,7 +522,7 @@ module AttributeContent
|
|
498
522
|
AttributeDefinitionCollection.new(all_attribute_definitions)
|
499
523
|
end
|
500
524
|
|
501
|
-
# For
|
525
|
+
# For testing purposes only.
|
502
526
|
def reset_attribute_defaults!
|
503
527
|
@attribute_defaults = nil
|
504
528
|
end
|
@@ -526,17 +550,17 @@ module AttributeContent
|
|
526
550
|
|
527
551
|
# @api public
|
528
552
|
#
|
529
|
-
# This method
|
530
|
-
# It does not prevent adding
|
553
|
+
# This method prevents UI users from creating +Objs+ or +Widgets+ of the given type.
|
554
|
+
# It does not prevent adding such objects programatically.
|
531
555
|
#
|
532
|
-
# By default +hide_from_editor+ is +false+.
|
556
|
+
# By default, +hide_from_editor+ is +false+.
|
533
557
|
#
|
534
|
-
# @example Hiding error pages
|
558
|
+
# @example Hiding error pages:
|
535
559
|
# class ErrorPage < Obj
|
536
560
|
# hide_from_editor
|
537
561
|
# end
|
538
562
|
#
|
539
|
-
# @example Hiding admin widgets
|
563
|
+
# @example Hiding admin widgets:
|
540
564
|
# class AdminWidget < Widget
|
541
565
|
# hide_from_editor
|
542
566
|
# end
|
@@ -573,6 +597,15 @@ module AttributeContent
|
|
573
597
|
raise ScrivitoError, "Unknown attribute type '#{type}'" unless ATTRIBUTE_TYPES.include?(type)
|
574
598
|
end
|
575
599
|
|
600
|
+
def assert_valid_attribute_default(name, type, default)
|
601
|
+
inlined_default_allowed = ['string', 'stringlist', 'enum', 'multienum', 'html']
|
602
|
+
unless inlined_default_allowed.include?(type)
|
603
|
+
raise ScrivitoError, "Attribute '#{name}': " \
|
604
|
+
"Inline defaults for '#{type}' attributes are not supported. " \
|
605
|
+
"Please use 'default_for(:#{name})' for '#{type}' attributes instead."
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
576
609
|
def all_attribute_definitions
|
577
610
|
if superclass.respond_to?(:all_attribute_definitions, true)
|
578
611
|
superclass.all_attribute_definitions.merge(own_attribute_definitions)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Scrivito
|
2
2
|
|
3
3
|
#
|
4
|
-
# This class represents
|
4
|
+
# This class represents an attribute definition.
|
5
5
|
#
|
6
6
|
# @api public
|
7
7
|
#
|
@@ -25,8 +25,8 @@ class AttributeDefinition
|
|
25
25
|
# Allowed values for an attribute.
|
26
26
|
#
|
27
27
|
# @api public
|
28
|
-
# @return [Array<String>] allowed values if type is +enum+ or +multienum+ or an empty array
|
29
|
-
# otherwise. If no values have been specified,
|
28
|
+
# @return [Array<String>] allowed values if +type+ is +enum+ or +multienum+ or an empty array
|
29
|
+
# otherwise. If no values have been specified, an empty array is returned.
|
30
30
|
#
|
31
31
|
def values
|
32
32
|
if type == 'enum' || type == 'multienum'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Scrivito
|
2
2
|
|
3
|
-
class AttributeSerializer < Struct.new(:obj_class_name)
|
3
|
+
class AttributeSerializer < Struct.new(:obj_class_name, :obj_id)
|
4
4
|
def serialize(attributes, attribute_definitions)
|
5
5
|
return attributes if attributes.blank?
|
6
6
|
serialized_attributes = attributes.map do |attribute_name, attribute_value|
|
@@ -72,7 +72,7 @@ class AttributeSerializer < Struct.new(:obj_class_name)
|
|
72
72
|
|
73
73
|
def serialize_binary_value(attribute_value, attribute_definition)
|
74
74
|
case attribute_value
|
75
|
-
when File then CmsRestApi.upload_file(attribute_value)
|
75
|
+
when File then CmsRestApi.upload_file(attribute_value, obj_id)
|
76
76
|
when UploadedBinary then attribute_value.params
|
77
77
|
else
|
78
78
|
raise_validation_error(attribute_definition.name,
|
@@ -62,6 +62,10 @@ module ObjDataCache
|
|
62
62
|
index_access
|
63
63
|
end
|
64
64
|
|
65
|
+
def write_index_not_updatable(index, key, data)
|
66
|
+
index_access
|
67
|
+
end
|
68
|
+
|
65
69
|
private
|
66
70
|
|
67
71
|
def index_access
|
@@ -94,8 +98,8 @@ module ObjDataCache
|
|
94
98
|
|
95
99
|
return nil unless updated_result
|
96
100
|
|
97
|
-
if cached_at !=
|
98
|
-
|
101
|
+
if cached_at != stable_csid
|
102
|
+
write_cache_updatable(index, key, updated_result)
|
99
103
|
end
|
100
104
|
|
101
105
|
updated_result
|
@@ -103,7 +107,12 @@ module ObjDataCache
|
|
103
107
|
end
|
104
108
|
|
105
109
|
def write_index(index, key, data)
|
106
|
-
|
110
|
+
write_cache_updatable(index, key, data)
|
111
|
+
end
|
112
|
+
|
113
|
+
# use this to cache data that cannot be updated
|
114
|
+
def write_index_not_updatable(index, key, data)
|
115
|
+
write_cache(index, key, viewed_state.content_state_id, data)
|
107
116
|
end
|
108
117
|
|
109
118
|
def read_obj(id)
|
@@ -128,8 +137,8 @@ module ObjDataCache
|
|
128
137
|
|
129
138
|
return nil unless updated_tag
|
130
139
|
|
131
|
-
if cached_at !=
|
132
|
-
|
140
|
+
if cached_at != stable_csid
|
141
|
+
write_cache_updatable("id", id, updated_tag)
|
133
142
|
end
|
134
143
|
|
135
144
|
CmsDataCache.read_data_from_tag(updated_tag)
|
@@ -141,16 +150,20 @@ module ObjDataCache
|
|
141
150
|
end
|
142
151
|
|
143
152
|
def write_obj_tag(id, tag)
|
144
|
-
|
153
|
+
write_cache_updatable("id", id, tag)
|
145
154
|
end
|
146
155
|
|
147
156
|
private
|
148
157
|
|
149
|
-
def
|
158
|
+
def write_cache_updatable(index, key, data)
|
159
|
+
write_cache(index, key, stable_csid, data)
|
160
|
+
end
|
161
|
+
|
162
|
+
def write_cache(index, key, csid, data)
|
150
163
|
raise InternalError unless data
|
151
164
|
|
152
165
|
CmsDataCache.write_obj_data_rest(
|
153
|
-
cache_id, index, key, [
|
166
|
+
cache_id, index, key, [csid, data])
|
154
167
|
end
|
155
168
|
|
156
169
|
# tries to update an outdated cache result using the changes recorded in the
|
@@ -182,7 +195,7 @@ module ObjDataCache
|
|
182
195
|
end
|
183
196
|
end
|
184
197
|
|
185
|
-
def
|
198
|
+
def stable_csid
|
186
199
|
viewed_state.next_stable_node.content_state_id
|
187
200
|
end
|
188
201
|
|