scrivito_sdk 1.9.1 → 1.10.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/obj_class_controller.rb +12 -3
  3. data/app/controllers/scrivito/users_controller.rb +11 -0
  4. data/app/helpers/scrivito_helper.rb +4 -4
  5. data/config/ca-bundle.crt +1 -1
  6. data/lib/assets/javascripts/scrivito.js +12 -12
  7. data/lib/assets/javascripts/scrivito_ui_redirect.js +2 -2
  8. data/lib/assets/javascripts/scrivito_with_js_sdk.js +20123 -19370
  9. data/lib/assets/stylesheets/scrivito.css +1 -1
  10. data/lib/scrivito/attribute_content.rb +25 -15
  11. data/lib/scrivito/attribute_serializer.rb +3 -1
  12. data/lib/scrivito/backend/obj_load.rb +1 -5
  13. data/lib/scrivito/backend/obj_query.rb +2 -6
  14. data/lib/scrivito/backend/parent_path_index.rb +4 -7
  15. data/lib/scrivito/backend/path_index.rb +5 -8
  16. data/lib/scrivito/backend/permalink_index.rb +4 -7
  17. data/lib/scrivito/basic_obj.rb +70 -67
  18. data/lib/scrivito/basic_widget.rb +1 -0
  19. data/lib/scrivito/binary.rb +17 -2
  20. data/lib/scrivito/binary_param_verifier.rb +30 -34
  21. data/lib/scrivito/client_error.rb +2 -0
  22. data/lib/scrivito/cms_data_cache.rb +71 -73
  23. data/lib/scrivito/cms_rest_api.rb +114 -118
  24. data/lib/scrivito/cms_rest_api/rate_limit.rb +21 -26
  25. data/lib/scrivito/cms_routing.rb +1 -1
  26. data/lib/scrivito/configuration.rb +412 -373
  27. data/lib/scrivito/connection_manager.rb +42 -36
  28. data/lib/scrivito/deprecation.rb +11 -15
  29. data/lib/scrivito/diff.rb +6 -8
  30. data/lib/scrivito/gem_info.rb +9 -6
  31. data/lib/scrivito/generator_helper.rb +5 -7
  32. data/lib/scrivito/migrations/cms_backend.rb +11 -8
  33. data/lib/scrivito/migrations/migrator.rb +19 -21
  34. data/lib/scrivito/obj_search_enumerator.rb +24 -24
  35. data/lib/scrivito/request_homepage.rb +10 -14
  36. data/lib/scrivito/route.rb +27 -31
  37. data/lib/scrivito/sdk_engine.rb +8 -4
  38. data/lib/scrivito/tag_renderer.rb +17 -23
  39. data/lib/scrivito/test_request.rb +7 -9
  40. data/lib/scrivito/ui_config.rb +0 -19
  41. data/lib/scrivito/user.rb +89 -99
  42. data/lib/scrivito/workspace.rb +12 -16
  43. data/lib/scrivito/workspace_data.rb +2 -6
  44. data/lib/scrivito_sdk.rb +0 -13
  45. data/lib/tasks/cache.rake +2 -0
  46. metadata +18 -4
@@ -2,6 +2,7 @@ require 'rails'
2
2
 
3
3
  require 'jbuilder'
4
4
  require 'net/http/post/multipart'
5
+ require_relative './legacy_switch'
5
6
 
6
7
  module ::Scrivito
7
8
  class SdkEngine < Rails::Engine
@@ -62,14 +63,17 @@ module ::Scrivito
62
63
  app.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
63
64
  end
64
65
 
66
+ initializer 'scrivito.add_middlewares' do |app|
67
+ config.app_middleware.use Scrivito::EditingContextMiddleware
68
+ config.app_middleware.use Scrivito::CacheMiddleware
69
+ config.app_middleware.use Scrivito::WorkspaceSelectionMiddleware
70
+ config.app_middleware.use Scrivito::DisableBrowserCacheForUiMiddleware
71
+ end
72
+
65
73
  config.autoload_paths += paths['lib'].to_a
