scrivito_sdk 0.50.1 → 0.60.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/objs_controller.rb +25 -21
  3. data/app/controllers/scrivito/ui_controller.rb +1 -1
  4. data/app/controllers/scrivito/webservice_controller.rb +1 -1
  5. data/app/models/scrivito/content_widget.rb +1 -3
  6. data/app/views/cms/index.html.erb +3 -0
  7. data/app/views/scrivito/objs/destroy.json.jbuilder +1 -0
  8. data/app/views/scrivito/objs/show.json.jbuilder +2 -0
  9. data/app/views/scrivito/objs/update.json.jbuilder +1 -1
  10. data/app/views/scrivito/objs/{widget_modification.json.jbuilder → widget.json.jbuilder} +0 -0
  11. data/config/ca-bundle.crt +24 -219
  12. data/config/precedence_routes.rb +60 -0
  13. data/config/routes.rb +13 -46
  14. data/lib/assets/javascripts/scrivito_ui.js +360 -202
  15. data/lib/assets/stylesheets/scrivito_sdk.css +1 -1
  16. data/lib/assets/stylesheets/scrivito_ui.css +1 -1
  17. data/lib/generators/scrivito/install/templates/app/models/download.rb +1 -3
  18. data/lib/generators/scrivito/install/templates/app/models/headline_widget.rb +1 -5
  19. data/lib/generators/scrivito/install/templates/app/models/image.rb +1 -3
  20. data/lib/generators/scrivito/install/templates/app/models/image_widget.rb +1 -5
  21. data/lib/generators/scrivito/install/templates/app/models/page.rb +3 -6
  22. data/lib/generators/scrivito/install/templates/app/models/text_widget.rb +1 -5
  23. data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito_migration.rb +1 -25
  24. data/lib/generators/scrivito/migration/templates/migration.erb +2 -26
  25. data/lib/generators/scrivito/page/page_generator.rb +0 -11
  26. data/lib/generators/scrivito/page/templates/model.erb +3 -7
  27. data/lib/generators/scrivito/widget/widget_generator.rb +0 -11
  28. data/lib/scrivito/attribute.rb +10 -16
  29. data/lib/scrivito/attribute_collection.rb +4 -0
  30. data/lib/scrivito/attribute_content.rb +239 -161
  31. data/lib/scrivito/attribute_definition.rb +16 -10
  32. data/lib/scrivito/attribute_definition_collection.rb +7 -4
  33. data/lib/scrivito/attribute_definition_migrator.rb +1 -3
  34. data/lib/scrivito/attribute_deserializer.rb +111 -0
  35. data/lib/scrivito/attribute_serializer.rb +189 -0
  36. data/lib/scrivito/basic_obj.rb +113 -78
  37. data/lib/scrivito/basic_widget.rb +103 -37
  38. data/lib/scrivito/binary.rb +3 -3
  39. data/lib/scrivito/cache/chainable.rb +10 -4
  40. data/lib/scrivito/cache/file_store.rb +7 -4
  41. data/lib/scrivito/cache/ram_store.rb +1 -1
  42. data/lib/scrivito/class_collection.rb +2 -2
  43. data/lib/scrivito/client_config.rb +7 -6
  44. data/lib/scrivito/cms_backend.rb +2 -2
  45. data/lib/scrivito/cms_field_tag.rb +33 -25
  46. data/lib/scrivito/cms_rest_api/{attribute_serializer.rb → legacy_attribute_serializer.rb} +1 -1
  47. data/lib/scrivito/cms_routing.rb +20 -14
  48. data/lib/scrivito/configuration.rb +1 -1
  49. data/lib/scrivito/controller_actions.rb +12 -4
  50. data/lib/scrivito/date_attribute.rb +8 -0
  51. data/lib/scrivito/diff.rb +1 -1
  52. data/lib/scrivito/editing_context.rb +1 -1
  53. data/lib/scrivito/editing_context_middleware.rb +1 -1
  54. data/lib/scrivito/errors.rb +4 -0
  55. data/lib/scrivito/link_parser.rb +6 -1
  56. data/lib/scrivito/migrations/cms_backend.rb +17 -60
  57. data/lib/scrivito/migrations/migration_store.rb +0 -1
  58. data/lib/scrivito/model_library.rb +6 -6
  59. data/lib/scrivito/obj_class.rb +34 -48
  60. data/lib/scrivito/obj_class_collection.rb +21 -3
  61. data/lib/scrivito/obj_create_params_parser.rb +2 -1
  62. data/lib/scrivito/obj_data.rb +9 -103
  63. data/lib/scrivito/obj_data_from_hash.rb +19 -21
  64. data/lib/scrivito/obj_data_from_service.rb +28 -48
  65. data/lib/scrivito/obj_params_parser.rb +14 -14
  66. data/lib/scrivito/obj_search_enumerator.rb +1 -1
  67. data/lib/scrivito/obj_update_params_parser.rb +2 -2
  68. data/lib/scrivito/restriction_set.rb +1 -1
  69. data/lib/scrivito/sdk_engine.rb +2 -2
  70. data/lib/scrivito/test_request.rb +10 -0
  71. data/lib/scrivito/type_computer.rb +5 -1
  72. data/lib/scrivito/widget_collection.rb +15 -0
  73. data/lib/scrivito/widget_garbage_collection.rb +1 -1
  74. data/lib/scrivito/widget_tag.rb +2 -0
  75. data/lib/scrivito/workspace.rb +2 -1
  76. data/lib/scrivito/workspace_data_from_service.rb +1 -0
  77. data/lib/scrivito_sdk.rb +17 -1
  78. metadata +36 -34
  79. data/app/views/scrivito/objs/modification.json.jbuilder +0 -1
  80. data/config/cms_routes.rb +0 -22
  81. data/lib/generators/scrivito/page/templates/migration.erb +0 -9
  82. data/lib/generators/scrivito/widget/templates/migration.erb +0 -7
