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.
- 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
@@ -1,40 +1,35 @@
|
|
1
1
|
module Scrivito
|
2
2
|
class CmsRestApi
|
3
3
|
module RateLimit
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
4
|
+
def self.retry_on_rate_limit(request_timer, &block)
|
5
|
+
internal_retry(block, request_timer, 0)
|
6
|
+
end
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
private_class_method def self.internal_retry(request_proc, request_timer, retry_count)
|
9
|
+
response = request_proc.call
|
13
10
|
|
14
|
-
|
15
|
-
|
11
|
+
if failed_because_of_rate_limit?(response)
|
12
|
+
time_to_sleep = calculate_time_to_sleep(response['Retry-After'].to_f, retry_count)
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
raise Scrivito::RateLimitExceeded.new('rate limit exceeded', 429)
|
23
|
-
end
|
14
|
+
if request_timer.cover?(Time.now + time_to_sleep.seconds)
|
15
|
+
Warning.warn("Rate limit exceeded. Will retry after #{time_to_sleep} seconds.")
|
16
|
+
sleep time_to_sleep
|
17
|
+
internal_retry(request_proc, request_timer, retry_count + 1)
|
24
18
|
else
|
25
|
-
|
19
|
+
raise Scrivito::RateLimitExceeded.new('rate limit exceeded', 429)
|
26
20
|
end
|
21
|
+
else
|
22
|
+
response
|
27
23
|
end
|
24
|
+
end
|
28
25
|
|
26
|
+
private_class_method def self.calculate_time_to_sleep(retry_after, retry_count)
|
27
|
+
backoff_wait_time = 2 ** retry_count * 0.5
|
28
|
+
[backoff_wait_time, retry_after].max
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
[backoff_wait_time, retry_after].max
|
33
|
-
end
|
34
|
-
|
35
|
-
def failed_because_of_rate_limit?(response)
|
36
|
-
response.code == '429'
|
37
|
-
end
|
31
|
+
private_class_method def self.failed_because_of_rate_limit?(response)
|
32
|
+
response.code == '429'
|
38
33
|
end
|
39
34
|
end
|
40
35
|
end
|
data/lib/scrivito/cms_routing.rb
CHANGED
@@ -50,7 +50,7 @@ class CmsRouting < Struct.new(:request, :context, :scrivito_engine, :image_optio
|
|
50
50
|
def path_or_url_without_editing_context(target, path_or_url, options)
|
51
51
|
if target.is_a?(Link)
|
52
52
|
path_or_url_for_links(target, path_or_url, options)
|
53
|
-
elsif target.is_a?(
|
53
|
+
elsif target.is_a?(Scrivito::BasicObj)
|
54
54
|
path_or_url_for_objs(target, path_or_url, options)
|
55
55
|
elsif target.respond_to?(:first)
|
56
56
|
if target.first.is_a?(Link)
|
@@ -11,425 +11,464 @@ module Scrivito
|
|
11
11
|
#
|
12
12
|
DEFAULT_CA_FILE = File.expand_path('../../../config/ca-bundle.crt', __FILE__)
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# Configures a callback to be invoked when the SDK determines whether current visitor is
|
20
|
-
# permitted to edit content.
|
21
|
-
#
|
22
|
-
# If the callback is missing in the +development+ or +test+ environment, then the SDK will
|
23
|
-
# assume, that the current visitor is {Scrivito::User.system_user}, who can always create
|
24
|
-
# workspaces, can always read, write, publish, delete and invite to any workspace.
|
25
|
-
#
|
26
|
-
# If the callback is missing in any other environment (for example in +production+ or
|
27
|
-
# +staging+), then the SDK will assume, that the current visitor is not permitted to edit
|
28
|
-
# content.
|
29
|
-
#
|
30
|
-
# @api public
|
31
|
-
#
|
32
|
-
# @param [Proc] block proc for detemining if the current visitor is permitted to edit content
|
33
|
-
# @yieldparam [Hash] env rack env
|
34
|
-
# @yieldreturn [Scrivito::User] if the current visitor is permitted to edit content
|
35
|
-
# @yieldreturn [false, nil] if the current visitor is not permitted to edit content
|
36
|
-
#
|
37
|
-
# @example
|
38
|
-
# Scrivito::Configuration.editing_auth do |env|
|
39
|
-
# if user_id = env['USER_ID']
|
40
|
-
# Scrivito::User.define(user_id)
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
def editing_auth(&block)
|
45
|
-
if block.respond_to?(:arity) && block.arity == 1
|
46
|
-
@editing_auth_callback = block
|
47
|
-
else
|
48
|
-
raise ArgumentError, 'editing_auth should have only one attribute!'
|
49
|
-
end
|
50
|
-
end
|
14
|
+
# Determine if current visitor is permitted to edit content.
|
15
|
+
def self.find_user_proc=(value)
|
16
|
+
@find_user_proc = value
|
17
|
+
end
|
51
18
|
|
52
|
-
|
53
|
-
|
54
|
-
|
19
|
+
def self.find_user_proc
|
20
|
+
@find_user_proc
|
21
|
+
end
|
55
22
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
23
|
+
#
|
24
|
+
# Configures a callback to be invoked when the SDK determines whether current visitor is
|
25
|
+
# permitted to edit content.
|
26
|
+
#
|
27
|
+
# If the callback is missing in the +development+ or +test+ environment, then the SDK will
|
28
|
+
# assume, that the current visitor is {Scrivito::User.system_user}, who can always create
|
29
|
+
# workspaces, can always read, write, publish, delete and invite to any workspace.
|
30
|
+
#
|
31
|
+
# If the callback is missing in any other environment (for example in +production+ or
|
32
|
+
# +staging+), then the SDK will assume, that the current visitor is not permitted to edit
|
33
|
+
# content.
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
#
|
37
|
+
# @param [Proc] block proc for detemining if the current visitor is permitted to edit content
|
38
|
+
# @yieldparam [Hash] env rack env
|
39
|
+
# @yieldreturn [Scrivito::User] if the current visitor is permitted to edit content
|
40
|
+
# @yieldreturn [false, nil] if the current visitor is not permitted to edit content
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# Scrivito::Configuration.editing_auth do |env|
|
44
|
+
# if user_id = env['USER_ID']
|
45
|
+
# Scrivito::User.define(user_id)
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
def self.editing_auth(&block)
|
50
|
+
if block.respond_to?(:arity) && block.arity == 1
|
51
|
+
@editing_auth_callback = block
|
52
|
+
else
|
53
|
+
raise ArgumentError, 'editing_auth should have only one attribute!'
|
82
54
|
end
|
55
|
+
end
|
83
56
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# +Scrivito+ makes heavy use of filesystem caching. Use this method to configure the directory
|
88
|
-
# that should be used to store cached data. By default, +RAILS_ROOT/tmp/scrivito_cache+ will
|
89
|
-
# be used.
|
90
|
-
#
|
91
|
-
# @api public
|
92
|
-
#
|
93
|
-
# @param path [String] Path to directory that should be used to store cached data.
|
94
|
-
#
|
95
|
-
# @example Configure +Scrivito+ to store its cache under +/tmp/my_cache+.
|
96
|
-
#
|
97
|
-
# Scrivito.configure do |config|
|
98
|
-
# config.cache_path = '/tmp/my_cache'
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
def cache_path=(path)
|
102
|
-
CmsDataCache.cache_path = path
|
103
|
-
end
|
57
|
+
def self.editing_auth_callback
|
58
|
+
@editing_auth_callback || default_editing_auth_callback
|
59
|
+
end
|
104
60
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
61
|
+
# Configures how to find users for the in-place GUI.
|
62
|
+
# @api public
|
63
|
+
# @param [Proc] find_user_proc proc for finding a user by the user id
|
64
|
+
# @yieldparam [String] user_id id of the user
|
65
|
+
# @yieldreturn [Scrivito::User] if the user with the given user id was found
|
66
|
+
# @yieldreturn [NilClass] if the user with the given user id was not found
|
67
|
+
# @raise [Scrivito::ScrivitoError] if the proc returns neither a {Scrivito::User}, nor +nil+
|
68
|
+
# @note This configuration key is optional. If it is not configured the in-place GUI would
|
69
|
+
# behave normally, but would not be able to find any users.
|
70
|
+
# @example Return a "dummy" {Scrivito::User}
|
71
|
+
# Scrivito.configure do |config|
|
72
|
+
# config.find_user do |user_id|
|
73
|
+
# Scrivito::User.define(user_id)
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
# @example Find the user with a custom user model and convert it to a {Scrivito::User}
|
77
|
+
# Scrivito.configure do |config|
|
78
|
+
# config.find_user do |user_id|
|
79
|
+
# my_user = MyUserModel.find(user_id)
|
80
|
+
# if my_user
|
81
|
+
# my_user.to_scrivito_user
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
def self.find_user(&find_user_proc)
|
86
|
+
self.find_user_proc = find_user_proc
|
87
|
+
end
|
130
88
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
89
|
+
#
|
90
|
+
# Set the path for the filesystem cache.
|
91
|
+
#
|
92
|
+
# +Scrivito+ makes heavy use of filesystem caching. Use this method to configure the directory
|
93
|
+
# that should be used to store cached data. By default, +RAILS_ROOT/tmp/scrivito_cache+ will
|
94
|
+
# be used.
|
95
|
+
#
|
96
|
+
# @api public
|
97
|
+
#
|
98
|
+
# @param path [String] Path to directory that should be used to store cached data.
|
99
|
+
#
|
100
|
+
# @example Configure +Scrivito+ to store its cache under +/tmp/my_cache+.
|
101
|
+
#
|
102
|
+
# Scrivito.configure do |config|
|
103
|
+
# config.cache_path = '/tmp/my_cache'
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
def self.cache_path=(path)
|
107
|
+
CmsDataCache.cache_path = path
|
108
|
+
end
|
141
109
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
# @api public
|
168
|
-
#
|
169
|
-
def minimum_open_timeout=(value)
|
170
|
-
ConnectionManager.minimum_open_timeout = value
|
171
|
-
end
|
110
|
+
#
|
111
|
+
# Sets the second level cache.
|
112
|
+
#
|
113
|
+
# If it is set, then +Scrivito+ will additionaly store its cache in both: the filesystem cache
|
114
|
+
# and the second level cache. Also +Scrivito+ will search in the second level cache if
|
115
|
+
# searching in the filesystem cache returns no results. If the second level cache returns
|
116
|
+
# results, then the results will be store in the filesystem cache.
|
117
|
+
#
|
118
|
+
# By default it is not set.
|
119
|
+
#
|
120
|
+
# @api public
|
121
|
+
#
|
122
|
+
# @param cache_store [ActiveSupport::Cache::Store] cache store to be used as the second level
|
123
|
+
# cache
|
124
|
+
#
|
125
|
+
# @example Use Memcached as the second level cache (https://rubygems.org/gems/dalli)
|
126
|
+
#
|
127
|
+
# Scrivito.configure do |config|
|
128
|
+
# config.second_level_cache = ActiveSupport::Cache::DalliStore.new("localhost",
|
129
|
+
# "server-downstairs.localnetwork:8229")
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
def self.second_level_cache=(cache_store)
|
133
|
+
CmsDataCache.second_level_cache = cache_store
|
134
|
+
end
|
172
135
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
ConnectionManager.minimum_ssl_timeout = value
|
184
|
-
end
|
136
|
+
#
|
137
|
+
# Sets the tenant name.
|
138
|
+
# This configuration key _must_ be provided.
|
139
|
+
#
|
140
|
+
# @api public
|
141
|
+
#
|
142
|
+
def self.tenant=(tenant_name)
|
143
|
+
@endpoint_uri = nil
|
144
|
+
@tenant = tenant_name
|
145
|
+
end
|
185
146
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
def minimum_read_timeout=(value)
|
196
|
-
ConnectionManager.minimum_read_timeout = value
|
197
|
-
end
|
147
|
+
#
|
148
|
+
# Sets the API key.
|
149
|
+
# This configuration key _must_ be provided.
|
150
|
+
#
|
151
|
+
# @api public
|
152
|
+
#
|
153
|
+
def self.api_key=(value)
|
154
|
+
@api_key = value
|
155
|
+
end
|
198
156
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
# e.g. Content Read Service.
|
211
|
-
# @api public
|
212
|
-
def ca_file=(path)
|
213
|
-
if path # Try to read the given file and fail if it doesn't exist or is not readable.
|
214
|
-
File.read(path)
|
215
|
-
end
|
216
|
-
@ca_file = path
|
217
|
-
end
|
157
|
+
#
|
158
|
+
# Sets the API endpoint URL.
|
159
|
+
# This configuration key is optional.
|
160
|
+
# Default is +'api.scrivito.com'+.
|
161
|
+
# If no schema is provided HTTPS is assumed.
|
162
|
+
#
|
163
|
+
# @api public
|
164
|
+
#
|
165
|
+
def self.endpoint=(value)
|
166
|
+
@endpoint = value
|
167
|
+
end
|
218
168
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
169
|
+
#
|
170
|
+
# Sets a minimum
|
171
|
+
# {https://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html#open_timeout-attribute-method
|
172
|
+
# +Net::HTTP#open_timeout+} for endpoint connections.
|
173
|
+
#
|
174
|
+
# Default is +0.5+
|
175
|
+
#
|
176
|
+
# @api public
|
177
|
+
#
|
178
|
+
def self.minimum_open_timeout=(value)
|
179
|
+
ConnectionManager.minimum_open_timeout = value
|
180
|
+
end
|
225
181
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
182
|
+
#
|
183
|
+
# Sets a minimum
|
184
|
+
# {https://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html#ssl_timeout-attribute-method
|
185
|
+
# +Net::HTTP#ssl_timeout+} for endpoint connections.
|
186
|
+
#
|
187
|
+
# Default is +1.0+
|
188
|
+
#
|
189
|
+
# @api public
|
190
|
+
#
|
191
|
+
def self.minimum_ssl_timeout=(value)
|
192
|
+
ConnectionManager.minimum_ssl_timeout = value
|
193
|
+
end
|
231
194
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
195
|
+
#
|
196
|
+
# Sets a minimum
|
197
|
+
# {https://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html#read_timeout-attribute-method
|
198
|
+
# +Net::HTTP#read_timeout+} for endpoint connections.
|
199
|
+
#
|
200
|
+
# Default is +0.5+
|
201
|
+
#
|
202
|
+
# @api public
|
203
|
+
#
|
204
|
+
def self.minimum_read_timeout=(value)
|
205
|
+
ConnectionManager.minimum_read_timeout = value
|
206
|
+
end
|
237
207
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
208
|
+
#
|
209
|
+
# Gets the path of a CA certification file in PEM format.
|
210
|
+
#
|
211
|
+
# @return [String]
|
212
|
+
# @api public
|
213
|
+
#
|
214
|
+
def self.ca_file
|
215
|
+
@ca_file
|
216
|
+
end
|
242
217
|
|
243
|
-
|
244
|
-
|
218
|
+
# Sets path of a CA certification file in PEM format.
|
219
|
+
# The file can contain several CA certificates.
|
220
|
+
# Certifications will be used for endpoint peer verification of various scrivito services
|
221
|
+
# e.g. Content Read Service.
|
222
|
+
# @api public
|
223
|
+
def self.ca_file=(path)
|
224
|
+
if path # Try to read the given file and fail if it doesn't exist or is not readable.
|
225
|
+
File.read(path)
|
245
226
|
end
|
227
|
+
@ca_file = path
|
228
|
+
end
|
246
229
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
self.legacy_routing = false
|
252
|
-
self.default_image_transformation = {}
|
253
|
-
self.choose_homepage_callback = -> (env) { Obj.root }
|
254
|
-
self.find_user_proc = nil
|
255
|
-
self.inject_preset_routes = true
|
256
|
-
@editing_auth_callback = nil
|
230
|
+
def self.to_prepare
|
231
|
+
unless Rails.configuration.cache_classes
|
232
|
+
BasicObj.reset_type_computer!
|
233
|
+
BasicWidget.reset_type_computer!
|
257
234
|
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.tenant
|
238
|
+
tenant = @tenant || ENV['SCRIVITO_TENANT']
|
239
|
+
assert_configuration_key_present(:tenant, tenant)
|
240
|
+
tenant
|
241
|
+
end
|
242
|
+
|
243
|
+
def self.api_key
|
244
|
+
api_key = @api_key || ENV['SCRIVITO_API_KEY']
|
245
|
+
assert_configuration_key_present(:api_key, api_key)
|
246
|
+
api_key
|
247
|
+
end
|
248
|
+
|
249
|
+
def self.endpoint
|
250
|
+
raise 'Missing required configuration key "endpoint"' unless @endpoint
|
251
|
+
@endpoint
|
252
|
+
end
|
253
|
+
|
254
|
+
def self.endpoint_uri
|
255
|
+
@endpoint_uri ||= calculate_endpoint_uri
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.set_defaults!
|
259
|
+
self.ca_file = DEFAULT_CA_FILE
|
260
|
+
self.endpoint = 'api.scrivito.com'
|
261
|
+
self.check_batch_size = 100
|
262
|
+
self.legacy_routing = false
|
263
|
+
self.default_image_transformation = {}
|
264
|
+
self.choose_homepage_callback = -> (env) { Obj.root }
|
265
|
+
self.find_user_proc = nil
|
266
|
+
self.inject_preset_routes = true
|
267
|
+
@editing_auth_callback = nil
|
268
|
+
end
|
269
|
+
|
270
|
+
#
|
271
|
+
# Configures the in-place UI to use a locale different from the one used by the rest of the
|
272
|
+
# application.
|
273
|
+
#
|
274
|
+
# @api public
|
275
|
+
# @example
|
276
|
+
# # The application will use +:de+ as locale.
|
277
|
+
# I18n.locale = :de
|
278
|
+
#
|
279
|
+
# Scrivito.configure do |config|
|
280
|
+
# # But the in-place UI will nevertheless use +:en+.
|
281
|
+
# config.ui_locale = :en
|
282
|
+
# end
|
283
|
+
#
|
284
|
+
def self.ui_locale
|
285
|
+
@ui_locale
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.ui_locale=(value)
|
289
|
+
@ui_locale = value
|
290
|
+
end
|
258
291
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
#
|
273
|
-
attr_accessor :ui_locale
|
274
|
-
|
275
|
-
|
276
|
-
# @api public
|
277
|
-
# @deprecated The legacy routing is deprecated and will be removed in the next major
|
278
|
-
# version of Scrivito.
|
279
|
-
#
|
280
|
-
# Scrivito changed its routing to a slug first url scheme. This configuration option
|
281
|
-
# allows you to switch back to the old id first url scheme.
|
282
|
-
attr_accessor :legacy_routing
|
283
|
-
|
284
|
-
def legacy_routing=(enabled)
|
285
|
-
if enabled
|
286
|
-
Scrivito::Deprecation.warn(%[
|
292
|
+
# @api public
|
293
|
+
# @deprecated The legacy routing is deprecated and will be removed in the next major
|
294
|
+
# version of Scrivito.
|
295
|
+
#
|
296
|
+
# Scrivito changed its routing to a slug first url scheme. This configuration option
|
297
|
+
# allows you to switch back to the old id first url scheme.
|
298
|
+
def self.legacy_routing
|
299
|
+
@legacy_routing
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.legacy_routing=(enabled)
|
303
|
+
if enabled
|
304
|
+
Scrivito::Deprecation.warn(%[
|
287
305
|
The legacy routing is deprecated and will be removed in the next major version of Scrivito.
|
288
306
|
Please use the new scrivito_route api to replicate the legacy routes:
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
end
|
294
|
-
@legacy_routing = enabled
|
307
|
+
scrivito_route '/', using: 'homepage', via: :all
|
308
|
+
scrivito_route '(/):id/*slug', using: 'slug_id', via: :all
|
309
|
+
scrivito_route '/*permalink', using: 'permalink', via: all
|
310
|
+
])
|
295
311
|
end
|
312
|
+
@legacy_routing = enabled
|
313
|
+
end
|
296
314
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
315
|
+
# @api public
|
316
|
+
#
|
317
|
+
# The +inject_preset_routes+ configuration is enabled by default and adds the default
|
318
|
+
# Scrivito routing to your application routes. It can be disabled by setting it to
|
319
|
+
# +false+ which lets you use {RoutingExtensions#scrivito_route scrivito_route} to
|
320
|
+
# customize the routing used by Scrivito.
|
321
|
+
def self.inject_preset_routes=(value)
|
322
|
+
@inject_preset_routes = value
|
323
|
+
end
|
304
324
|
|
305
|
-
|
306
|
-
|
307
|
-
|
325
|
+
def self.inject_preset_routes
|
326
|
+
@inject_preset_routes
|
327
|
+
end
|
308
328
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
self.inject_preset_routes = false
|
313
|
-
yield
|
314
|
-
ensure
|
315
|
-
self.inject_preset_routes = initial_value
|
316
|
-
end
|
317
|
-
end
|
329
|
+
def self.scrivito_route_enabled?
|
330
|
+
inject_preset_routes == false
|
331
|
+
end
|
318
332
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
# When delivering binary Objs, the default image transformation will be applied.
|
327
|
-
#
|
328
|
-
# If not changed the default image transformation is an empty transformation (an empty
|
329
|
-
# +Hash+). Set it to +false+ to disabled the default image transformation completely.
|
330
|
-
#
|
331
|
-
# @param [Hash] value the {Scrivito::Binary#transform transformation definition}
|
332
|
-
#
|
333
|
-
# @see Scrivito::Binary#transform
|
334
|
-
#
|
335
|
-
attr_writer :default_image_transformation
|
336
|
-
|
337
|
-
attr_reader :default_image_transformation
|
338
|
-
|
339
|
-
# @api public
|
340
|
-
#
|
341
|
-
# A callback that can be provided for determining the CMS object to be used when visiting
|
342
|
-
# the homepage. See {Scrivito::RoutingExtensions#scrivito_route scrivito_route} for
|
343
|
-
# details on how to define routes. The callback is called once per request and receives
|
344
|
-
# the rack environment as its only parameter. By default, the CMS object at the root
|
345
|
-
# path (+/+) is used as the homepage.
|
346
|
-
#
|
347
|
-
# @yield Rack environment of the current request
|
348
|
-
#
|
349
|
-
# @example
|
350
|
-
# Scrivito.configure do |config|
|
351
|
-
# config.choose_homepage do |env|
|
352
|
-
# Obj.root # Replace with code to set the homepage
|
353
|
-
# end
|
354
|
-
# end
|
355
|
-
def choose_homepage(&block)
|
356
|
-
self.choose_homepage_callback = block
|
333
|
+
def self.with_scrivito_route_enabled
|
334
|
+
begin
|
335
|
+
initial_value = inject_preset_routes
|
336
|
+
self.inject_preset_routes = false
|
337
|
+
yield
|
338
|
+
ensure
|
339
|
+
self.inject_preset_routes = initial_value
|
357
340
|
end
|
341
|
+
end
|
358
342
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
{
|
363
|
-
id: obj.id,
|
364
|
-
obj_class: obj.obj_class,
|
365
|
-
description_for_editor: obj.description_for_editor,
|
366
|
-
modification: obj.modification,
|
367
|
-
has_conflict: obj.has_conflict?,
|
368
|
-
last_changed: obj.last_changed.utc.iso8601,
|
369
|
-
is_binary: obj.binary?,
|
370
|
-
restriction_messages: user.restriction_messages_for(obj)
|
371
|
-
}
|
372
|
-
end
|
373
|
-
}
|
374
|
-
end
|
343
|
+
def self.choose_homepage_callback=(value)
|
344
|
+
@choose_homepage_callback = value
|
345
|
+
end
|
375
346
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
else
|
380
|
-
obj_formats[name] = block
|
381
|
-
end
|
382
|
-
end
|
347
|
+
def self.choose_homepage_callback
|
348
|
+
@choose_homepage_callback
|
349
|
+
end
|
383
350
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
end
|
351
|
+
def self.check_batch_size=(value)
|
352
|
+
@check_batch_size = value
|
353
|
+
end
|
388
354
|
|
389
|
-
|
390
|
-
|
391
|
-
|
355
|
+
def self.check_batch_size
|
356
|
+
@check_batch_size
|
357
|
+
end
|
392
358
|
|
393
|
-
|
359
|
+
#
|
360
|
+
# Set the default {Scrivito::Binary#transform image transformation}.
|
361
|
+
#
|
362
|
+
# @api public
|
363
|
+
#
|
364
|
+
# When delivering binary Objs, the default image transformation will be applied.
|
365
|
+
#
|
366
|
+
# If not changed the default image transformation is an empty transformation (an empty
|
367
|
+
# +Hash+). Set it to +false+ to disabled the default image transformation completely.
|
368
|
+
#
|
369
|
+
# @param [Hash] value the {Scrivito::Binary#transform transformation definition}
|
370
|
+
#
|
371
|
+
# @see Scrivito::Binary#transform
|
372
|
+
#
|
373
|
+
def self.default_image_transformation=(value)
|
374
|
+
@default_image_transformation = value
|
375
|
+
end
|
376
|
+
|
377
|
+
def self.default_image_transformation
|
378
|
+
@default_image_transformation
|
379
|
+
end
|
394
380
|
|
395
|
-
|
396
|
-
|
397
|
-
|
381
|
+
# @api public
|
382
|
+
#
|
383
|
+
# A callback that can be provided for determining the CMS object to be used when visiting
|
384
|
+
# the homepage. See {Scrivito::RoutingExtensions#scrivito_route scrivito_route} for
|
385
|
+
# details on how to define routes. The callback is called once per request and receives
|
386
|
+
# the rack environment as its only parameter. By default, the CMS object at the root
|
387
|
+
# path (+/+) is used as the homepage.
|
388
|
+
#
|
389
|
+
# @yield Rack environment of the current request
|
390
|
+
#
|
391
|
+
# @example
|
392
|
+
# Scrivito.configure do |config|
|
393
|
+
# config.choose_homepage do |env|
|
394
|
+
# Obj.root # Replace with code to set the homepage
|
395
|
+
# end
|
396
|
+
# end
|
397
|
+
def self.choose_homepage(&block)
|
398
|
+
self.choose_homepage_callback = block
|
399
|
+
end
|
400
|
+
|
401
|
+
def self.obj_formats
|
402
|
+
@obj_formats ||= {
|
403
|
+
'_default' => proc do |obj, user|
|
404
|
+
{
|
405
|
+
id: obj.id,
|
406
|
+
obj_class: obj.obj_class,
|
407
|
+
description_for_editor: obj.description_for_editor,
|
408
|
+
modification: obj.modification,
|
409
|
+
has_conflict: obj.has_conflict?,
|
410
|
+
last_changed: obj.last_changed.utc.iso8601,
|
411
|
+
is_binary: obj.binary?,
|
412
|
+
restriction_messages: user.restriction_messages_for(obj)
|
413
|
+
}
|
398
414
|
end
|
415
|
+
}
|
416
|
+
end
|
417
|
+
|
418
|
+
def self.register_obj_format(name, &block)
|
419
|
+
if name.start_with? '_'
|
420
|
+
raise InvalidFormatNameError.new('Format names starting with underscore are not allowed.')
|
421
|
+
else
|
422
|
+
obj_formats[name] = block
|
399
423
|
end
|
424
|
+
end
|
425
|
+
|
426
|
+
# For test purposes only.
|
427
|
+
def self.reset_editing_auth_callback!
|
428
|
+
@editing_auth_callback = nil
|
429
|
+
end
|
400
430
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
Missing the required configuration key "#{key}".
|
431
|
+
def self.migration_path
|
432
|
+
'scrivito/migrate'
|
433
|
+
end
|
405
434
|
|
406
|
-
|
407
|
-
|
435
|
+
private_class_method def self.default_editing_auth_callback
|
436
|
+
if Rails.env.development? || Rails.env.test?
|
437
|
+
->(_) { User.system_user }
|
438
|
+
end
|
439
|
+
end
|
408
440
|
|
409
|
-
|
410
|
-
|
441
|
+
private_class_method def self.assert_configuration_key_present(key, value)
|
442
|
+
unless value
|
443
|
+
raise %{
|
444
|
+
Missing the required configuration key "#{key}".
|
411
445
|
|
412
|
-
|
413
|
-
|
414
|
-
config.api_key = 'secret123'
|
415
|
-
end
|
446
|
+
You need to configure the "tenant" and the "api_key" in order to connect the application
|
447
|
+
to the Scrivito backend.
|
416
448
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
449
|
+
Either use the environment variables "SCRIVITO_TENANT" and "SCRIVITO_API_KEY" or set the
|
450
|
+
keys in an initializer:
|
451
|
+
|
452
|
+
Scrivito.configure do |config|
|
453
|
+
config.tenant = 'my_tenant'
|
454
|
+
config.api_key = 'secret123'
|
455
|
+
end
|
421
456
|
|
422
|
-
|
423
|
-
|
424
|
-
url = "https://#{url}" unless url.match(/^http/)
|
425
|
-
url = "#{url}/tenants/#{tenant}"
|
426
|
-
URI.parse(url)
|
457
|
+
The values of the keys can be obtained from the dashboard at https://scrivito.com.
|
458
|
+
}
|
427
459
|
end
|
428
460
|
end
|
429
461
|
|
430
|
-
|
462
|
+
private_class_method def self.calculate_endpoint_uri
|
463
|
+
url = endpoint
|
464
|
+
url = "https://#{url}" unless url.match(/^http/)
|
465
|
+
url = "#{url}/tenants/#{tenant}"
|
466
|
+
URI.parse(url)
|
467
|
+
end
|
431
468
|
end
|
432
469
|
|
470
|
+
Configuration.set_defaults!
|
471
|
+
|
433
472
|
class InvalidFormatNameError < StandardError
|
434
473
|
end
|
435
474
|
end
|