66
74
  config.autoload_once_paths += paths['lib'].to_a
67
75
  config.eager_load_paths += [root.join('lib', 'scrivito').to_s]
68
76
 
69
- config.app_middleware.use Scrivito::EditingContextMiddleware
70
- config.app_middleware.use Scrivito::CacheMiddleware
71
- config.app_middleware.use Scrivito::WorkspaceSelectionMiddleware
72
- config.app_middleware.use Scrivito::DisableBrowserCacheForUiMiddleware
73
77
  end
74
78
  end
75
79
 
@@ -13,33 +13,27 @@ module TagRenderer
13
13
  {}
14
14
  end
15
15
 
16
- class << self
17
-
18
- def render(view, tag, given_options, &block)
19
- content = tag.content(&block)
20
- tag_name = tag.tag_name
21
- options = given_options
22
- .merge(tag.html_options)
23
- .merge(formatted_options(tag))
24
-
25
- if VOID_TAGS.include?(tag_name.to_s)
26
- view.tag(tag_name, options)
27
- else
28
- view.content_tag(tag_name, content, options)
29
- end
16
+ def self.render(view, tag, given_options, &block)
17
+ content = tag.content(&block)
18
+ tag_name = tag.tag_name
19
+ options = given_options
20
+ .merge(tag.html_options)
21
+ .merge(formatted_options(tag))
22
+
23
+ if VOID_TAGS.include?(tag_name.to_s)
24
+ view.tag(tag_name, options)
25
+ else
26
+ view.content_tag(tag_name, content, options)
30
27
  end
28
+ end
31
29
 
32
- private
33
-
34
- def formatted_options(tag)
35
- formatted_options = {}
36
- tag.options.each do |key, value|
37
- formatted_options["data-scrivito-#{key}"] = value
38
- end
39
-
40
- formatted_options
30
+ private_class_method def self.formatted_options(tag)
31
+ formatted_options = {}
32
+ tag.options.each do |key, value|
33
+ formatted_options["data-scrivito-#{key}"] = value
41
34
  end
42
35
 
36
+ formatted_options
43
37
  end
44
38
 
45
39
  end
@@ -47,15 +47,13 @@ module Scrivito
47
47
  end
48
48
  end
49
49
 
50
- class << self
51
- def assign_parameters(routes, controller_path, *args)
52
- super routes, controller_path, *args
53
- rescue *ROUTING_ERRORS => e
54
- begin
55
- super routes, 'scrivito/cms_dispatch', *args
56
- rescue *ROUTING_ERRORS
57
- raise e
58
- end
50
+ def self.assign_parameters(routes, controller_path, *args)
51
+ super routes, controller_path, *args
52
+ rescue *ROUTING_ERRORS => e
53
+ begin
54
+ super routes, 'scrivito/cms_dispatch', *args
55
+ rescue *ROUTING_ERRORS
56
+ raise e
59
57
  end
60
58
  end
61
59
  end
@@ -14,8 +14,6 @@ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extens
14
14
  i18n: i18n_config,
15
15
  is_development_mode: Rails.env.development?,
16
16
  resource_dialog: resource_dialog_config,
17
- user: user_config,
18
- user_permissions: user_permissions_config,
19
17
  class_datas: obj_class_config + widget_class_config,
20
18
  useRailsEngine: true,
21
19
  }.to_json
@@ -47,23 +45,6 @@ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extens
47
45
  }
48
46
  end
49
47
 
50
- def user_permissions_config
51
- {
52
- create_workspace: editor.can?(:create, :workspace),
53
- rename_workspace: editor.can?(:write, selected_workspace),
54
- invite_to_workspace: editor.can?(:invite_to, selected_workspace),
55
- rebase_workspace: editor.can?(:write, selected_workspace),
56
- delete_workspace: editor.can?(:delete, selected_workspace),
57
- publish_workspace: editor.can?(:publish, selected_workspace),
58
- }
59
- end
60
-
61
- def user_config
62
- {
63
- current: editor.as_json,
64
- }
65
- end
66
-
67
48
  def editor