@@ -1,6 +1,6 @@
1
1
  module Scrivito
2
2
  class CmsRestApi
3
- module AttributeSerializer
3
+ module LegacyAttributeSerializer
4
4
  class << self
5
5
 
6
6
  def generate_widget_pool_changes(widget_hash)
@@ -73,30 +73,36 @@ class CmsRouting < Struct.new(:request, :main_app)
73
73
  end
74
74
 
75
75
  def path_or_url_for_objs(obj, path_or_url, options = {})
76
+ if editing_context.display_mode == "editing"
77
+ return id_path_or_url_for_objs(obj, path_or_url, options)
78
+ end
79
+
76
80
  permalink = obj.permalink
77
81
  if permalink
78
82
  main_app.public_send("scrivito_permalink_#{path_or_url}", options.merge(:permalink => permalink))
79
83
  elsif obj.homepage?
80
84
  main_app.public_send("scrivito_root_#{path_or_url}", options)
81
- else
82
- if obj.binary? && editing_context.display_mode != "editing"
83
- if obj.binary_url
84
- obj.binary_url
85
- else
86
- LINK_TO_EMPTY_BLOB
87
- end
85
+ elsif obj.binary?
86
+ if obj.binary_url
87
+ obj.binary_url
88
88
  else
89
- main_app.public_send(
90
- "cms_id_#{path_or_url}",
91
- options.merge(
92
- id: obj.id,
93
- slug: obj.slug.presence
94
- )
95
- )
89
+ LINK_TO_EMPTY_BLOB
96
90
  end
91
+ else
92
+ id_path_or_url_for_objs(obj, path_or_url, options)
97
93
  end
98
94
  end
99
95
 
