scrivito_sdk 0.70.2 → 0.71.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/binary_redirect_controller.rb +12 -9
  3. data/app/controllers/scrivito/blobs_controller.rb +1 -2
  4. data/app/controllers/scrivito/objs_controller.rb +16 -0
  5. data/app/helpers/scrivito_helper.rb +6 -2
  6. data/app/views/cms/index.html.erb +1 -1
  7. data/app/views/scrivito/blobs/activate_upload.json.jbuilder +1 -0
  8. data/app/views/scrivito/objs/obj.json.jbuilder +1 -1
  9. data/app/views/scrivito/objs/transfer_modifications.json.jbuilder +6 -0
  10. data/config/ca-bundle.crt +128 -81
  11. data/config/precedence_routes.rb +1 -0
  12. data/lib/assets/images/scrivito/source_invalid.png +0 -0
  13. data/lib/assets/images/scrivito/source_too_large.png +0 -0
  14. data/lib/assets/images/scrivito/source_type_invalid.png +0 -0
  15. data/lib/assets/javascripts/scrivito_ui.js +1043 -645
  16. data/lib/assets/stylesheets/scrivito.css +1 -1
  17. data/lib/assets/stylesheets/scrivito_ui.css +1 -1
  18. data/lib/generators/scrivito/page/templates/thumbnail.html.erb +1 -1
  19. data/lib/scrivito/attribute_content.rb +54 -17
  20. data/lib/scrivito/attribute_deserializer.rb +1 -1
  21. data/lib/scrivito/attribute_serializer.rb +6 -4
  22. data/lib/scrivito/backend/obj_query.rb +11 -2
  23. data/lib/scrivito/base_widget_tag.rb +77 -0
  24. data/lib/scrivito/basic_obj.rb +67 -67
  25. data/lib/scrivito/basic_widget.rb +11 -6
  26. data/lib/scrivito/binary.rb +50 -5
  27. data/lib/scrivito/binary_param_verifier.rb +4 -5
  28. data/lib/scrivito/client_attribute_serializer.rb +3 -3
  29. data/lib/scrivito/cms_backend.rb +12 -0
  30. data/lib/scrivito/cms_field_tag.rb +8 -6
  31. data/lib/scrivito/cms_rest_api.rb +28 -8
  32. data/lib/scrivito/cms_rest_api/rate_limit.rb +1 -0
  33. data/lib/scrivito/cms_routing.rb +7 -1
  34. data/lib/scrivito/configuration.rb +1 -1
  35. data/lib/scrivito/controller_actions.rb +38 -35
  36. data/lib/scrivito/date_attribute.rb +3 -7
  37. data/lib/scrivito/editing_context.rb +3 -3
  38. data/lib/scrivito/editing_context_middleware.rb +3 -3
  39. data/lib/scrivito/errored_widget_tag.rb +34 -0
  40. data/lib/scrivito/errors.rb +6 -0
  41. data/lib/scrivito/future_binary.rb +23 -0
  42. data/lib/scrivito/link_parser.rb +12 -1
  43. data/lib/scrivito/membership_collection.rb +8 -8
  44. data/lib/scrivito/obj_collection.rb +2 -2
  45. data/lib/scrivito/obj_create_params_parser.rb +2 -2
  46. data/lib/scrivito/obj_params_parser.rb +5 -1
  47. data/lib/scrivito/obj_search_builder.rb +2 -12
  48. data/lib/scrivito/obj_search_enumerator.rb +48 -43
  49. data/lib/scrivito/page_config.rb +2 -1
  50. data/lib/scrivito/type_computer.rb +6 -6
  51. data/lib/scrivito/user.rb +9 -10
  52. data/lib/scrivito/user_definition.rb +2 -2
  53. data/lib/scrivito/warning.rb +17 -0
  54. data/lib/scrivito/widget_garbage_collection.rb +1 -1
  55. data/lib/scrivito/widget_tag.rb +28 -53
  56. data/lib/scrivito/workspace.rb +32 -23
  57. metadata +10 -6
  58. data/app/views/scrivito/objs/copy_widget.html.erb +0 -1
  59. data/app/views/scrivito/objs/create_widget.html.erb +0 -1
@@ -23,11 +23,12 @@ class PageConfig < Struct.new(:obj, :editing_context, :lookup_context)
23
23
  return {} unless obj