68
49
  editing_context.editor
69
50
  end
data/lib/scrivito/user.rb CHANGED
@@ -31,108 +31,103 @@ module Scrivito
31
31
  :read_history,
32
32
  ].freeze
33
33
 
34
- class << self
35
- #
36
- # Defines a new user.
37
- #
38
- # @api public
39
- #
40
- # @param [String] id The unique, unalterable id of the user.
41
- # The user id is used to associate the user with the corresponding CMS resources.
42
- # It is persisted in the CMS.
43
- #
44
- # @raise [Scrivito::ScrivitoError] if id is blank
45
- # @raise [Scrivito::ScrivitoError] if id is more than 64 characters long
46
- #
47
- # @yieldparam [Scrivito::UserDefinition] user object to define rules on
48
- #
49
- # @see Scrivito::UserDefinition#can_always
50
- # @see Scrivito::UserDefinition#can_never
51
- # @see Scrivito::UserDefinition#description
52
- # @see Scrivito::UserDefinition#restrict_obj_publish
53
- # @see Scrivito::UserDefinition#suggest_users
54
- #
55
- # @example
56
- # Scrivito::User.define('alice') do |user_definition|
57
- # user_definition.description { 'Alice Almighty' }
58
- #
59
- # user_definition.can_always(:read, :workspace)
60
- # user_definition.can_always(:write, :workspace)
61
- # user_definition.can_always(:publish, :workspace, 'You can always publish workspaces.')
62
- # end
63
- #
64
- # Scrivito::User.define('bob') do |user_definition|
65
- # user_definition.description('Bob Doe')
66
- #
67
- # user_definition.can_never(:create, :workspace, 'You are not allowed to create workspaces.')
68
- # user_definition.can_always(:read, :workspace)
69
- #
70
- # user_definition.restrict_obj_publish(using: :_obj_class) do |obj_class|
71
- # if obj_class == 'BlogPost'
72
- # false
73
- # else
74
- # 'You are not allowed to publish blog posts.'
75
- # end
76
- # end
77
- # end
78
- #
79
- def define(id, &block)
80
- assert_valid_id(id)
81
- define_user(id, &block)
82
- end
83
-
84
- #
85
- # Returns an anonymous system user who can always create workspaces, can always read, write,
86
- # publish, delete, and invite others to collaborate on any workspace.
87
- # @example Check whether the user may publish a particular object:
88
- # Scrivito::User.system_user.can_publish?(Obj.root)
89
- # # => true
90
- #
91
- # @example Get the notification messages for publishing restrictions. An empty array indicates that no restrictions exist.
92
- # Scrivito::User.system_user.restriction_messages_for(Obj.root)
93
- # # => []
94
- #
95
- # @api public
96
- # @return [Scrivito::User] the system user
97
- #
98
- def system_user
99
- define_user { |user| user.is_admin! }
100
- end
34
+ # Defines a new user.
35
+ #
36
+ # @api public
37
+ #
38
+ # @param [String] id The unique, unalterable id of the user.
39
+ # The user id is used to associate the user with the corresponding CMS resources.
40
+ # It is persisted in the CMS.
41
+ #
42
+ # @raise [Scrivito::ScrivitoError] if id is blank
43
+ # @raise [Scrivito::ScrivitoError] if id is more than 64 characters long
44
+ #
45
+ # @yieldparam [Scrivito::UserDefinition] user object to define rules on
46
+ #
47
+ # @see Scrivito::UserDefinition#can_always
48
+ # @see Scrivito::UserDefinition#can_never
49
+ # @see Scrivito::UserDefinition#description
50
+ # @see Scrivito::UserDefinition#restrict_obj_publish
51
+ # @see Scrivito::UserDefinition#suggest_users
52
+ #
53
+ # @example
54
+ # Scrivito::User.define('alice') do |user_definition|
55
+ # user_definition.description { 'Alice Almighty' }
56
+ #
57
+ # user_definition.can_always(:read, :workspace)
58
+ # user_definition.can_always(:write, :workspace)
59
+ # user_definition.can_always(:publish, :workspace, 'You can always publish workspaces.')
60
+ # end
61
+ #
62
+ # Scrivito::User.define('bob') do |user_definition|
63
+ # user_definition.description('Bob Doe')
64
+ #
65
+ # user_definition.can_never(:create, :workspace, 'You are not allowed to create workspaces.')
66
+ # user_definition.can_always(:read, :workspace)
67
+ #
68
+ # user_definition.restrict_obj_publish(using: :_obj_class) do |obj_class|
69
+ # if obj_class == 'BlogPost'
70
+ # false
71
+ # else
72
+ # 'You are not allowed to publish blog posts.'
73
+ # end
74
+ # end
75
+ # end
76
+ #
77
+ def self.define(id, &block)
78
+ assert_valid_id(id)
79
+ define_user(id, &block)
80
+ end
101
81
 