96
+ def id_path_or_url_for_objs(obj, path_or_url, options)
97
+ main_app.public_send(
98
+ "cms_id_#{path_or_url}",
99
+ options.merge(
100
+ id: obj.id,
101
+ slug: obj.slug.presence
102
+ )
103
+ )
104
+ end
105
+
100
106
  def editor_authenticated?
101
107
  editing_context.authenticated_editor?
102
108
  end
@@ -65,7 +65,7 @@ module Scrivito
65
65
  # @example Return a "dummy" {Scrivito::User}
66
66
  # Scrivito.configure do |config|
67
67
  # config.find_user do |user_id|
68
- # Scrivito::User.new(user_id)
68
+ # Scrivito::User.define(user_id)
69
69
  # end
70
70
  # end
71
71
  # @example Find the user with a custom user model and convert it to a {Scrivito::User}
@@ -84,7 +84,7 @@ module ControllerActions
84
84
  end
85
85
 
86
86
  def editing_context
87
- request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new
87
+ EditingContextMiddleware.from_request(request)
88
88
  end
89
89
 
90
90
  delegate :comparison, to: :editing_context
@@ -97,9 +97,17 @@ module ControllerActions
97
97
  end
98
98
 
99
99
  def load_widget
100
- if widget = @obj.widget_from_pool(params[:widget_id])
101
- widget
102
- elsif comparison.active? # The "diff" mode.
100
+ widget = widget_from_current_revision || widget_from_base_revision
101
+ raise ResourceNotFound, "Widget with ID #{params[:widget_id]} not found!" unless widget
102
+ widget
103
+ end
104
+
105
+ def widget_from_current_revision
106
+ @obj.widget_from_pool(params[:widget_id])
107
+ end
108
+
109
+ def widget_from_base_revision
110
+ if comparison.active? # The "diff" mode.
103
111
  @obj.in_revision(editing_context.selected_workspace.base_revision)
104
112
  .widget_from_pool(params[:widget_id])
105
113
  end
@@ -11,6 +11,14 @@ module Scrivito
11
11
  raise "The value is not a valid ISO date time: #{iso_date_time.inspect}"
12
12
  end
13
13
  end
14
+
15
+ def self.serialize(attribute_value)
16
+ attribute_value = case attribute_value
17
+ when Date then attribute_value.to_time
18
+ when Time then attribute_value.to_time.utc
19
+ end
20
+ attribute_value.strftime('%Y%m%d%H%M%S') if attribute_value
21
+ end
14
22
  end
15
23
 
16
24
  end
data/lib/scrivito/diff.rb CHANGED
@@ -7,7 +7,7 @@ class Diff; class << self
7
7
 
8
8
  def for(mode, field_type, old, new)
9
9
  case field_type
10
- when "widget"
10
+ when "widgetlist"
11
11
  ListComparison.for(mode, old || [], new || [])
12
12
  when "html"
13
13
  for_html(mode, old, new)
@@ -20,7 +20,7 @@ class EditingContext
20
20
  if @editor && !@editor.is_a?(Scrivito::User)
21
21
  raise ScrivitoError.new(
22
22
  "The editing auth callback has to return a Scrivito::User or falsy."+
23
- " To upgrade please return Scrivito::User.new(id) and set the permissions" +
23
+ " To upgrade please return Scrivito::User.define(id) and set the permissions" +
24
24
  " of the user. See the documentation for further details."
25
25
  )
26
26
  end
@@ -6,7 +6,7 @@ class EditingContextMiddleware
6
6
  ENVKEY = 'SCRIVITO_EDITING_CONTEXT'
7
7
 
8
8
  def self.from_request(request)
9
- request.env[ENVKEY]
9
+ request.env[ENVKEY] || EditingContext.new
10
10
  end
11
11
 
12
12
  def initialize(app)
@@ -8,4 +8,8 @@ end
8
8
  class ResourceNotFound < ScrivitoError
9
9
  end
10
10
 
11
+ # @api public
12
+ class ObjClassNotFound < ResourceNotFound
13
+ end
14
+
11
15
  end # module Scrivito