24
24
  {
25
25
  id: obj.id,
26
- obj_class_name: obj.obj_class_name,
26
+ obj_class: obj.obj_class,
27
27
  has_children: obj.children.any?,
28
28
  has_conflict: obj.has_conflict?,
29
29
  has_details_view: obj_has_details_view?,
30
30
  modification: modification(obj),
31
+ parent_path: obj.parent_path,
31
32
  restriction_messages: editor.restriction_messages_for(obj),
32
33
  }
33
34
  end
@@ -5,12 +5,12 @@ class TypeComputer
5
5
  @base_class, @fallback_class = base_class, fallback_class
6
6
  end
7
7
 
8
- def compute_type(obj_class_name)
9
- load_class(obj_class_name) || @fallback_class
8
+ def compute_type(obj_class)
9
+ load_class(obj_class) || @fallback_class
10
10
  end
11
11
 
12
- def compute_type_without_fallback(obj_class_name)
13
- if obj_class = load_class(obj_class_name)
12
+ def compute_type_without_fallback(obj_class)
13
+ if obj_class = load_class(obj_class)
14
14
  obj_class
15
15
  else
16
16
  raise ObjClassNotFound
@@ -23,8 +23,8 @@ class TypeComputer
23
23
 
24
24
  private
25
25
 
26
- def load_class(obj_class_name)
27
- klass = obj_class_name.constantize
26
+ def load_class(obj_class)
27
+ klass = obj_class.constantize
28
28
  klass if inherits_from_base?(klass)
29
29
  rescue NameError
30
30
  end
@@ -52,8 +52,8 @@ module Scrivito
52
52
  # user_definition.can_never(:create, :workspace, 'You are not allowed to create workspaces.')
53
53
  # user_definition.can_always(:read, :workspace)
54
54
  #
55
- # user_definition.restrict_obj_publish(using: :_obj_class_name) do |obj_class_name|
56
- # if obj_class_name == 'BlogPost'
55
+ # user_definition.restrict_obj_publish(using: :_obj_class) do |obj_class|
56
+ # if obj_class == 'BlogPost'
57
57
  # false
58
58
  # else
59
59
  # 'You are not allowed to publish blog posts.'
@@ -155,7 +155,7 @@ module Scrivito
155
155
  # Checks whether the User may publish changes to a specific {Scrivito::BasicObj Obj}.
156
156
  #
157
157
  # @api public
158
- # @param [BasicObj] obj the object to be published
158
+ # @param [Scrivito::BasicObj] obj the object to be published
159
159
  # @return [Boolean] true if the user is allowed to publish the object, otherwise false
160
160
  #
161
161
  def can_publish?(obj)
@@ -164,11 +164,11 @@ module Scrivito
164
164
 
165
165
  #
166
166
  # Checks whether the User may publish changes to an {Scrivito::BasicObj Obj} and returns
167
- # the message specified in a {UserDefinition#restrict_obj_publish} callback if they may not.
168
- # If the user may publish the CMS object, an empty array is returned.
167
+ # the message specified in a {Scrivito::UserDefinition#restrict_obj_publish} callback if they
168
+ # may not. If the user may publish the CMS object, an empty array is returned.
169
169
  #
170
170
  # @api public
171
- # @param [BasicObj] obj the object to be published
171
+ # @param [Scrivito::BasicObj] obj the object to be published
172
172
  # @return [Array<String>] Hints on why the user cannot publish the object
173
173
  #
174
174
  def restriction_messages_for(obj)
@@ -236,10 +236,9 @@ module Scrivito
236
236
  def sandbox_suggest_user_proc(input)
237
237
  suggest_users_proc.call(input)
238
238
  rescue Exception => e