102
- def unknown_user(id)
103
- new(id: id, explicit_rules: {})
104
- end
82
+ #
83
+ # Returns an anonymous system user who can always create workspaces, can always read, write,
84
+ # publish, delete, and invite others to collaborate on any workspace.
85
+ # @example Check whether the user may publish a particular object:
86
+ # Scrivito::User.system_user.can_publish?(Obj.root)
87
+ # # => true
88
+ #
89
+ # @example Get the notification messages for publishing restrictions. An empty array indicates that no restrictions exist.
90
+ # Scrivito::User.system_user.restriction_messages_for(Obj.root)
91
+ # # => []
92
+ #
93
+ # @api public
94
+ # @return [Scrivito::User] the system user
95
+ #
96
+ def self.system_user
97
+ define_user { |user| user.is_admin! }
98
+ end
105
99
 
106
- def find(id)
107
- if Configuration.find_user_proc
108
- user = Scrivito::Configuration.find_user_proc.call(id)
109
- assert_valid_user(user)
110
- user
111
- end
112
- end
100
+ def self.unknown_user(id)
101
+ new(id: id, explicit_rules: {})
102
+ end
113
103
 
114
- def mget(*ids)
115
- ids.map(&method(:find))
104
+ def self.find(id)
105
+ if Configuration.find_user_proc
106
+ user = Scrivito::Configuration.find_user_proc.call(id)
107
+ assert_valid_user(user)
108
+ user
116
109
  end
110
+ end
117
111
 
118
- private
112
+ def self.mget(*ids)
113
+ ids.map(&method(:find))
114
+ end
119
115
 
120
- def define_user(id = nil)
121
- user_definition = UserDefinition.new(id)
122
- yield user_definition if block_given?
123
- user_definition.user
124
- end
116
+ private_class_method def self.define_user(id = nil)
117
+ user_definition = UserDefinition.new(id)
118
+ yield user_definition if block_given?
119
+ user_definition.user
120
+ end
125
121
 
126
- def assert_valid_id(id)
127
- raise ScrivitoError.new('User id must be a string') unless id.to_s == id
128
- raise ScrivitoError.new('User id can not be blank') if id.blank?
129
- raise ScrivitoError.new('User id is too long (max length 64)') if id.length > 64
130
- end
122
+ private_class_method def self.assert_valid_id(id)
123
+ raise ScrivitoError.new('User id must be a string') unless id.to_s == id
124
+ raise ScrivitoError.new('User id can not be blank') if id.blank?
125
+ raise ScrivitoError.new('User id is too long (max length 64)') if id.length > 64
126
+ end
131
127
 
132
- def assert_valid_user(user)
133
- unless user.is_a?(User) || user.nil?
134
- raise ScrivitoError.new("Expected an instance of #{self} or nil, but got #{user.inspect}")
135
- end
128
+ private_class_method def self.assert_valid_user(user)
129
+ unless user.is_a?(User) || user.nil?
130
+ raise ScrivitoError.new("Expected an instance of #{self} or nil, but got #{user.inspect}")
136
131
  end