@@ -10,7 +10,7 @@ module Scrivito
10
10
  def parse(url)
11
11
  uri = Addressable::URI.parse(url)
12
12
 
13
- if (params = route(uri.to_s)) && params[:controller] == 'scrivito/ui'
13
+ if (params = sdk_route(uri.to_s)) && params[:controller] == 'scrivito/ui'
14
14
  uri.path = params[:application_path]
15
15
  end
16
16
 
@@ -69,6 +69,11 @@ module Scrivito
69
69
  route_params && route_params[:controller] == 'scrivito/cms_dispatch'
70
70
  end
71
71
 
72
+ def sdk_route(uri)
73
+ Scrivito::SdkEngine.routes.recognize_path(uri.to_s, method: :get)
74
+ rescue ActionController::RoutingError
75
+ end
76
+
72
77
  def route(uri)
73
78
  Rails.application.routes.recognize_path(uri.to_s, method: :get)
74
79
  rescue ActionController::RoutingError
@@ -2,67 +2,36 @@ module Scrivito
2
2
  module Migrations
3
3
  class CmsBackend
4
4
  def read
5
- obj = find_migration_store_obj
6
-
7
- if obj
8
- obj[attribute_name]
5
+ if obj = find_migration_store_obj
6
+ obj.data_from_cms.value_of('versions')
9
7
  else
10
- initial_value
8
+ ''
11
9
  end
12
10
  end
13
11
 
14
12
  def save(value)
15
- CmsRestApi.put(
16
- endpoint("objs/#{migration_store_obj.id}"),
17
- :obj => {
18
- attribute_name => value
19
- }
20
- )
13
+ if Workspace.current.uses_obj_classes
14
+ CmsRestApi.put(endpoint("objs/#{migration_store_obj.id}"), obj: {versions: value})
15
+ else
16
+ CmsRestApi.put(endpoint("objs/#{migration_store_obj.id}"),
17
+ obj: {versions: ['string', value]})
18
+ end
21
19
  end
22
20
 
23
21
  private
24
22
 
25
23
  def create
26
- # Create obj class
27
- CmsRestApi.post(
28
- endpoint('obj_classes'),
29
- :obj_class => {
30
- :name => obj_class_name,
31
- :attributes => [
32
- {
33
- :name => attribute_name,
34
- :type => :text,
35
- },
36
- ],
37
- :type => :publication,
38
- :title => obj_class_name,
39
- }
40
- )
41
-
42
- # Create obj
43
- CmsRestApi.post(
44
- endpoint('objs'),
45
- :obj => {
46
- :_path => path,
47
- :_obj_class => obj_class_name,
48
- attribute_name => initial_value,
49
- }
50
- )
51
-
52
- # Deactivate obj class
53
- CmsRestApi.put(
54
- endpoint("obj_classes/#{obj_class_name}"),
55
- :obj_class => {
56
- :is_active => false,
57
- }
58
- )
24
+ if Workspace.current.uses_obj_classes
25
+ CmsRestApi.post(endpoint('objs'),
26
+ obj: {_path: path, _obj_class: 'MigrationStore', versions: ''})
27
+ else
28
+ CmsRestApi.post(endpoint('objs'),
29
+ obj: {_path: path, _obj_class: 'MigrationStore', versions: ['string', '']})
30
+ end
59
31
  end
60
32
 
61
33
  def migration_store_obj
62
- unless find_migration_store_obj
63
- create
64
- end
65
-
34
+ create unless find_migration_store_obj
66
35
  find_migration_store_obj
67
36
  end
68
37
 
@@ -70,22 +39,10 @@ module Scrivito
70
39
  Obj.find_by_path(path)
71
40
  end
72
41
 
73
- def attribute_name
74
- 'versions'
75
- end
76
-
77
- def obj_class_name
78
- 'MigrationStore'
79
- end
80
-
81
42
  def path
