scrivito_sdk 0.65.2 → 0.66.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/binary_redirect_controller.rb +19 -0
  3. data/app/controllers/scrivito/objs_controller.rb +6 -2
  4. data/app/controllers/scrivito/webservice_controller.rb +1 -1
  5. data/app/controllers/scrivito/workspaces_controller.rb +1 -7
  6. data/app/helpers/scrivito_helper.rb +115 -64
  7. data/app/views/scrivito/objs/is_outdated.json.jbuilder +1 -0
  8. data/app/views/scrivito/ui/index.html.erb +1 -0
  9. data/config/ca-bundle.crt +1 -1
  10. data/config/precedence_routes.rb +6 -4
  11. data/config/routes.rb +1 -1
  12. data/lib/assets/images/scrivito/source_too_large.png +0 -0
  13. data/lib/assets/images/scrivito/source_type_invalid.png +0 -0
  14. data/lib/assets/javascripts/scrivito_ui.js +2975 -357
  15. data/lib/assets/stylesheets/scrivito_sdk.css +1 -3
  16. data/lib/assets/stylesheets/scrivito_ui.css +1 -3
  17. data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito_migration.rb +0 -2
  18. data/lib/generators/scrivito/migration/templates/migration.erb +6 -8
  19. data/lib/scrivito/attribute_content.rb +16 -52
  20. data/lib/scrivito/attribute_deserializer.rb +3 -5
  21. data/lib/scrivito/attribute_serializer.rb +42 -45
  22. data/lib/scrivito/backend/content_state_node.rb +71 -19
  23. data/lib/scrivito/backend/index.rb +20 -0
  24. data/lib/scrivito/backend/obj_data_cache.rb +157 -31
  25. data/lib/scrivito/backend/obj_data_from_rest.rb +1 -0
  26. data/lib/scrivito/backend/obj_load.rb +10 -6
  27. data/lib/scrivito/backend/obj_query.rb +2 -1
  28. data/lib/scrivito/backend/parent_path_index.rb +5 -1
  29. data/lib/scrivito/backend/path_index.rb +5 -1
  30. data/lib/scrivito/backend/permalink_index.rb +18 -10
  31. data/lib/scrivito/basic_obj.rb +62 -42
  32. data/lib/scrivito/basic_widget.rb +5 -5
  33. data/lib/scrivito/binary.rb +154 -13
  34. data/lib/scrivito/binary_param_verifier.rb +31 -0
  35. data/lib/scrivito/binary_rewrite.rb +35 -0
  36. data/lib/scrivito/cache_middleware.rb +5 -0
  37. data/lib/scrivito/child_list_tag.rb +3 -3
  38. data/lib/scrivito/cms_backend.rb +89 -57
  39. data/lib/scrivito/cms_data_cache.rb +21 -4
  40. data/lib/scrivito/cms_dispatch_controller.rb +13 -0
  41. data/lib/scrivito/cms_field_tag.rb +16 -3
  42. data/lib/scrivito/cms_rest_api.rb +2 -2
  43. data/lib/scrivito/cms_routing.rb +41 -18
  44. data/lib/scrivito/configuration.rb +22 -0
  45. data/lib/scrivito/content_state.rb +1 -9
  46. data/lib/scrivito/content_state_caching.rb +0 -20
  47. data/lib/scrivito/controller_actions.rb +3 -2
  48. data/lib/scrivito/controller_runtime.rb +16 -8
  49. data/lib/scrivito/dialog_size_helper.rb +11 -0
  50. data/lib/scrivito/diff.rb +0 -2
  51. data/lib/scrivito/editing_context.rb +24 -13
  52. data/lib/scrivito/editing_context_middleware.rb +6 -1
  53. data/lib/scrivito/errors.rb +18 -0
  54. data/lib/scrivito/image_tag.rb +55 -0
  55. data/lib/scrivito/link.rb +12 -0
  56. data/lib/scrivito/membership_collection.rb +3 -2
  57. data/lib/scrivito/migrations/cms_backend.rb +6 -13
  58. data/lib/scrivito/migrations/migrator.rb +2 -23
  59. data/lib/scrivito/migrations/workspace_lock.rb +23 -11
  60. data/lib/scrivito/named_link.rb +1 -1
  61. data/lib/scrivito/obj_collection.rb +1 -1
  62. data/lib/scrivito/obj_data_from_service.rb +0 -7
  63. data/lib/scrivito/obj_search_enumerator.rb +2 -2
  64. data/lib/scrivito/parent_path.rb +9 -0
  65. data/lib/scrivito/routing_helper.rb +2 -2
  66. data/lib/scrivito/user.rb +2 -2
  67. data/lib/scrivito/user_definition.rb +2 -2
  68. data/lib/scrivito/widget_garbage_collection.rb +2 -2
  69. data/lib/scrivito/widget_tag.rb +6 -3
  70. data/lib/scrivito/workspace.rb +60 -41
  71. data/lib/scrivito/workspace_data.rb +40 -4
  72. data/lib/scrivito/workspace_data_from_service.rb +0 -10
  73. data/lib/scrivito_sdk.rb +0 -16
  74. metadata +12 -12
  75. data/lib/scrivito/attribute.rb +0 -152
  76. data/lib/scrivito/attribute_collection.rb +0 -66
  77. data/lib/scrivito/attribute_definition_migrator.rb +0 -188
  78. data/lib/scrivito/cms_rest_api/legacy_attribute_serializer.rb +0 -105
  79. data/lib/scrivito/image_tag_helper.rb +0 -46
  80. data/lib/scrivito/obj_class.rb +0 -258
  81. data/lib/scrivito/obj_class_collection.rb +0 -71
  82. data/lib/scrivito/obj_class_data.rb +0 -37
  83. data/lib/tasks/migrate_attribute_definitions.rake +0 -6