137
132
  end
138
133
 
@@ -235,7 +230,6 @@ module Scrivito
235
230
  {
236
231
  id: id,
237
232
  description: description,
238
- explicit_rules: explicit_rules_as_json,
239
233
  }
240
234
  end
241
235
 
@@ -263,9 +257,5 @@ module Scrivito
263
257
 
264
258
  nil
265
259
  end
266
-
267
- def explicit_rules_as_json
268
- @explicit_rules.map { |(adverb, verb, _)| "#{adverb}-#{verb}" }
269
- end
270
260
  end
271
261
  end
@@ -385,26 +385,22 @@ class Workspace
385
385
  end
386
386
  end
387
387
 
388
- class << self
389
- private
390
-
391
- def from_workspace_data(id, data)
392
- unless data
393
- raise ResourceNotFound, "Could not find #{self} with id #{id}"
394
- end
395
-
396
- cache[id] = Workspace.new(data)
388
+ private_class_method def self.from_workspace_data(id, data)
389
+ unless data
390
+ raise ResourceNotFound, "Could not find #{self} with id #{id}"
397
391
  end
398
392
 
399
- def warn_backend_not_available(error_message)
400
- Warning.warn <<-EOS
393
+ cache[id] = Workspace.new(data)
394
+ end
401
395
 
402
- Couldn't connect to backend to fetch published workspace.
403
- #{error_message}
404
- Serving from cache.
396
+ private_class_method def self.warn_backend_not_available(error_message)
397
+ Warning.warn <<-EOS
405
398
 
406
- EOS
407
- end
399
+ Couldn't connect to backend to fetch published workspace.
400
+ #{error_message}
401
+ Serving from cache.
402
+
403
+ EOS
408
404
  end
409
405
  end
410
406
 
@@ -1,11 +1,7 @@
1
1
  module Scrivito
2
2
  class WorkspaceData
3
- class << self
4
- private
5
-
6
- def data_attr_reader(attr_name)
7
- define_method(attr_name) { @data[attr_name.to_s] }
8
- end
3
+ private_class_method def self.data_attr_reader(attr_name)
4
+ define_method(attr_name) { @data[attr_name.to_s] }
9
5
  end
10
6
 
11
7
  data_attr_reader :id
data/lib/scrivito_sdk.rb CHANGED
@@ -138,19 +138,6 @@ module Scrivito
138
138
  def self.models
139
139
  @models ||= ModelLibrary.new
140
140
  end
141
-
142
- def self.autoload_all_sources
143
- source_files = Dir.glob(File.expand_path("../scrivito/*.rb", __FILE__)).map do |file|
144
- File.basename(file)
145
- end
146
-
147
- source_files.each do |file|
148
- name = file.gsub(".rb", "")
149
- autoload name.camelcase, "scrivito/#{name}"
150
- end
151
- end
152
-
153
- autoload_all_sources
154
141
  end
155
142
 
156
143
  require 'scrivito/sdk_engine' if defined?(Rails)
data/lib/tasks/cache.rake CHANGED
@@ -1,3 +1,5 @@
1
+ require_relative '../scrivito/cache_garbage_collector'
2
+
1
3
  namespace :scrivito do
2
4
  namespace :cache do
3
5
  desc 'Cap number of cache file inodes at ' \
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.9.1
4
+ version: 1.10.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: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.12.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: multi_json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.9'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.9'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: multipart-post
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -424,9 +438,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
424
438
  version: 2.1.0
425
439
  required_rubygems_version: !ruby/object:Gem::Requirement
426
440
  requirements:
427
- - - ">="
441
+ - - ">"
428
442
  - !ruby/object:Gem::Version
429
- version: '0'
443
+ version: 1.3.1
430
444
  requirements: []
431
445
  rubyforge_project:
432
446
  rubygems_version: 2.4.8