82
43
  '/_internal/migration-store'
83
44
  end
84
45
 
85
- def initial_value
86
- ''
87
- end
88
-
89
46
  def endpoint(path)
90
47
  "workspaces/#{Workspace.current.id}/#{path}"
91
48
  end
@@ -15,7 +15,6 @@ module Scrivito
15
15
 
16
16
  def add_version(version)
17
17
  versions << version
18
-
19
18
  backend.save(MultiJson.dump(versions))
20
19
  end
21
20
  end
@@ -1,7 +1,7 @@
1
1
  module Scrivito
2
2
 
3
3
  #
4
- # @api private
4
+ # @api public
5
5
  #
6
6
  class ModelLibrary
7
7
  attr_reader :custom_pages, :custom_widgets, :custom_paths
@@ -13,7 +13,7 @@ class ModelLibrary
13
13
  #
14
14
  # Clears model cache.
15
15
  #
16
- # @api private
16
+ # @api public
17
17
  # @see Scrivito.models
18
18
  #
19
19
  def clear_cache
@@ -25,7 +25,7 @@ class ModelLibrary
25
25
  #
26
26
  # Configures which models Scrivito assumes as pages and widgets.
27
27
  #
28
- # @api private
28
+ # @api public
29
29
  # @see Scrivito.models
30
30
  #
31
31
  def define(&block)
@@ -35,7 +35,7 @@ class ModelLibrary
35
35
  #
36
36
  # Lists available page models.
37
37
  #
38
- # @api private
38
+ # @api public
39
39
  # @see Scrivito.models
40
40
  # @return [Scrivito::ClassCollection] available page classes
41
41
  #
@@ -46,7 +46,7 @@ class ModelLibrary
46
46
  #
47
47
  # Lists available widget models.
48
48
  #
49
- # @api private
49
+ # @api public
50
50
  # @see Scrivito.models
51
51
  # @return [Scrivito::ClassCollection] available widget classes
52
52
  #
@@ -57,7 +57,7 @@ class ModelLibrary
57
57
  #
58
58
  # Lists available paths to scan for models.
59
59
  #
60
- # @api private
60
+ # @api public
61
61
  # @see Scrivito.models
62
62
  # @return [Array<String>] available paths to scan for models.
63
63
  #
@@ -4,13 +4,36 @@ module Scrivito
4
4
  # are defined by {Scrivito::Attribute} instances.
5
5
  #
6
6
  # @api public
7
+ # @deprecated
7
8
  class ObjClass
8
9
  include ModelIdentity
9
10
 
10
11
  class << self
11
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
+
12
34
  # Returns all obj classes.
13
35
  # @api public
36
+ # @deprecated
14
37
  # @return Scrivito::ObjClassCollection
15
38
  #
16
39
  def all
@@ -20,6 +43,7 @@ module Scrivito
20
43
  # Finds an obj class by its name.
21
44
  #
22
45
  # @api public
46
+ # @deprecated
23
47
  #
24
48
  # @example Find the obj class named "Homepage" in the current {Scrivito::Workspace}.
25
49
  # ObjClass.find('Homepage')
@@ -40,6 +64,7 @@ module Scrivito
40
64
  # Creates a new obj class and persists it in the CMS.
41
65
  #
42
66
  # @api public
67
+ # @deprecated
43
68
  #
44
69
  # This allows you to set the different properties of an obj class by
45
70
  # providing a hash with the property names as keys and the values you want
@@ -80,26 +105,7 @@ module Scrivito
80
105
  #
81
106
  # @return [Scrivito::ObjClass]
82
107
  def create(properties)
