scrivito_sdk 1.6.1 → 1.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,23 +6,24 @@ module Scrivito
6
6
  include Scrivito::ControllerHelper
7
7
 
8
8
  def process(action)
9
- CmsEnv.new(env).load
9
+ CmsEnv.new(request.env).load
10
10
 
11
11
  if obj_not_found? && editing_context.workspace_changed?
12
12
  redirect_to "/"
13
13
  return self.response
14
14
  end
15
15
 
16
- controller = target_controller(env)
17
- env["action_dispatch.request.path_parameters"]["controller"] = controller.controller_path
16
+ controller = target_controller(request.env)
17
+ request.env["action_dispatch.request.path_parameters"]["controller"] =
18
+ controller.controller_path
18
19
 
19
20
  if !obj_not_found? && action == 'index'
20
21
  action = loaded_obj.controller_action_name
21
22
  end
22
23
 
23
- env["action_dispatch.request.path_parameters"]["action"] = action
24
+ request.env["action_dispatch.request.path_parameters"]["action"] = action
24
25
 
25
- self.response = controller.action(action).call(env)
26
+ self.response = controller.action(action).call(request.env)
26
27
  end
27
28
 
28
29
  private
@@ -53,7 +54,7 @@ module Scrivito
53
54
  end
54
55
 
55
56
  def loaded_obj
56
- env[CmsEnv::OBJ_ENV_KEY]
57
+ request.env[CmsEnv::OBJ_ENV_KEY]
57
58
  end
58
59
 
59
60
  def obj_not_found?
@@ -16,15 +16,17 @@ module ControllerActions
16
16
  extend ActiveSupport::Concern
17
17
 
18
18
  included do
19
- before_filter :require_authenticated_editor, only: [
19
+ before_action :require_authenticated_editor, only: [
20
20
  :show_widget,
21
21
  :widget_details,
22
22
  :page_details,
23
23
  ]
24
24
 
25
- before_filter :load_object
25
+ before_action :load_object
26
26
 
27
- hide_action :on_scrivito_widget_error
27
+ if LegacySwitch.rails4?
28
+ hide_action :on_scrivito_widget_error
29
+ end
28
30
 
29
31
  helper :scrivito
30
32
  end
@@ -44,7 +46,7 @@ module ControllerActions
44
46
  widget = load_widget
45
47
  widget_tag = Scrivito::WidgetTag.new(view_context, widget,
46
48
  render_context: params[:template_name], inner_tag: params[:inner_tag])
47
- render text: widget_tag.render, layout: false
49
+ render plain: widget_tag.render, layout: false
48
50
  end
49
51
 
50
52
  def widget_details
@@ -168,7 +170,7 @@ module ControllerActions
168
170
  binary_routing = BinaryRouting.new(request, scrivito_engine)
169
171
  redirect_to binary_routing.resolved_binary_obj_url(@obj, binary)
170
172
  else
171
- render text: 'Empty Blob', status: 404
173
+ render plain: 'Empty Blob', status: 404
172
174
  end
173
175
  end
174
176
 
@@ -0,0 +1,7 @@
1
+ module Scrivito
2
+ module LegacySwitch
3
+ def self.rails4?
4
+ Rails::VERSION::MAJOR == 4
5
+ end
6
+ end
7
+ end
@@ -230,6 +230,21 @@ module Scrivito
230
230
  # fields, and boost parameters requested, as well as the number of words in a free text
231
231
  # search.
232
232
  #
233
+ # == Concurrent changes
234
+ #
235
+ # Please be aware that concurrent changes can change the search result and
236
+ # can yield incomplete results. This is due to the fact, that search results are lazily loaded in
237
+ # batches. If you want to modify the result of a search, please call +to_a+ first.
238
+ #
239
+ # @example Concurrent changes
240
+ # # bad example
241
+ # books = Book.where(:price, :equals, 10.99)
242
+ # books.map { |book| book.update(price: 9.99) }
243
+ #
244
+ # # good example
245
+ # books = Book.where(:price, :equals, 10.99).to_a
246
+ # books.map { |book| book.update(price: 9.99) }
247
+ #
233
248
  # @api public
234
249
  class ObjSearchEnumerator
235
250
  INVALID_NEGATED_OPERATORS = [:contains, :contains_prefix].freeze
@@ -475,7 +490,7 @@ module Scrivito
475
490
  # @param [String] attribute the name of an attribute.
476
491
  # @param [Hash] options the options to facet a request with.
477
492
  # @option options [Integer] :limit maximum number of unique values to return.
478
- # Defaults to +20+.
493
+ # Defaults to +10+.
479
494
  # @option options [Integer] :include_objs maximum number of Objs to fetch for
480
495
  # each unique value. Defaults to +0+.
481
496
  # @return [Array<Scrivito::ObjFacetValue>] A list of unique values that were found for the
@@ -5,7 +5,7 @@ require 'net/http/post/multipart'
5
5
 
6
6
  module ::Scrivito
7
7
  class SdkEngine < Rails::Engine
8
- config.to_prepare do
8
+ def self.to_prepare
9
9
  Scrivito::Configuration.to_prepare
10
10
 
11
11
  unless Rails.application.config.cache_classes
@@ -13,11 +13,17 @@ module ::Scrivito
13
13
  end
14
14
  end
15
15
 
16
+ if Scrivito::LegacySwitch.rails4?
17
+ config.to_prepare { SdkEngine.to_prepare }
18
+ else
19
+ ActiveSupport::Reloader.to_prepare { SdkEngine.to_prepare }
20
+ end
21
+
16
22
  # make sure our exceptions cause an adequate error page and http status code
17
23
  config.action_dispatch.rescue_responses.merge!("Scrivito::ResourceNotFound" => :not_found)
18
24
 
19
25
  initializer "scrivito.add_cms_routing_paths", :after => :add_routing_paths do |app|
20
- precedence_route = File.expand_path("precedence_routes.rb", paths['config'].to_a.first)
26
+ precedence_route = root.join('config', 'precedence_routes.rb').to_s
21
27
  app.routes_reloader.paths.unshift(precedence_route)
22
28
  end
23
29
 
@@ -51,17 +57,18 @@ module ::Scrivito
51
57
  scrivito_ui_redirect.js
52
58
  scrivito_ui.css
53
59
  scrivito_ui.js
54
- scrivito_sdk.js
60
+ scrivito_with_js_sdk.js
55
61
  ]