@@ -1,105 +0,0 @@
1
- module Scrivito
2
- class CmsRestApi
3
- module LegacyAttributeSerializer
4
- class << self
5
-
6
- def generate_widget_pool_changes(widget_hash)
7
- widget_pool_changes = {}
8
-
9
- widget_hash.each do |widget, attributes|
10
- if attributes.present?
11
- widget_pool_changes[widget.id] =
12
- self.convert(attributes)
13
- else # Empty hash or nil
14
- widget_pool_changes[widget.id] = attributes
15
- end
16
- end
17
-
18
- widget_pool_changes
19
- end
20
-
21
- def convert(attributes)
22
- Hash[
23
- attributes.map do |attribute_name, value|
24
- attribute_name = attribute_name.to_s
25
-
26
- converted_value = if value.nil? || value == []
27
- nil
28
- elsif link_array?(value)
29
- convert_links(value)
30
- elsif value.is_a?(Link)
31
- convert_link(value)
32
- elsif value.is_a?(BasicObj)
33
- value.id
34
- elsif widget_array?(value)
35
- convert_widgets(value)
36
- elsif obj_array?(value)
37
- value.map(&:id)
38
- elsif value.is_a?(Time) || value.is_a?(Date)
39
- convert_time(value)
40
- elsif value.is_a?(Array)
41
- value.map(&:to_s)
42
- elsif value.is_a?(File)
43
- Scrivito::CmsRestApi.upload_file(value)
44
- elsif value.is_a?(UploadedBinary)
45
- value.params
46
- else
47
- value.to_s
48
- end
49
-
50
- [attribute_name, converted_value]
51
- end
52
- ]
53
- end
54
-
55
- def convert_time(point_in_time)
56
- time_object = if point_in_time.instance_of?(Date)
57
- point_in_time.to_time
58
- else
59
- point_in_time.to_time.utc
60
- end
61
-
62
- time_object.strftime("%Y%m%d%H%M%S")
63
- end
64
-
65
- private
66
-
67
- def widget_array?(value)
68
- value.is_a?(Array) && value.all? do |element|
69
- element.is_a?(BasicWidget)
70
- end
71
- end
72
-
73
- def convert_widgets(value)
74
- converted_widgets = value.map do |widget|
75
- { 'widget' => widget.id }
76
- end
77
-
78
- { 'list' => converted_widgets }
79
- end
80
-
81
- def link_array?(value)
82
- value.is_a?(Array) && value.all? do |element|
83
- element.is_a?(Link)
84
- end
85
- end
86
-
87
- def obj_array?(value)
88
- value.is_a?(Array) && value.all? do |element|
89
- element.is_a?(BasicObj)
90
- end
91
- end
92
-
93
- def convert_links(links)
94
- links.map do |link|
95
- convert_link(link)
96
- end
97
- end
98
-
99
- def convert_link(link)
100
- link.to_cms_api_linklist_params
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,46 +0,0 @@
1
- module Scrivito
2
-
3
- class ImageTagHelper < Struct.new(:view_context)
4
-
5
- def self.display_title(target)
6
- if target.respond_to?(:display_title)
7
- target.display_title
8
- elsif target.respond_to?(:first) && target.first.respond_to?(:display_title)
9
- target.first.display_title
10
- elsif target.respond_to?(:filename)
11
- target.filename
12
- end
13
- end
14
-
15
- def options(obj, field_name, tag_options, editing_options)
16
- tag_options.reverse_merge(src: scrivito_image_tag_src(obj, field_name, editing_options),
17
- alt: scrivito_image_tag_alt(obj, field_name))
18
- end
19
-
20
- private
21
-
22
- def scrivito_image_tag_src(obj, field_name, editing_options)
23
- scrivito_image_tag_path(obj, field_name) || editing_options[:placeholder] ||
24
- view_context.image_path('scrivito/image_placeholder.png')
25
- end
26
-
27
- def scrivito_image_tag_alt(obj, field_name)
28
- self.class.display_title(obj[field_name])
29
- end
30
-
31
- def scrivito_image_tag_path(obj, field_name)
32
- field_type = obj.type_of_attribute(field_name)
33
- field_value = obj[field_name]
34
-
35
- case field_type
36
- when 'link', 'binary', 'reference'
37
- field_value && view_context.scrivito_path(field_value)
38
- when 'linklist'
39
- path = view_context.scrivito_path(field_value)
40
- path == CmsRouting::LINK_TO_EMPTY_LINKLIST ? nil : path
41
- end
42
- end
43
-
44
- end
45
-
46
- end
@@ -1,258 +0,0 @@
1
- module Scrivito
2
- # This class represents a CMS obj class. Obj classes can be created, updated and all properties
3
- # can be read. The class also provides methods to find obj classes. The attributes of an obj class
4
- # are defined by {Scrivito::Attribute} instances.
5
- #
6
- # @api public
7
- # @deprecated
8
- class ObjClass
9
- include ModelIdentity
10
-
11
- class << self
12
- #
13
- # Remove all obj classes.
14
- #
15
- # This method removes all classes in the corresponding workspace. By doing that it migrates
16
- # the contents of the workspace. The migrated workspace will not use {Scrivito::ObjClass},
17
- # {Scrivito::Attribute} etc. anymore to determine which attributes an {Obj} has, but will
18
- # use attributes defined in model with {Scrivito::AttributeContent::ClassMethods#attribute}.
19
- # The +id+ of the current workspace must be +"rtc"+.
20
- # For detailed migration instructions please visit https://scrivito.com/obj-class-migration.
21
- #
22
- # @api public
23
- # @see Scrivito::AttributeContent::ClassMethods#attribute
24
- # @raise [ScrivitoError] if the +id+ of the corresponding workspace is not +"rtc"+
25
- #
26
- def remove
27
- if Workspace.current.rtc?
28
- Workspace.current.api_request(:delete, '/obj_classes')
29
- else
30
- raise ScrivitoError, 'Scrivito::ObjClass.remove is only allowed in the "rtc" workspace.'
31
- end
32
- end
33
-
34
- # Returns all obj classes.
35
- # @api public
36
- # @deprecated
37
- # @return Scrivito::ObjClassCollection
38
- #
39
- def all
40
- Workspace.current.obj_classes
41
- end
42
-
43
- # Finds an obj class by its name.
44
- #
45
- # @api public
46
- # @deprecated
47
- #
48
- # @example Find the obj class named "Homepage" in the current {Scrivito::Workspace}.
49
- # ObjClass.find('Homepage')
50
- #
51
- # @param [String] name The name of the obj class.
52
- # @return [Scrivito::ObjClass]
53
- # @raise [Scrivito::ResourceNotFound] Raised when no obj class with the given +name+ can be found.
54
- def find(name)
55
- obj_class = Workspace.current.obj_classes[name]
56
-
57
- unless obj_class
58
- raise ResourceNotFound, "Could not find '#{ObjClass}' with name '#{name}'."
59
- end
60
-
61
- obj_class
62
- end
63
-
64
- # Creates a new obj class and persists it in the CMS.
65
- #
66
- # @api public
67
- # @deprecated
68
- #
69
- # This allows you to set the different properties of an obj class by
70
- # providing a hash with the property names as keys and the values you want
71
- # to set as values. Attributes can be either given as {Scrivito::Attribute} instances or as
72
- # an attribute property hash.
73
- #
74
- # @example Create a obj class
75
- # ObjClass.create(name: 'Homepage', attributes: [
76
- # { name: 'title', type: :string },
77
- # { name: 'body', type: :widget }
78
- # ])
79
- #
80
- # @example Create a binary obj class.
81
- # ObjClass.create(name: 'Image', attributes: [
82
- # { name: 'blob', type: :binary }
83
- # ])
84
- #
85
- # @example Create an obj class with attributes passed in as an Array of attribute property hashes.
86
- # ObjClass.create(name: 'Blog', attributes: [
87
- # { name: 'headline', type: :string },
88
- # { name: 'category', type: :enum, values: %w(tech social) },
89
- # ])
90
- #
91
- # @example Create an obj class with attributes passed in as an Array of {Scrivito::Attribute} instances.
92
- # ObjClass.create(name: 'Blog', attributes: [
93
- # Attribute.new(name: 'headline', type: :string),
94
- # Attribute.new(name: 'category', type: :enum, values: %w(tech social)),
95
- # ])
96
- #
97
- # @param [Hash] properties
98
- # @option properties [String] :name The name of the obj class.
99
- # @option properties [Boolean] :is_active Is it possible to create instances of this obj class?
100
- # @option properties [Array<Scrivito::Attribute>, Array<Hash>] :attributes A list of
101
- # attributes for this obj class. Can be either a list of attribute instances or attribute
102
- # property hashes.
103
- #
104
- # @note the +is_binary+ option is deprecated
105
- #
106
- # @return [Scrivito::ObjClass]
107
- def create(properties)
108
- Scrivito.raise_obj_class_deprecated_error
109
- end
110
-
111
- private
112
-
113
- # Formats obj class properties into a CMS REST API format.
114
- # @param [Hash] properties
115
- # @return [Hash] Properties formated for the CMS.
116
- def format_properties_for_cms(properties)
117
- params = properties.dup
118
-
119
- if params.has_key?(:is_binary)
120
- params[:type] = params.delete(:is_binary) ? :generic : :publication
121
- end
122
-
123
- if params.has_key?(:attributes)
124
- params[:attributes] = params[:attributes].map(&:to_cms_rest_api)
125
- end
126
-
127
- params
128
- end
129
- end
130
-
131
- # Initializes a new obj class. It expects the CMS backend representation of an obj class.
132
- #
133
- # See {ObjClass.create} for a detailed overview of how to set properties.
134
- #
135
- # @param [Hash] obj_class_data
136
- # @param [Workspace,NilClass] workspace
137
- # @raise [Scrivito::ScrivitoError]
138
- # @return [Scrivito::ObjClass]
139
- def initialize(obj_class_data, workspace)
140
- update_obj_class_data(obj_class_data)
141
- @workspace = workspace
142
- end
143
-
144
- # @api public
145
- # @deprecated
146
- # Returns true if this ObjClass was created with a +is_binary+ option.
147
- # Creating ObjClass with this option is deprecated and will be removed.
148
- #
149
- # @return [Boolean]
150
- def legacy_type?
151
- !!obj_class_data.type
152
- end
153
-
154
- # @!attribute [r] id
155
- # @api public
156
- # @deprecated
157
- # @return [String] unique identifier of this obj class
158
- # @!attribute [r] name
159
- # @api public
160
- # @deprecated
161
- # @return [String] the name of this obj class
162
- # @!attribute [r] is_active
163
- # @api public
164
- # @deprecated
165
- # @return [Boolean] whether instances can be created with this obj class
166
- delegate :id, :name, :is_active, to: :obj_class_data
167
-
168
- # @api public
169
- # @deprecated
170
- # @return [Boolean] whether instances of this class are binary, e.g. images or PDFs
171
- # @deprecated Please create objects without using the +is_binary+ option
172
- # @raise [ScrivitoError] if the method is called on a non-legacy-type ObjClass
173
- def is_binary
174
- if legacy_type?
175
- obj_class_data.is_binary
176
- else
177
- raise ScrivitoError,
178
- %(`is_binary' and `binary?' can only be called on ObjClasses with a legacy_type.)
179
- end
180
- end
181
-
182
- alias_method :active?, :is_active
183
- alias_method :binary?, :is_binary
184
-
185
- # @api public
186
- # @deprecated
187
- # @return [Scrivito::AttributeCollection] the attributes of this obj class.
188
- #
189
- # @example Find an attribute named "locale" for the obj class "Homepage".
190
- # ObjClass.find('Homepage').attributes['locale']
191
- #
192
- # @example Add a new +string+ attribute named "headline" to the "Homepage" obj class by providing an attribute property hash.
193
- # ObjClass.find('Homepage').attributes.add(name: 'headline', type: :string)
194
- #
195
- # @example Add a new +enum+ attribute named "category" to the "Homepage" obj class by providing an attribute instance.
196
- # attribute = Attribute.new(name: 'category', type: :enum, values: %w(tech social))
197
- # ObjClass.find('Homepage').attributes.add(attribute)
198
- #
199
- # @example Iterate over the list of attributes from the obj class "Homepage" and print their name and type.
200
- # ObjClass.find('Homepage').attributes.each do |attribute|
201
- # puts "#{attribute.name}:#{attribute.type}"
202
- # end
203
- attr_reader :attributes
204
-
205
- # @api public
206
- # @deprecated
207
- # Updates this obj class and persists the changes in the CMS. It is not possible to
208
- # update the +name+.
209
- #
210
- # See {Scrivito::ObjClass.create} for a detailed overview of
211
- # what properties are allowed and how to set them.
212
- #
213
- # The +is_binary+ option can only be removed. By passing +nil+ for the
214
- # +is_binary+ option to update, you can convert legacy objects. This conversion
215
- # removes the fields +title+, +body+ (if +is_binary+ was +false+) or +blob+ (if
216
- # +is_binary+ was +true+). If you add the fields in the same request the values
217
- # will be kept for all objs.
218
- #
219
- # @example Removing +is_binary+ but keeping the previously predefined fields
220
- # ObjClass.find('Homepage').update(is_binary: nil, attributes: [
221
- # {name: 'title', type: 'string'},
222
- # {name: 'body', type: 'html'}
223
- # ])
224
- #
225
- # # Binary ObjClass
226
- # ObjClass.find('Image').update(is_binary: nil, attributes: [
227
- # {name: 'title', type: 'string'},
228
- # {name: 'blob', type: 'binary'}
229
- # ])
230
- #
231
- # @param [Hash] properties
232
- #
233
- # @raise [ScrivitoError] Raised when trying to change +name+ or +is_binary+.
234
- #
235
- # @return [nil]
236
- def update(properties)
237
- Scrivito.raise_obj_class_deprecated_error
238
- end
239
-
240
- def update_obj_class_data(obj_class_data)
241
- @obj_class_data = obj_class_data
242
- update_attributes
243
- end
244
-
245
- private
246
-
247
- attr_reader :obj_class_data, :workspace
248
-
249
- def update_attributes
250
- attributes = @obj_class_data.attributes.map do |attribute_data|
251
- attribute = Attribute.new(attribute_data)
252
- attribute.obj_class = self
253
- attribute
254
- end
255
- @attributes = AttributeCollection.new(self, attributes)
256
- end
257
- end
258
- end
@@ -1,71 +0,0 @@
1
- module Scrivito
2
- # This class allows you to retrieve obj classes from a specific working copy. It behaves almost
3
- # exactly as an Array, so methods like +#each+, +#select+ etc. are available. You can get an
4
- # instance by accessing {Workspace#obj_classes}.
5
- #
6
- # @api public
7
- # @deprecated
8
- class ObjClassCollection
9
- include Enumerable
10
-
11
- # Initializes an obj class collection for a workspace.
12
- #
13
- # @param [Workspace] workspace
14
- # @return [ObjClassCollection]
15
- def initialize(workspace)
16
- @workspace = workspace
17
- end
18
-
19
- # Finds an obj class by its name in the working copy of the collection.
20
- #
21
- # @api public
22
- # @deprecated
23
- #
24
- # @example Find the obj class named "Homepage" in the "rtc" {Workspace}.
25
- # Workspace.find('rtc').obj_classes['Homepage']
26
- #
27
- # @param [String] name The name of the obj class.
28
- # @return [ObjClass, nil] Returns the obj class or nil when no obj class with the given +name+ can be found in the working copy.
29
- def [](name)
30
- if obj_class_data = CmsBackend.instance.find_obj_class_data_by_name(workspace.revision, name)
31
- ObjClass.new(obj_class_data, workspace)
32
- end
33
- end
34
-
35
- #
36
- # @!method each
37
- #
38
- # Yields successive obj classes of the collection. Implements the +Enumerable+ interface.
39
- #
40
- # @api public
41
- # @deprecated
42
- # @see Scrivito::ObjClass.remove
43
- #
44
- # @yield [ObjClass] successive obj classes of the collection if the corresponding workspace
45
- # still uses {Scrivito::ObjClass}.
46
- # @yield [Array] an empty array if the corresponding workspace does not use {Scrivito::ObjClass}
47
- # anymore.
48
- #
49
- # @example Find all obj classes in the "rtc" {Workspace} and print their name.
50
- # Workspace.find('rtc').obj_classes.each do |obj_class|
51
- # puts obj_class.name
52
- # end
53
- #
54
- delegate :each, to: :obj_classes
55
-
56
- private
57
-
58
- def obj_classes
59
- if workspace.uses_obj_classes
60
- CmsBackend.instance.find_all_obj_class_data(workspace.revision).map do |obj_class_data|
61
- ObjClass.new(obj_class_data, workspace)
62
- end
63
- else
64
- Scrivito.print_obj_class_deprecated_warning
65
- []
66
- end
67
- end
68
-
69
- attr_reader :workspace
70
- end
71
- end