83
- properties = properties.with_indifferent_access
84
-
85
- if properties.key?(:is_binary)
86
- Scrivito::Deprecation.warn(
87
- "`is_binary' is deprecated and should not be used anymore."\
88
- "Please remove the parameter and specify all attributes you need "\
89
- "including the previously provided attributes 'title', 'body', 'blob'"
90
- )
91
- end
92
-
93
- if properties[:attributes]
94
- properties[:attributes].map! do |attribute|
95
- attribute.respond_to?(:to_cms_rest_api) ? attribute : Attribute.new(attribute)
96
- end
97
- end
98
-
99
- workspace = Workspace.current
100
- raw_obj_class_data = workspace.api_request(:post, '/obj_classes',
101
- obj_class: format_properties_for_cms(properties))
102
- new(ObjClassData.new(raw_obj_class_data), workspace)
108
+ Scrivito.raise_obj_class_deprecated_error
103
109
  end
104
110
 
105
111
  private
@@ -136,6 +142,7 @@ module Scrivito
136
142
  end
137
143
 
138
144
  # @api public
145
+ # @deprecated
139
146
  # Returns true if this ObjClass was created with a +is_binary+ option.
140
147
  # Creating ObjClass with this option is deprecated and will be removed.
141
148
  #
@@ -146,16 +153,20 @@ module Scrivito
146
153
 
147
154
  # @!attribute [r] id
148
155
  # @api public
156
+ # @deprecated
149
157
  # @return [String] unique identifier of this obj class
150
158
  # @!attribute [r] name
151
159
  # @api public
160
+ # @deprecated
152
161
  # @return [String] the name of this obj class
153
162
  # @!attribute [r] is_active
154
163
  # @api public
164
+ # @deprecated
155
165
  # @return [Boolean] whether instances can be created with this obj class
156
166
  delegate :id, :name, :is_active, to: :obj_class_data
157
167
 
158
168
  # @api public
169
+ # @deprecated
159
170
  # @return [Boolean] whether instances of this class are binary, e.g. images or PDFs
160
171
  # @deprecated Please create objects without using the +is_binary+ option
161
172
  # @raise [ScrivitoError] if the method is called on a non-legacy-type ObjClass
@@ -172,6 +183,7 @@ module Scrivito
172
183
  alias_method :binary?, :is_binary
173
184
 
174
185
  # @api public
186
+ # @deprecated
175
187
  # @return [Scrivito::AttributeCollection] the attributes of this obj class.
176
188
  #
177
189
  # @example Find an attribute named "locale" for the obj class "Homepage".
@@ -191,6 +203,7 @@ module Scrivito
191
203
  attr_reader :attributes
192
204
 
193
205
  # @api public
206
+ # @deprecated
194
207
  # Updates this obj class and persists the changes in the CMS. It is not possible to
195
208
  # update the +name+.
196
209
  #
@@ -221,34 +234,7 @@ module Scrivito
221
234
  #
222
235
  # @return [nil]
223
236
  def update(properties)
224
- params = properties.with_indifferent_access
225
-
226
- if params.has_key?(:is_binary)
227
- if params[:is_binary].nil?
228
- params[:type] = params.delete(:is_binary)
229
- else
230
- raise ScrivitoError, "#{self.class} only supports removing the `is_binary' property"
231
- end
232
- end
233
-
234
- if params.has_key?(:name)
235
- raise ScrivitoError, "#{self.class} does not support changing 'name'. Please remove" \
236
- " the key from the properties."
237
- end
238
-
239
- if params.has_key?(:attributes)
240
- params[:attributes].map! do |attribute|
241
- attribute = Attribute.new(attribute) unless attribute.respond_to?(:to_cms_rest_api)
242
- attribute.obj_class = self
243
- attribute.to_cms_rest_api
244
- end
245
- end
246
-
247
- raw_obj_class_data = workspace.api_request(:put, "/obj_classes/#{name}", obj_class: params)
248
- update_obj_class_data(ObjClassData.new(raw_obj_class_data))
249
- workspace.reload
250
-
251
- nil
237
+ Scrivito.raise_obj_class_deprecated_error
252
238
  end
253
239
 
254
240
  def update_obj_class_data(obj_class_data)