239
- Rails.logger.error(%{
240
- Method `suggest_users' of the user "#{id}" raised an error on input "#{input}": #{e}
241
- #{e.backtrace.join("\n")}
242
- })
239
+ message = %{Method `suggest_users' of the user "#{id}" raised an error on input "#{input}"}
240
+ Warning.error(message, e)
241
+
243
242
  nil
244
243
  end
245
244
  end
@@ -185,8 +185,8 @@ module Scrivito
185
185
  # end
186
186
  # end
187
187
  #
188
- # user.restrict_obj_publish(using: :_obj_class_name) do |obj_class_name|
189
- # if obj_class_name == 'BlogPost'
188
+ # user.restrict_obj_publish(using: :_obj_class) do |obj_class|
189
+ # if obj_class == 'BlogPost'
190
190
  # false
191
191
  # else
192
192
  # 'You are only allowed to edit Blog Posts.'
@@ -0,0 +1,17 @@
1
+ module Scrivito
2
+ module Warning
3
+ def self.warn(message)
4
+ Rails.logger.warn("[Scrivito] WARNING! #{message}")
5
+ end
6
+
7
+ def self.error(message, exception=nil)
8
+ if exception
9
+ padded_backtrace = exception.backtrace.map { |line| " #{line}" }
10
+
11
+ message += ": #{exception.class.to_s} (#{exception})\n#{padded_backtrace.join("\n")}"
12
+ end
13
+
14
+ Rails.logger.error("[Scrivito] ERROR! #{message}")
15
+ end
16
+ end
17
+ end
@@ -2,7 +2,7 @@ module Scrivito
2
2
 
3
3
  class WidgetGarbageCollection
4
4
 
5
- # @param [BasicObj] obj the Obj that the update applies to
5
+ # @param [Scrivito::BasicObj] obj the Obj that the update applies to
6
6
  # @param [Hash] update the keys are content objects (Obj or Widget)
7
7
  # and the values are their update params.
8
8
  # update params are accepted in the same format as accepted by Obj.create or Obj#update.
@@ -1,83 +1,58 @@
1
1
  module Scrivito
2
2
 
3
- class WidgetTag < Struct.new(:view, :widget, :placement_modification, :template_name, :inner_tag)
4
- DEFAULT_TAG = "div"
5
-
6
- include TagRenderer
7
-
3
+ class WidgetTag < BaseWidgetTag
8
4
  def render
9
5
  super
10
6
  rescue => error
11
- if !['development', 'test'].include?(Rails.env) &&
12
- view.controller.respond_to?(:on_scrivito_widget_error)
13
- view.controller.on_scrivito_widget_error(widget, error)
7
+ if handle_render_errors?
8
+ errored_widget_tag(error).render
14
9
  else
15
10
  raise error
16
11
  end
17
12
  end
18
13
 
19
- def tag_name
20
- inner_tag || DEFAULT_TAG
21
- end
22
-
23
14
  def content
24
- view.render(template: template_path, locals: {widget: widget})
25
- rescue ActionView::MissingTemplate
26
- raise if Rails.env.development? || Rails.env.test?
27
- "Missing show template for #{widget.description_for_editor}" if view.scrivito_user
15
+ render_content(render_context)
28
16
  end
29
17
 
30
- def options
31
- options = {}
32
-
33
- if inplace_editing_allowed?
34
- options['private-widget-id'] = widget.id
35
- options['widget-obj-class'] = widget.obj_class_name
36
- options['private-widget-description-for-editor'] = widget.description_for_editor
18
+ private
37
19
 
38
- if has_widget_details_view?(widget)
39
- options['private-widget-has-details-view'] = true
40
- end
20
+ def errored_widget_tag(error)
21
+ ErroredWidgetTag.new(view, widget, placement_modification: placement_modification,
22
+ render_context: render_context, inner_tag: inner_tag, error: error)
23
+ end
41
24
 
42
- comparison = editing_context.comparison
43
- options['private-widget-modification'] =
44
- if comparison.revision == widget.revision
45
- if placement_modification
46
- unless widget.in_revision(Workspace.current.revision)
47
- Modification::DELETED
48
- end
49
- end
50
- else
51
- comparison.modification(widget)
52
- end
25
+ def description_for_editor
26
+ widget.description_for_editor
27
+ end
53
28
 
54
- options['private-widget-placement-modification'] =
55
- placement_modification
29
+ def render_content(context)
30
+ template_path = widget.public_send("#{context}_view_path")
31
+ view.render(template: template_path, locals: {widget: widget})
32
+ rescue ActionView::MissingTemplate
33
+ if context == DEFAULT_RENDER_CONTEXT
34
+ if view.scrivito_user
35
+ view.content_tag(:h4, "Error: Missing 'show' template for #{widget.obj_class}",
36
+ class: 'scrivito_error')
37
+ end
38
+ else
39
+ render_content(DEFAULT_RENDER_CONTEXT)
56
40
  end
57
-
58
- options
59
41
  end
60
42
 
61
- private
62
-
63
- def template_path
64
- widget.public_send("to_#{template_name}_view_path")
43
+ def render_context
44
+ super || DEFAULT_RENDER_CONTEXT
65
45
  end
66
46
 
67
47
  def has_widget_details_view?(widget)
68
- view.lookup_context.find(widget.to_details_view_path).present?
48
+ view.lookup_context.find(widget.details_view_path).present?
69
49
  rescue ActionView::MissingTemplate
70
50
  false
71
51
  end
72
52
 
73
- def inplace_editing_allowed?
74
- editing_context.authenticated_editor?
53
+ def handle_render_errors?
54
+ !Rails.env.development? && !Rails.env.test?
75
55
  end
76
-
77
- def editing_context
78
- EditingContextMiddleware.from_request(view.request)
79
- end
80
-
81
56
  end
82
57
 
83
58
  end
@@ -92,34 +92,34 @@ class Workspace
92
92
  all.detect { |workspace| workspace.title == title }
93
93
  end
94
94
 
95
+ #
95
96
  # Find a workspace by its id or title and set it as the currently used workspace.
96
- # @example
97
- # Scrivito::Workspace.use('6a75fe694eeeb093')
98
97
  #
99
- # Scrivito::Workspace.current.id
100
- # # => '6a75fe694eeeb093'
98
+ # @api public
101
99
  #
102
- # Scrivito::Workspace.use('my working copy')
100
+ # @param [String] id_or_title id or title of the workspace
101
+ # @raise [Scrivito::ResourceNotFound]
102
+ # @return [void]
103
103
  #
104
+ # @example
105
+ # Scrivito::Workspace.use("6a75fe694eeeb093")
106
+ # Scrivito::Workspace.current.id
107
+ # # => "6a75fe694eeeb093"
108
+ #
109
+ # Scrivito::Workspace.use("my working copy")
104
110
  # Scrivito::Workspace.current.title
105
- # # => 'my working copy'
111
+ # # => "my working copy"
106
112
  #
107
113
  # # raises Scrivito::ResourceNotFound:
108
- # Scrivito::Workspace.use('missing')
109
- # @api public
110
- # @param [String] id_or_title
111
- # @return [void]
112
- # @raise [Scrivito::ResourceNotFound]
114
+ # Scrivito::Workspace.use("missing")
115
+ #
113
116
  def self.use(id_or_title)
114
- workspace = begin
117
+ self.current = if id_or_title =~ /^[a-z0-9]{16}$/
115
118
  find(id_or_title)
116
- rescue ResourceNotFound
117
- find_by_title(id_or_title)
118
- end
119
- if workspace.blank?
120
- raise(ResourceNotFound, "Could not find #{self} with id or title #{id_or_title}")
119
+ else
120
+ find_by_title(id_or_title) or
121
+ raise ResourceNotFound, "Could not find #{self} with title #{id_or_title}"
121
122
  end
122
- self.current = workspace
123
123
  end
124
124
 
125
125
  delegate :content_state_id, :base_content_state_id, :content_state,
@@ -170,6 +170,14 @@ class Workspace
170
170
  response
171
171
  end
172
172
 
173
+ def create_obj(attributes)
174
+ CmsBackend.instance.create_obj(id, attributes).tap { reload }
175
+ end
176
+
177
+ def update_obj(obj_id, attributes)
178
+ CmsBackend.instance.update_obj(id, obj_id, attributes).tap { reload }
179
+ end
180
+
173
181
  def task_unaware_api_request(verb, path, payload = nil)
174
182
  CmsRestApi.task_unaware_request(verb, "#{backend_url}#{path}", payload)
175
183
  end
@@ -231,7 +239,7 @@ class Workspace
231
239
 
232
240
  # @api public
233
241
  # Returns the memberships (users and their roles) of this workspace.
234
- # @return [MembershipCollection]
242
+ # @return [Scrivito::MembershipCollection]
235
243
  def memberships
236
244
  @memberships ||= MembershipCollection.new(self)
237
245
  end
@@ -289,9 +297,9 @@ class Workspace
289
297
  raise ScrivitoError, 'published workspace is not modifiable' if published?
290
298
  end
291
299
 
292
- # Returns an {ObjCollection} of this working copy for accessing its CMS objects.
300
+ # Returns an {Scrivito::ObjCollection} of this working copy for accessing its CMS objects.
293
301
  # @api public
294
- # @return {ObjCollection}
302
+ # @return {Scrivito::ObjCollection}
295
303
  def objs
296
304
  @objs ||= ObjCollection.new(self)
297
305
  end
@@ -355,12 +363,13 @@ class Workspace
355
363
  end
356
364
 
357
365
  def warn_backend_not_available(error_message)
358
- message = <<-EOS
366
+ Warning.warn <<-EOS
367
+
359
368
  Couldn't connect to backend to fetch published workspace.
360
369
  #{error_message}
361
370
  Serving from cache.
371
+
362
372
  EOS
363
- Rails.logger.warn(message)
364
373
  end
365
374
  end
366
375
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.70.2
4
+ version: 0.71.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infopark AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -172,11 +172,10 @@ files:
172
172
  - app/views/cms/index.html.erb
173
173
  - app/views/google_maps_widget/show.html.erb
174
174
  - app/views/scrivito/_editing_auth_warning.html.erb
175
+ - app/views/scrivito/blobs/activate_upload.json.jbuilder
175
176
  - app/views/scrivito/blobs/upload_permission.json.jbuilder
176
177
  - app/views/scrivito/content_widget/show.html.erb
177
178
  - app/views/scrivito/fallback_thumbnail.html.erb
178
- - app/views/scrivito/objs/copy_widget.html.erb
179
- - app/views/scrivito/objs/create_widget.html.erb
180
179
  - app/views/scrivito/objs/destroy.json.jbuilder
181
180
  - app/views/scrivito/objs/format_missing_error.json.jbuilder
182
181
  - app/views/scrivito/objs/is_outdated.json.jbuilder
@@ -185,6 +184,7 @@ files:
185
184
  - app/views/scrivito/objs/search.json.jbuilder
186
185
  - app/views/scrivito/objs/search_only_size.json.jbuilder
187
186
  - app/views/scrivito/objs/show.json.jbuilder
187
+ - app/views/scrivito/objs/transfer_modifications.json.jbuilder
188
188
  - app/views/scrivito/objs/update.json.jbuilder
189
189
  - app/views/scrivito/objs/widget.json.jbuilder
190
190
  - app/views/scrivito/objs/widget_class_selection.json.jbuilder
@@ -273,6 +273,7 @@ files:
273
273
  - lib/scrivito/backend/path_index.rb
274
274
  - lib/scrivito/backend/permalink_index.rb
275
275
  - lib/scrivito/backend_error.rb
276
+ - lib/scrivito/base_widget_tag.rb
276
277
  - lib/scrivito/basic_obj.rb
277
278
  - lib/scrivito/basic_widget.rb
278
279
  - lib/scrivito/binary.rb
@@ -317,7 +318,9 @@ files:
317
318
  - lib/scrivito/diff.rb
318
319
  - lib/scrivito/editing_context.rb
319
320
  - lib/scrivito/editing_context_middleware.rb
321
+ - lib/scrivito/errored_widget_tag.rb
320
322
  - lib/scrivito/errors.rb
323
+ - lib/scrivito/future_binary.rb
321
324
  - lib/scrivito/gem_info.rb
322
325
  - lib/scrivito/generator_helper.rb
323
326
  - lib/scrivito/html_string.rb
@@ -366,6 +369,7 @@ files:
366
369
  - lib/scrivito/uploaded_binary.rb
367
370
  - lib/scrivito/user.rb
368
371
  - lib/scrivito/user_definition.rb
372
+ - lib/scrivito/warning.rb
369
373
  - lib/scrivito/widget_collection.rb
370
374
  - lib/scrivito/widget_garbage_collection.rb
371
375
  - lib/scrivito/widget_tag.rb
@@ -393,9 +397,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
393
397
  version: 2.1.0
394
398
  required_rubygems_version: !ruby/object:Gem::Requirement
395
399
  requirements:
396
- - - ">="
400
+ - - ">"
397
401
  - !ruby/object:Gem::Version
398
- version: '0'
402
+ version: 1.3.1
399
403
  requirements: []
400
404
  rubyforge_project:
401
405
  rubygems_version: 2.4.5
@@ -1 +0,0 @@
1
- <%= Scrivito::WidgetTag.new(self, @widget).render %>
@@ -1 +0,0 @@
1
- <%= Scrivito::WidgetTag.new(self, @widget).render %>