scrivito_sdk 1.9.1 → 1.10.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/scrivito/obj_class_controller.rb +12 -3
- data/app/controllers/scrivito/users_controller.rb +11 -0
- data/app/helpers/scrivito_helper.rb +4 -4
- data/config/ca-bundle.crt +1 -1
- data/lib/assets/javascripts/scrivito.js +12 -12
- data/lib/assets/javascripts/scrivito_ui_redirect.js +2 -2
- data/lib/assets/javascripts/scrivito_with_js_sdk.js +20123 -19370
- data/lib/assets/stylesheets/scrivito.css +1 -1
- data/lib/scrivito/attribute_content.rb +25 -15
- data/lib/scrivito/attribute_serializer.rb +3 -1
- data/lib/scrivito/backend/obj_load.rb +1 -5
- data/lib/scrivito/backend/obj_query.rb +2 -6
- data/lib/scrivito/backend/parent_path_index.rb +4 -7
- data/lib/scrivito/backend/path_index.rb +5 -8
- data/lib/scrivito/backend/permalink_index.rb +4 -7
- data/lib/scrivito/basic_obj.rb +70 -67
- data/lib/scrivito/basic_widget.rb +1 -0
- data/lib/scrivito/binary.rb +17 -2
- data/lib/scrivito/binary_param_verifier.rb +30 -34
- data/lib/scrivito/client_error.rb +2 -0
- data/lib/scrivito/cms_data_cache.rb +71 -73
- data/lib/scrivito/cms_rest_api.rb +114 -118
- data/lib/scrivito/cms_rest_api/rate_limit.rb +21 -26
- data/lib/scrivito/cms_routing.rb +1 -1
- data/lib/scrivito/configuration.rb +412 -373
- data/lib/scrivito/connection_manager.rb +42 -36
- data/lib/scrivito/deprecation.rb +11 -15
- data/lib/scrivito/diff.rb +6 -8
- data/lib/scrivito/gem_info.rb +9 -6
- data/lib/scrivito/generator_helper.rb +5 -7
- data/lib/scrivito/migrations/cms_backend.rb +11 -8
- data/lib/scrivito/migrations/migrator.rb +19 -21
- data/lib/scrivito/obj_search_enumerator.rb +24 -24
- data/lib/scrivito/request_homepage.rb +10 -14
- data/lib/scrivito/route.rb +27 -31
- data/lib/scrivito/sdk_engine.rb +8 -4
- data/lib/scrivito/tag_renderer.rb +17 -23
- data/lib/scrivito/test_request.rb +7 -9
- data/lib/scrivito/ui_config.rb +0 -19
- data/lib/scrivito/user.rb +89 -99
- data/lib/scrivito/workspace.rb +12 -16
- data/lib/scrivito/workspace_data.rb +2 -6
- data/lib/scrivito_sdk.rb +0 -13
- data/lib/tasks/cache.rake +2 -0
- metadata +18 -4
@@ -6,54 +6,60 @@ module Scrivito
|
|
6
6
|
|
7
7
|
attr_reader :uri
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
connection.request(request, timeout)
|
13
|
-
end
|
9
|
+
def self.request(request, timeout: nil, uri: nil)
|
10
|
+
connection_pool_for(uri || Configuration.endpoint_uri).with do |connection|
|
11
|
+
connection.request(request, timeout)
|
14
12
|
end
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
# For test purpose only.
|
16
|
+
def self.clear_cache!
|
17
|
+
@connection_pools = nil
|
18
|
+
@cert_store = nil
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
21
|
+
def self.cert_store
|
22
|
+
@cert_store ||= OpenSSL::X509::Store.new.tap do |store|
|
23
|
+
store.set_default_paths
|
24
|
+
store.add_file(Configuration.ca_file)
|
27
25
|
end
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def self.minimum_open_timeout
|
29
|
+
@minimum_open_timeout || 0.5
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def self.minimum_open_timeout=(value)
|
33
|
+
@minimum_open_timeout = value
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def self.minimum_ssl_timeout
|
37
|
+
@minimum_ssl_timeout || 1.0
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def self.minimum_ssl_timeout=(value)
|
41
|
+
@minimum_ssl_timeout = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.minimum_read_timeout
|
45
|
+
@minimum_read_timeout || 0.5
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.minimum_read_timeout=(value)
|
49
|
+
@minimum_read_timeout = value
|
50
|
+
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
52
|
+
def self.connection_pool_for(uri)
|
53
|
+
endpoint_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
|
54
|
+
connection_pools.fetch(endpoint_url) do
|
55
|
+
connection_pools[endpoint_url] = ConnectionPool.new(size: 100, timeout: 0) do
|
56
|
+
new(URI.parse(endpoint_url))
|
51
57
|
end
|
52
58
|
end
|
59
|
+
end
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
61
|
+
def self.connection_pools
|
62
|
+
@connection_pools ||= {}
|
57
63
|
end
|
58
64
|
|
59
65
|
def initialize(uri)
|
data/lib/scrivito/deprecation.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
module Scrivito
|
2
2
|
class Deprecation
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def warn_method(deprecated_method_name, new_method_name = nil)
|
9
|
-
warn(warn_method_message(deprecated_method_name, new_method_name), caller(1))
|
10
|
-
end
|
3
|
+
def self.warn(message, source = caller(1))
|
4
|
+
ActiveSupport::Deprecation.warn(message, source)
|
5
|
+
end
|
11
6
|
|
12
|
-
|
7
|
+
def self.warn_method(deprecated_method_name, new_method_name = nil)
|
8
|
+
warn(warn_method_message(deprecated_method_name, new_method_name), caller(1))
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
11
|
+
private_class_method def self.warn_method_message(deprecated_method_name, new_method_name = nil)
|
12
|
+
message = "The method #{deprecated_method_name} is deprecated and will be removed "\
|
13
|
+
"from the Scrivito SDK in the next major version. "
|
14
|
+
message << "Please use #{new_method_name} instead" if new_method_name
|
15
|
+
message
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
data/lib/scrivito/diff.rb
CHANGED
@@ -3,9 +3,9 @@ require "hyp_diff"
|
|
3
3
|
|
4
4
|
module Scrivito
|
5
5
|
|
6
|
-
class Diff
|
6
|
+
class Diff
|
7
7
|
|
8
|
-
def for(mode, field_type, old, new)
|
8
|
+
def self.for(mode, field_type, old, new)
|
9
9
|
case field_type
|
10
10
|
when "widgetlist"
|
11
11
|
ListComparison.for(mode, old || [], new || [])
|
@@ -16,13 +16,11 @@ class Diff; class << self
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
def for_string(mode, old, new)
|
19
|
+
private_class_method def self.for_string(mode, old, new)
|
22
20
|
for_html(mode, ERB::Util.h(old), ERB::Util.h(new))
|
23
21
|
end
|
24
22
|
|
25
|
-
def for_html(mode, old, new)
|
23
|
+
private_class_method def self.for_html(mode, old, new)
|
26
24
|
return if !old
|
27
25
|
return if !new
|
28
26
|
return unless %w[added deleted diff].include?(mode)
|
@@ -31,7 +29,7 @@ class Diff; class << self
|
|
31
29
|
[StringTagging.tag_as_html(diff)]
|
32
30
|
end
|
33
31
|
|
34
|
-
def hyp_diff_options(mode)
|
32
|
+
private_class_method def self.hyp_diff_options(mode)
|
35
33
|
render_insertion_proc = proc { |html| "<span class='scrivito_insertion'>#{html}</span>" }
|
36
34
|
render_deletion_proc = proc { |html| "<span class='scrivito_deletion'>#{html}</span>" }
|
37
35
|
render_nothing_proc = proc {}
|
@@ -118,6 +116,6 @@ class Diff; class << self
|
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
121
|
-
end
|
119
|
+
end
|
122
120
|
|
123
121
|
end
|
data/lib/scrivito/gem_info.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Scrivito
|
2
2
|
module GemInfo
|
3
|
-
class << self
|
4
|
-
delegate :name, :version, to: :spec
|
5
3
|
|
6
|
-
|
4
|
+
def self.name
|
5
|
+
spec.name
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.version
|
9
|
+
spec.version
|
10
|
+
end
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
12
|
+
private_class_method def self.spec
|
13
|
+
@spec ||= Gem.loaded_specs['scrivito_sdk']
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Scrivito
|
2
2
|
module GeneratorHelper
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
"attribute :#{arg.name}, :#{arg.type}"
|
9
|
-
end
|
3
|
+
def self.attribute_definition(arg)
|
4
|
+
if %w(enum multienum).include?(arg.type.to_s)
|
5
|
+
"attribute :#{arg.name}, :#{arg.type}, values: []"
|
6
|
+
else
|
7
|
+
"attribute :#{arg.name}, :#{arg.type}"
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -10,8 +10,8 @@ module Scrivito
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def save(value)
|
13
|
-
|
14
|
-
obj: {versions: ['string', value]})
|
13
|
+
Workspace.current.update_obj(migration_store_obj.id,
|
14
|
+
{ obj: { versions: ['string', value] } })
|
15
15
|
|
16
16
|
Workspace.current.reload
|
17
17
|
end
|
@@ -19,8 +19,15 @@ module Scrivito
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def create
|
22
|
-
|
23
|
-
|
22
|
+
obj_id = SecureRandom.hex(8)
|
23
|
+
Workspace.current.update_obj(obj_id, {
|
24
|
+
obj: {
|
25
|
+
_id: obj_id,
|
26
|
+
_obj_class: 'MigrationStore',
|
27
|
+
_path: path,
|
28
|
+
versions: ['string', ''],
|
29
|
+
}
|
30
|
+
})
|
24
31
|
|
25
32
|
Workspace.current.reload
|
26
33
|
end
|
@@ -37,10 +44,6 @@ module Scrivito
|
|
37
44
|
def path
|
38
45
|
'/_internal/migration-store'
|
39
46
|
end
|
40
|
-
|
41
|
-
def endpoint(path)
|
42
|
-
"workspaces/#{Workspace.current.id}/#{path}"
|
43
|
-
end
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -1,33 +1,31 @@
|
|
1
1
|
module Scrivito
|
2
2
|
module Migrations
|
3
3
|
class Migrator
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def determine_migrations(paths)
|
10
|
-
paths = Array(paths)
|
11
|
-
files = Dir[*paths.map { |path| "#{path}/**/[0-9]*_*.rb" }]
|
12
|
-
splitter = /([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/
|
13
|
-
|
14
|
-
migrations = files.map do |filename|
|
15
|
-
version, name, scope = filename.scan(splitter).first
|
4
|
+
def self.migrations_path
|
5
|
+
Rails.root + Scrivito::Configuration.migration_path
|
6
|
+
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
def self.determine_migrations(paths)
|
9
|
+
paths = Array(paths)
|
10
|
+
files = Dir[*paths.map { |path| "#{path}/**/[0-9]*_*.rb" }]
|
11
|
+
splitter = /([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/
|
21
12
|
|
22
|
-
|
23
|
-
|
13
|
+
migrations = files.map do |filename|
|
14
|
+
version, name, scope = filename.scan(splitter).first
|
24
15
|
|
25
|
-
|
26
|
-
|
16
|
+
unless version
|
17
|
+
raise ScrivitoError.new("Illegal name for migration file: #{filename}\n\t
|
18
|
+
(only lower case letters, numbers, and '_' allowed)")
|
27
19
|
end
|
28
20
|
|
29
|
-
|
21
|
+
version = version
|
22
|
+
name = name.camelize
|
23
|
+
|
24
|
+
require(File.expand_path(filename))
|
25
|
+
name.constantize.new(name, version, filename, scope)
|
30
26
|
end
|
27
|
+
|
28
|
+
migrations.sort_by(&:version)
|
31
29
|
end
|
32
30
|
|
33
31
|
attr_reader :migrations
|
@@ -248,6 +248,17 @@ module Scrivito
|
|
248
248
|
# @api public
|
249
249
|
class ObjSearchEnumerator
|
250
250
|
INVALID_NEGATED_OPERATORS = [:contains, :contains_prefix].freeze
|
251
|
+
OPERATOR_WHITELIST = [
|
252
|
+
:contains,
|
253
|
+
:contains_prefix,
|
254
|
+
:equals,
|
255
|
+
:starts_with,
|
256
|
+
:is_greater_than,
|
257
|
+
:is_less_than,
|
258
|
+
:links_to,
|
259
|
+
:refers_to,
|
260
|
+
].freeze
|
261
|
+
|
251
262
|
include Enumerable
|
252
263
|
|
253
264
|
attr_reader :workspace
|
@@ -279,11 +290,12 @@ module Scrivito
|
|
279
290
|
# @return [Scrivito::ObjSearchEnumerator]
|
280
291
|
# @api public
|
281
292
|
def and(field, operator, value, boost = nil)
|
282
|
-
|
283
|
-
|
293
|
+
symbolized_operator = ensure_symbol_and_validate_operator(operator)
|
294
|
+
|
295
|
+
subquery = { field: field, operator: symbolized_operator, value: convert_value(value) }
|
284
296
|
if boost.present?
|
285
297
|
valid_boost_operators = [:contains, :contains_prefix]
|
286
|
-
if valid_boost_operators.include?(
|
298
|
+
if valid_boost_operators.include?(symbolized_operator)
|
287
299
|
subquery[:boost] = boost
|
288
300
|
else
|
289
301
|
raise "Boost is not allowed with operator '#{operator}'. " +
|
@@ -315,8 +327,9 @@ module Scrivito
|
|
315
327
|
if INVALID_NEGATED_OPERATORS.include?(operator.to_sym)
|
316
328
|
raise "Negating operator '#{operator}' is not valid."
|
317
329
|
end
|
318
|
-
|
319
|
-
|
330
|
+
symbolized_operator = ensure_symbol_and_validate_operator(operator)
|
331
|
+
|
332
|
+
subquery = { field: field, operator: symbolized_operator, value: convert_value(value),
|
320
333
|
negate: true }
|
321
334
|
reset_for_changed_query
|
322
335
|
@query = (query || []) + [subquery]
|
@@ -657,27 +670,14 @@ module Scrivito
|
|
657
670
|
end
|
658
671
|
end
|
659
672
|
|
660
|
-
def
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
when :contains_prefix
|
665
|
-
:prefix_search
|
666
|
-
when :equals
|
667
|
-
:equal
|
668
|
-
when :starts_with
|
669
|
-
:prefix
|
670
|
-
when :is_greater_than
|
671
|
-
:greater_than
|
672
|
-
when :is_less_than
|
673
|
-
:less_than
|
674
|
-
when :links_to
|
675
|
-
:links_to
|
676
|
-
when :refers_to
|
677
|
-
:refers_to
|
678
|
-
else
|
673
|
+
def ensure_symbol_and_validate_operator(operator)
|
674
|
+
symbolized_operator = operator.to_sym
|
675
|
+
|
676
|
+
unless OPERATOR_WHITELIST.include?(symbolized_operator)
|
679
677
|
raise "Operator '#{operator}' is not valid!"
|
680
678
|
end
|
679
|
+
|
680
|
+
symbolized_operator
|
681
681
|
end
|
682
682
|
|
683
683
|
def search_dsl_params
|
@@ -2,21 +2,17 @@ module Scrivito
|
|
2
2
|
module RequestHomepage
|
3
3
|
HOMEPAGE_ENV_KEY = "SCRIVITO_HOMEPAGE"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
5
|
+
def self.call(env)
|
6
|
+
env[HOMEPAGE_ENV_KEY] ||= fetch_homepage(env)
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
9
|
+
private_class_method def self.fetch_homepage(env)
|
10
|
+
callback_result = Scrivito::Configuration.choose_homepage_callback.call(env)
|
11
|
+
if callback_result.is_a?(Scrivito::BasicObj)
|
12
|
+
callback_result
|
13
|
+
else
|
14
|
+
raise "choose_homepage callback did not return an Obj. "\
|
15
|
+
"Instead saw #{callback_result.class}."
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
data/lib/scrivito/route.rb
CHANGED
@@ -2,47 +2,43 @@ module Scrivito
|
|
2
2
|
|
3
3
|
class Route
|
4
4
|
|
5
|
-
|
6
|
-
VALID_ROUTE_NAMES = %i(homepage slug_id permalink).freeze
|
5
|
+
VALID_ROUTE_NAMES = %i(homepage slug_id permalink).freeze
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def self.register(route_set, name)
|
8
|
+
assert_valid_route_name(name)
|
9
|
+
registry(route_set)[name] = new(name)
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def self.find(given_context, name)
|
13
|
+
available_contexts(given_context).each do |context|
|
14
|
+
route = registry(context._routes)[name]
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
if route && route.defined_in?(context)
|
17
|
+
return route.apply_to(context)
|
20
18
|
end
|
21
|
-
|
22
|
-
nil
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
nil
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
private_class_method def self.registry(route_set)
|
25
|
+
@registry ||= {}
|
26
|
+
@registry[route_set] ||= {}
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
29
|
+
private_class_method def self.assert_valid_route_name(name)
|
30
|
+
unless VALID_ROUTE_NAMES.include?(name)
|
31
|
+
valid_values = VALID_ROUTE_NAMES.join(', ')
|
32
|
+
raise ScrivitoError,
|
33
|
+
%("#{name}" is not a valid scrivito route name. Valid values are: #{valid_values}.)
|
38
34
|
end
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
37
|
+
private_class_method def self.available_contexts(context)
|
38
|
+
[
|
39
|
+
context,
|
40
|
+
context.try(:main_app)
|
41
|
+
].compact
|
46
42
|
end
|
47
43
|
|
48
44
|
def initialize(name)
|