56
62
  app.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
57
63
  end
58
64
 
59
65
  config.autoload_paths += paths['lib'].to_a
60
66
  config.autoload_once_paths += paths['lib'].to_a
67
+ config.eager_load_paths += [root.join('lib', 'scrivito').to_s]
61
68
 
62
- config.app_middleware.use "Scrivito::EditingContextMiddleware"
63
- config.app_middleware.use "Scrivito::CacheMiddleware"
64
- config.app_middleware.use "Scrivito::WorkspaceSelectionMiddleware"
69
+ config.app_middleware.use Scrivito::EditingContextMiddleware
70
+ config.app_middleware.use Scrivito::CacheMiddleware
71
+ config.app_middleware.use Scrivito::WorkspaceSelectionMiddleware
65
72
  end
66
73
  end
67
74
 
@@ -26,15 +26,33 @@ module Scrivito
26
26
  # end
27
27
  # end
28
28
  #
29
- def for_scrivito_obj(test_obj = nil)
29
+ def for_scrivito_obj(test_obj = nil, routes = nil)
30
30
  env[Scrivito::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj
31
31
 
32
+ unless Scrivito::LegacySwitch.rails4?
33
+ # If +assign_parameters+ is monkey patched, then +generate_extras+ also needs to
34
+ # be monkey patched. See [1] for details.
35
+ #
36
+ # [1] https://github.com/rails/rails/commit/f6232a518bb7377948f339d2b0b25dc607e1e42a
37
+ class << (routes || Rails.application.routes)
38
+ def generate_extras(options, recall={})
39
+ super options, recall
40
+ rescue *ROUTING_ERRORS => e
41
+ begin
42
+ super options.merge(controller: 'scrivito/cms_dispatch'), recall
43
+ rescue *ROUTING_ERRORS
44
+ raise e
45
+ end
46
+ end
47
+ end
48
+ end
49
+
32
50
  class << self
33
- def assign_parameters(routes, controller_path, action, parameters = {})
34
- super routes, controller_path, action, parameters
51
+ def assign_parameters(routes, controller_path, *args)
52
+ super routes, controller_path, *args
35
53
  rescue *ROUTING_ERRORS => e
36
54
  begin
37
- super routes, 'scrivito/cms_dispatch', action, parameters
55
+ super routes, 'scrivito/cms_dispatch', *args
38
56
  rescue *ROUTING_ERRORS
39
57
  raise e
40
58
  end
@@ -10,7 +10,6 @@ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extens
10
10
  {
11
11
  app_extension_tags: app_extension_tags,
12
12
  editing_context: editing_context_config,
13
- session: session_config,
14
13
  backend_endpoint: Configuration.endpoint,
15
14
  tenant: Configuration.tenant,
16
15
  i18n: i18n_config,
@@ -34,10 +33,6 @@ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extens
34
33
  }
35
34
  end
36
35
 
37
- def session_config
38
- Session.renew(SecureRandom.hex(8), editor)
39
- end
40
-
41
36
  def workspace_config(workspace)
42
37
  {
43
38
  id: workspace.id,
@@ -18,12 +18,6 @@ class WorkspaceSelectionMiddleware
18
18
 
19
19
  @app.call(env)
20
20
  end
21
-
22
- private
23
-
24
- def session(env)
25
- env[Rack::Session::Abstract::ENV_SESSION_KEY]
26
- end
27
21
  end
28
22
 
29
23
  end # module Scrivito
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: 1.6.1
4
+ version: 1.7.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: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 1.7.7
89
+ version: 1.8.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 1.7.7
96
+ version: 1.8.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: memoist
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,22 @@ dependencies:
140
140
  name: rails
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 4.2.0
145
+ version: '4.2'
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: '5.1'
146
149
  type: :runtime
147
150
  prerelease: false
148
151
  version_requirements: !ruby/object:Gem::Requirement
149
152
  requirements:
150
- - - "~>"
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '4.2'
156
+ - - "<"
151
157
  - !ruby/object:Gem::Version
152
- version: 4.2.0
158
+ version: '5.1'
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: rake
155
161
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +220,6 @@ files:
214
220
  - app/views/scrivito/users/publish_ability.json.jbuilder
215
221
  - app/views/scrivito/users/users.json.jbuilder
216
222
  - app/views/scrivito/webservice/_workspace.json.jbuilder
217
- - app/views/scrivito/webservice/empty.json
218
223
  - app/views/scrivito/webservice/error.json.jbuilder
219
224
  - app/views/scrivito/webservice/workspaces.json.jbuilder
220
225
  - app/views/scrivito/workspaces/check.json.jbuilder
@@ -235,8 +240,8 @@ files:
235
240
  - lib/assets/images/scrivito/source_too_large.png
236
241
  - lib/assets/images/scrivito/source_type_invalid.png
237
242
  - lib/assets/javascripts/scrivito.js
238
- - lib/assets/javascripts/scrivito_sdk.js
239
243
  - lib/assets/javascripts/scrivito_ui_redirect.js
244
+ - lib/assets/javascripts/scrivito_with_js_sdk.js
240
245
  - lib/assets/stylesheets/scrivito.css
241
246
  - lib/generators/scrivito/install/install_generator.rb
242
247
  - lib/generators/scrivito/install/templates/app/controllers/cms_controller.rb
@@ -347,6 +352,7 @@ files:
347
352
  - lib/scrivito/image_tag.rb
348
353
  - lib/scrivito/integer_conversion.rb
349
354
  - lib/scrivito/layout_tags.rb
355
+ - lib/scrivito/legacy_switch.rb
350
356
  - lib/scrivito/link.rb
351
357
  - lib/scrivito/link_parser.rb
352
358
  - lib/scrivito/log_subscriber.rb
@@ -387,7 +393,6 @@ files:
387
393
  - lib/scrivito/route.rb
388
394
  - lib/scrivito/routing_extensions.rb
389
395
  - lib/scrivito/sdk_engine.rb
390
- - lib/scrivito/session.rb
391
396
  - lib/scrivito/string_tagging.rb
392
397
  - lib/scrivito/tag_renderer.rb
393
398
  - lib/scrivito/task.rb
@@ -423,12 +428,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
423
428
  version: 2.1.0
424
429
  required_rubygems_version: !ruby/object:Gem::Requirement
425
430
  requirements:
426
- - - ">="
431
+ - - ">"
427
432
  - !ruby/object:Gem::Version
428
- version: '0'
433
+ version: 1.3.1
429
434
  requirements: []
430
435
  rubyforge_project:
431
- rubygems_version: 2.4.5
436
+ rubygems_version: 2.4.8
432
437
  signing_key:
433
438
  specification_version: 4
434
439
  summary: SDK for the Scrivito CMS
@@ -1,23 +0,0 @@
1
- module Scrivito
2
- class Session
3
- def self.renew(id, user)
4
- payload = {
5
- session: {
6
- role: 'editor',
7
- user_id: user.id,
8
- permissions: permissions(user),
9
- },
10
- }
11
-
12
- CmsRestApi.task_unaware_request(:put, "sessions/#{id}", payload)
13
- end
14
-
15
- def self.permissions(user)
16
- Hash[user.explicit_rules.map do |permission, verb, _, _|
17
- [verb, permission.to_s]
18
- end]
19
- end
20
-
21
- private_class_method :permissions
22
- end
23
- end