scrivito_sdk 0.18.1 → 0.30.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/blobs_controller.rb +1 -2
- data/app/controllers/scrivito/default_cms_controller.rb +9 -75
- data/app/controllers/scrivito/objs_controller.rb +107 -119
- data/app/controllers/scrivito/tasks_controller.rb +1 -1
- data/app/controllers/scrivito/users_controller.rb +1 -1
- data/app/controllers/scrivito/webservice_controller.rb +6 -2
- data/app/controllers/scrivito/workspaces_controller.rb +57 -17
- data/app/helpers/scrivito_helper.rb +285 -0
- data/app/views/google_maps_widget/show.html.erb +1 -0
- data/app/views/scrivito/_editing_auth_warning.html.erb +43 -0
- data/app/views/scrivito/blobs/upload_permission.json.jbuilder +1 -0
- data/app/views/scrivito/objs/copy.json.jbuilder +1 -0
- data/app/views/scrivito/objs/copy_widget.html.erb +1 -1
- data/app/views/scrivito/objs/create.json.jbuilder +1 -0
- data/app/views/scrivito/objs/create_widget.html.erb +1 -1
- data/app/views/scrivito/objs/details.json.jbuilder +1 -0
- data/app/views/scrivito/objs/format_missing_error.json.jbuilder +1 -0
- data/app/views/scrivito/objs/modification.json.jbuilder +1 -0
- data/app/views/scrivito/objs/page_class_selection.json.jbuilder +1 -0
- data/app/views/scrivito/objs/search.json.jbuilder +6 -0
- data/app/views/scrivito/objs/search_only_size.json.jbuilder +1 -0
- data/app/views/scrivito/objs/update.json.jbuilder +1 -0
- data/app/views/scrivito/objs/widget_class_selection.json.jbuilder +1 -0
- data/app/views/scrivito/objs/widget_modification.json.jbuilder +1 -0
- data/app/views/scrivito/tasks/show.json.jbuilder +3 -0
- data/app/views/scrivito/users/suggest.json.jbuilder +1 -0
- data/app/views/scrivito/webservice/empty.json +1 -0
- data/app/views/scrivito/webservice/error.json.jbuilder +2 -0
- data/app/views/scrivito/workspaces/_workspace.json.jbuilder +5 -0
- data/app/views/scrivito/workspaces/check.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/create.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/index.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/show.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/task.json.jbuilder +5 -0
- data/config/ca-bundle.crt +259 -234
- data/config/cms_routes.rb +2 -2
- data/config/routes.rb +3 -0
- data/lib/assets/javascripts/{scrivito_editing.js → scrivito_sdk.js} +1662 -1180
- data/lib/assets/stylesheets/{scrivito_editing.css → scrivito_sdk.css} +242 -6
- data/lib/generators/scrivito/install/install_generator.rb +62 -0
- data/lib/generators/scrivito/install/templates/app/controllers/cms_controller.rb +3 -0
- data/lib/generators/scrivito/install/templates/app/controllers/page_controller.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/models/headline_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/image.rb +5 -0
- data/lib/generators/scrivito/install/templates/app/models/image_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/obj.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/models/page.rb +8 -0
- data/lib/generators/scrivito/install/templates/app/models/text_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/widget.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/views/headline_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/image_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/page/details.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +16 -0
- data/lib/generators/scrivito/install/templates/app/views/page/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/text_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/text_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/config/initializers/scrivito.rb +10 -0
- data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito.rb +49 -0
- data/lib/generators/scrivito/migration/USAGE +9 -0
- data/lib/generators/{cms → scrivito}/migration/migration_generator.rb +4 -9
- data/lib/generators/{cms → scrivito}/migration/templates/migration.erb +3 -3
- data/lib/generators/{cms → scrivito}/widget/templates/details.html.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/migration.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/model.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/show.html.erb +0 -0
- data/lib/generators/scrivito/widget/templates/thumbnail.html.erb +3 -0
- data/lib/generators/{cms → scrivito}/widget/widget_generator.rb +3 -2
- data/lib/obj.rb +17 -3
- data/lib/scrivito/attribute_collection.rb +7 -12
- data/lib/scrivito/attribute_content.rb +31 -12
- data/lib/scrivito/basic_obj.rb +186 -96
- data/lib/scrivito/basic_widget.rb +25 -10
- data/lib/scrivito/binary.rb +75 -0
- data/lib/scrivito/cache_garbage_collector.rb +19 -4
- data/lib/scrivito/child_list_tag.rb +108 -0
- data/lib/scrivito/client_config.rb +2 -1
- data/lib/scrivito/client_error.rb +3 -2
- data/lib/scrivito/cms_backend.rb +81 -16
- data/lib/scrivito/cms_dispatch_controller.rb +7 -0
- data/lib/scrivito/cms_env.rb +0 -2
- data/lib/scrivito/cms_field_tag.rb +44 -35
- data/lib/scrivito/cms_rest_api.rb +23 -6
- data/lib/scrivito/cms_rest_api/attribute_serializer.rb +1 -1
- data/lib/scrivito/cms_routing.rb +120 -0
- data/lib/scrivito/configuration.rb +69 -58
- data/lib/scrivito/connection_manager.rb +30 -1
- data/lib/scrivito/content_service.rb +10 -7
- data/lib/scrivito/controller_actions.rb +108 -0
- data/lib/scrivito/diff.rb +30 -15
- data/lib/scrivito/editing_context.rb +4 -0
- data/lib/scrivito/editing_context_helper.rb +19 -0
- data/lib/scrivito/editing_context_middleware.rb +20 -1
- data/lib/scrivito/image_tag_helper.rb +44 -0
- data/lib/scrivito/layout_tags.rb +33 -0
- data/lib/scrivito/link.rb +4 -2
- data/lib/scrivito/membership.rb +0 -8
- data/lib/scrivito/migrations.rb +0 -1
- data/lib/scrivito/migrations/installer.rb +1 -1
- data/lib/scrivito/migrations/migration.rb +0 -2
- data/lib/scrivito/migrations/migrator.rb +2 -3
- data/lib/scrivito/obj_class.rb +64 -16
- data/lib/scrivito/obj_class_data.rb +4 -0
- data/lib/scrivito/obj_search_enumerator.rb +1 -1
- data/lib/scrivito/routing_helper.rb +42 -0
- data/lib/scrivito/{engine.rb → sdk_engine.rb} +15 -29
- data/lib/scrivito/tag_renderer.rb +40 -0
- data/lib/scrivito/test_request.rb +40 -0
- data/lib/scrivito/type_computer.rb +1 -6
- data/lib/scrivito/user.rb +33 -15
- data/lib/scrivito/user_definition.rb +34 -6
- data/lib/scrivito/widget_tag.rb +67 -0
- data/lib/scrivito/workspace.rb +12 -24
- data/lib/scrivito_sdk.rb +17 -1
- data/lib/tasks/cache.rake +4 -5
- data/lib/tasks/migration.rake +1 -1
- data/lib/widget.rb +21 -3
- metadata +119 -70
- data/README +0 -6
- data/app/controllers/cms_controller.rb +0 -7
- data/app/helpers/cms_helper.rb +0 -7
- data/app/helpers/cms_routing_helper.rb +0 -7
- data/app/helpers/scrivito/cms_asset_helper.rb +0 -110
- data/app/helpers/scrivito/cms_tag_helper.rb +0 -232
- data/app/helpers/scrivito/default_cms_helper.rb +0 -21
- data/app/helpers/scrivito/default_cms_routing_helper.rb +0 -128
- data/app/helpers/scrivito/display_helper.rb +0 -64
- data/app/helpers/scrivito/editing_helper.rb +0 -32
- data/app/helpers/scrivito/layout_helper.rb +0 -21
- data/app/models/named_link.rb +0 -2
- data/app/views/cms/_index.html.erb +0 -7
- data/app/views/cms/index.html.erb +0 -1
- data/app/views/scrivito/_editing_javascript.html.erb +0 -7
- data/app/views/scrivito/default_cms/show_widget.html.erb +0 -1
- data/lib/assets/stylesheets/scrivito.css +0 -199
- data/lib/generators/cms/migration/USAGE +0 -9
- data/lib/generators/cms/widget/templates/thumbnail.html.erb +0 -2
- data/lib/scrivito/blob.rb +0 -48
- data/lib/scrivito/cms_accessible.rb +0 -30
- data/lib/scrivito/cms_rest_api/blob_uploader.rb +0 -18
- data/lib/scrivito/cms_test_request.rb +0 -23
- data/lib/scrivito/migrations/migration_dsl.rb +0 -180
@@ -40,6 +40,13 @@ module Scrivito
|
|
40
40
|
|
41
41
|
def default_controller
|
42
42
|
CmsController
|
43
|
+
rescue NameError => e
|
44
|
+
if e.message.include?('CmsController')
|
45
|
+
raise 'Your application does not define the "CmsController" needed for Scrivito. '\
|
46
|
+
'Did you forget to run "rails generate scrivito:install"?'
|
47
|
+
else
|
48
|
+
raise
|
49
|
+
end
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
data/lib/scrivito/cms_env.rb
CHANGED
@@ -2,41 +2,25 @@ module Scrivito
|
|
2
2
|
|
3
3
|
# this class is the server-side equivalent of the JavaScript class `cms_field_element`
|
4
4
|
class CmsFieldTag < Struct.new(
|
5
|
-
:
|
6
|
-
)
|
5
|
+
:view, :tag_name, :obj_or_widget, :field_name)
|
7
6
|
|
8
|
-
|
9
|
-
formatted_options = {}
|
10
|
-
raw_options.each do |key, value|
|
11
|
-
formatted_options["data-scrivito-#{key}"] = value
|
12
|
-
end
|
13
|
-
|
14
|
-
formatted_options
|
15
|
-
end
|
16
|
-
|
17
|
-
def field_type
|
18
|
-
@field_type ||= obj_or_widget.type_of_attribute(field_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def default_content
|
22
|
-
calculate_content_and_modification
|
23
|
-
@content_and_modification.first
|
24
|
-
end
|
7
|
+
include TagRenderer
|
25
8
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
9
|
+
def content(&block)
|
10
|
+
if field_type == 'widget'
|
11
|
+
raise ArgumentError, 'No block allowed for widget fields' if block_given?
|
12
|
+
modifications = modification_info || []
|
13
|
+
rendered_widgets = default_content.each_with_index.map do |widget, index|
|
14
|
+
WidgetTag.new(view, widget, modifications[index]).render
|
15
|
+
end
|
16
|
+
view.safe_join(rendered_widgets)
|
17
|
+
else
|
18
|
+
block_given? ? view.capture { yield } : view.scrivito_value(default_content)
|
19
|
+
end
|
36
20
|
end
|
37
21
|
|
38
|
-
def
|
39
|
-
return {} unless
|
22
|
+
def options
|
23
|
+
return {} unless authenticated_editor?
|
40
24
|
|
41
25
|
options = {
|
42
26
|
'private-field-workspace-id' => current_workspace_id,
|
@@ -51,14 +35,14 @@ class CmsFieldTag < Struct.new(
|
|
51
35
|
end
|
52
36
|
|
53
37
|
if obj_or_widget.kind_of?(BasicWidget)
|
54
|
-
options['private-field-id'] = obj_or_widget.obj.id
|
38
|
+
options['private-field-obj-id'] = obj_or_widget.obj.id
|
55
39
|
options['private-field-widget-id'] = obj_or_widget.id
|
56
40
|
else
|
57
|
-
options['private-field-id'] = obj_or_widget.id
|
41
|
+
options['private-field-obj-id'] = obj_or_widget.id
|
58
42
|
end
|
59
43
|
|
60
44
|
if FIELD_TYPES_WITH_ORIGINAL_CONTENT.include?(field_type)
|
61
|
-
original_value =
|
45
|
+
original_value = view.scrivito_value(current_value)
|
62
46
|
original_content = original_content(field_type, original_value)
|
63
47
|
encoded_content = Base64.strict_encode64(MultiJson.encode(original_content))
|
64
48
|
options['private-field-original-content'] = encoded_content
|
@@ -74,6 +58,27 @@ class CmsFieldTag < Struct.new(
|
|
74
58
|
options
|
75
59
|
end
|
76
60
|
|
61
|
+
def modification_info
|
62
|
+
calculate_content_and_modification
|
63
|
+
@content_and_modification.second
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def field_type
|
69
|
+
@field_type ||= obj_or_widget.type_of_attribute(field_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def default_content
|
73
|
+
calculate_content_and_modification
|
74
|
+
@content_and_modification.first
|
75
|
+
end
|
76
|
+
|
77
|
+
def calculate_content_and_modification
|
78
|
+
@content_and_modification ||=
|
79
|
+
comparison.diff_for(obj_or_widget, field_name) || [current_value, nil]
|
80
|
+
end
|
81
|
+
|
77
82
|
def comparison
|
78
83
|
editing_context.comparison
|
79
84
|
end
|
@@ -96,10 +101,14 @@ class CmsFieldTag < Struct.new(
|
|
96
101
|
text
|
97
102
|
]
|
98
103
|
|
99
|
-
def
|
104
|
+
def authenticated_editor?
|
100
105
|
editing_context.authenticated_editor?
|
101
106
|
end
|
102
107
|
|
108
|
+
def editing_context
|
109
|
+
EditingContextMiddleware.from_request(view.request)
|
110
|
+
end
|
111
|
+
|
103
112
|
def original_content(field_type, field_value)
|
104
113
|
case field_type
|
105
114
|
when 'reference' then field_value.try(:id)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'restclient'
|
2
|
-
require 'active_support/all'
|
3
|
-
|
4
1
|
module Scrivito
|
5
2
|
|
6
3
|
# Provides a simple wrapper for the CMS Rest API.
|
@@ -64,6 +61,23 @@ module Scrivito
|
|
64
61
|
@number_of_requests
|
65
62
|
end
|
66
63
|
|
64
|
+
def self.upload_file(file)
|
65
|
+
upload_permission = get('blobs/upload_permission')
|
66
|
+
uri = URI.parse(upload_permission['url'])
|
67
|
+
File.open(file) do |open_file|
|
68
|
+
content_type = MIME::Types.type_for(file.path).first.content_type
|
69
|
+
upload_io = UploadIO.new(open_file, content_type, File.basename(file))
|
70
|
+
params = upload_permission['fields'].merge('file' => upload_io)
|
71
|
+
request = Net::HTTP::Post::Multipart.new(uri.path, params)
|
72
|
+
response = ConnectionManager.request(uri, request)
|
73
|
+
if response.code.starts_with?('2')
|
74
|
+
upload_permission['blob'].merge('filename' => File.basename(file.path))
|
75
|
+
else
|
76
|
+
raise ScrivitoError, "File upload failed with code #{response.code}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
67
81
|
class << self
|
68
82
|
|
69
83
|
private
|
@@ -109,10 +123,12 @@ module Scrivito
|
|
109
123
|
raise AccessDenied.new(response.body)
|
110
124
|
else
|
111
125
|
begin
|
112
|
-
|
126
|
+
error_body = MultiJson.decode(response.body)
|
127
|
+
specific_output = error_body['error']
|
113
128
|
|
114
129
|
if response.code.start_with?('4')
|
115
|
-
|
130
|
+
error_code = error_body['code']
|
131
|
+
raise ClientError.new(specific_output, code, error_code)
|
116
132
|
elsif response.code == '500' && specific_output
|
117
133
|
raise BackendError.new(specific_output, code)
|
118
134
|
else # 3xx and >500 are treated as NetworkErrors
|
@@ -135,7 +151,8 @@ module Scrivito
|
|
135
151
|
end
|
136
152
|
return task_data["result"] if task_data["status"] == "success"
|
137
153
|
message = task_data["message"] || "Missing error message in task response #{task_data}"
|
138
|
-
|
154
|
+
error_code = task_data['code']
|
155
|
+
raise ClientError.new(message, 400, error_code)
|
139
156
|
end
|
140
157
|
|
141
158
|
def set_headers(request)
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Scrivito
|
2
|
+
|
3
|
+
class CmsRouting < Struct.new(:request, :main_app)
|
4
|
+
LINK_TO_EMPTY_LINKLIST = "#__empty_linklist"
|
5
|
+
LINK_TO_EMPTY_BLOB = "#__empty_blob"
|
6
|
+
|
7
|
+
def self.match_protocol(url, request)
|
8
|
+
request.ssl? && !url.starts_with?('https') ? url.gsub(/^http/, 'https') : url
|
9
|
+
end
|
10
|
+
|
11
|
+
def path_or_url(target, path_or_url, options = {})
|
12
|
+
if cms_with_editing_context?(target)
|
13
|
+
path_or_url_with_editing_context(target, path_or_url, options)
|
14
|
+
else
|
15
|
+
path_or_url_without_editing_context(target, path_or_url, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert_links(html)
|
20
|
+
if html
|
21
|
+
html.gsub(%r{<?\bobjid:([a-f0-9]{16})\b>?}) do
|
22
|
+
if obj = Obj.find_by_id($1)
|
23
|
+
path_or_url(obj, "path")
|
24
|
+
else
|
25
|
+
"#__target_object_not_reachable"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def path_or_url_with_editing_context(target, path_or_url, options)
|
34
|
+
path_or_url_without_editing_context(target, path_or_url,
|
35
|
+
options.merge(editing_context.to_params))
|
36
|
+
end
|
37
|
+
|
38
|
+
def path_or_url_without_editing_context(target, path_or_url, options)
|
39
|
+
if target.is_a?(Link)
|
40
|
+
path_or_url_for_links(target, path_or_url, options)
|
41
|
+
elsif target.is_a?(Obj)
|
42
|
+
path_or_url_for_objs(target, path_or_url, options)
|
43
|
+
elsif target.respond_to?(:first)
|
44
|
+
if target.first.is_a?(Link)
|
45
|
+
path_or_url_for_links(target.first, path_or_url, options)
|
46
|
+
else
|
47
|
+
return LINK_TO_EMPTY_LINKLIST
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+
|
51
|
+
"It must only be called with an Obj or a Link or a non-empty LinkList."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def path_or_url_for_links(link, path_or_url, options = {})
|
56
|
+
url = basic_url_or_path_for_link(link, path_or_url,
|
57
|
+
Rack::Utils.parse_nested_query(link.query).merge(options))
|
58
|
+
url = url + "##{link.fragment}" if link.fragment.present?
|
59
|
+
url
|
60
|
+
end
|
61
|
+
|
62
|
+
def path_or_url_for_objs(obj, path_or_url, options = {})
|
63
|
+
permalink = obj.permalink
|
64
|
+
if permalink
|
65
|
+
main_app.public_send("scrivito_permalink_#{path_or_url}", options.merge(:permalink => permalink))
|
66
|
+
elsif obj.homepage?
|
67
|
+
main_app.public_send("scrivito_root_#{path_or_url}", options)
|
68
|
+
else
|
69
|
+
if obj.binary? && editing_context.display_mode != "editing"
|
70
|
+
if obj.binary_url
|
71
|
+
self.class.match_protocol(obj.binary_url, request)
|
72
|
+
else
|
73
|
+
LINK_TO_EMPTY_BLOB
|
74
|
+
end
|
75
|
+
else
|
76
|
+
main_app.public_send(
|
77
|
+
"cms_id_#{path_or_url}",
|
78
|
+
options.merge(
|
79
|
+
id: obj.id,
|
80
|
+
slug: obj.slug.presence
|
81
|
+
)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def editor_authenticated?
|
88
|
+
editing_context.authenticated_editor?
|
89
|
+
end
|
90
|
+
|
91
|
+
def editing_context
|
92
|
+
EditingContextMiddleware.from_request(request)
|
93
|
+
end
|
94
|
+
|
95
|
+
def cms_with_editing_context?(target)
|
96
|
+
editor_authenticated? && (!target.is_a?(Link) || target.internal?)
|
97
|
+
end
|
98
|
+
|
99
|
+
def basic_url_or_path_for_link(link, path_or_url, options = {})
|
100
|
+
if link.internal?
|
101
|
+
path_or_url_without_editing_context(link.obj, path_or_url, options)
|
102
|
+
else
|
103
|
+
url = link.url
|
104
|
+
url = merge_options(url, options) if options.any?
|
105
|
+
url
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def merge_options(url, options)
|
110
|
+
parsed_url = URI.parse(url)
|
111
|
+
|
112
|
+
query = Rack::Utils.parse_query(parsed_url.query)
|
113
|
+
merged_query = query.merge(options.stringify_keys)
|
114
|
+
parsed_url.query = merged_query.to_query
|
115
|
+
|
116
|
+
parsed_url.to_s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -1,21 +1,4 @@
|
|
1
|
-
require 'scrivito/blob'
|
2
|
-
|
3
1
|
module Scrivito
|
4
|
-
#
|
5
|
-
# Configures the Scrivito SDK.
|
6
|
-
# The configuration keys +tenant+ and +api_key+ _must_ be provided.
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# Scrivito.configure do |config|
|
10
|
-
# config.tenant = 'my-tenant-name'
|
11
|
-
# config.api_key = 'secret'
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# @api public
|
15
|
-
#
|
16
|
-
def self.configure
|
17
|
-
yield ::Scrivito::Configuration
|
18
|
-
end
|
19
2
|
|
20
3
|
#
|
21
4
|
# @api public
|
@@ -30,28 +13,46 @@ module Scrivito
|
|
30
13
|
|
31
14
|
class << self
|
32
15
|
# Determine if current visitor is permitted to edit content.
|
33
|
-
attr_accessor :editing_auth_callback
|
34
|
-
|
35
16
|
attr_accessor :find_user_proc
|
36
17
|
|
37
|
-
# Configure a callback to be invoked when the Scrivito SDK determines,
|
38
|
-
# if current visitor is permitted to edit content.
|
39
|
-
# Default is <code>false</code>.
|
40
18
|
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
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
|
+
#
|
46
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
|
+
#
|
47
44
|
def editing_auth(&block)
|
48
45
|
if block.respond_to?(:arity) && block.arity == 1
|
49
|
-
|
46
|
+
@editing_auth_callback = block
|
50
47
|
else
|
51
48
|
raise ArgumentError, 'editing_auth should have only one attribute!'
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
52
|
+
def editing_auth_callback
|
53
|
+
@editing_auth_callback || default_editing_auth_callback
|
54
|
+
end
|
55
|
+
|
55
56
|
# Configures how to find users for the in-place GUI.
|
56
57
|
# @api public
|
57
58
|
# @param [Proc] find_user_proc proc for finding a user by the user id
|
@@ -80,11 +81,6 @@ module Scrivito
|
|
80
81
|
self.find_user_proc = find_user_proc
|
81
82
|
end
|
82
83
|
|
83
|
-
# TODO: Legacy compatiblity. Remove when DisplayHelper gets removed.
|
84
|
-
def editor_interface_enabled?
|
85
|
-
false
|
86
|
-
end
|
87
|
-
|
88
84
|
# The +Scrivito+ makes heavy use of filesystem caching.
|
89
85
|
# Use this method to configure the directory that should be used to store cached data.
|
90
86
|
# By default, +RAILS_ROOT/tmp/scrivito_cache+ will be used.
|
@@ -148,25 +144,23 @@ module Scrivito
|
|
148
144
|
NamedLink.reset_cache
|
149
145
|
BasicObj.reset_type_computer!
|
150
146
|
BasicWidget.reset_type_computer!
|
151
|
-
::ApplicationController.__send__(:helper, :cms)
|
152
147
|
end
|
153
148
|
end
|
154
149
|
|
155
|
-
def configure_cms_database
|
156
|
-
end
|
157
|
-
|
158
150
|
def tenant
|
159
|
-
|
160
|
-
|
151
|
+
tenant = @tenant || ENV['SCRIVITO_TENANT']
|
152
|
+
assert_configuration_key_present(:tenant, tenant)
|
153
|
+
tenant
|
161
154
|
end
|
162
155
|
|
163
156
|
def api_key
|
164
|
-
|
165
|
-
|
157
|
+
api_key = @api_key || ENV['SCRIVITO_API_KEY']
|
158
|
+
assert_configuration_key_present(:api_key, api_key)
|
159
|
+
api_key
|
166
160
|
end
|
167
161
|
|
168
162
|
def endpoint
|
169
|
-
|
163
|
+
raise 'Missing required configuration key "endpoint"' unless @endpoint
|
170
164
|
@endpoint
|
171
165
|
end
|
172
166
|
|
@@ -176,7 +170,6 @@ module Scrivito
|
|
176
170
|
|
177
171
|
def set_defaults!
|
178
172
|
self.ca_file = DEFAULT_CA_FILE
|
179
|
-
self.editing_auth { |env| false }
|
180
173
|
self.endpoint = 'api.scrivito.com'
|
181
174
|
self.check_batch_size = 100
|
182
175
|
end
|
@@ -192,18 +185,6 @@ module Scrivito
|
|
192
185
|
self.choose_homepage_callback = block
|
193
186
|
end
|
194
187
|
|
195
|
-
def cms_routes(*args)
|
196
|
-
raise <<-EOS.gsub(/\s+/, ' ')
|
197
|
-
Calling Scrivito::Configuration.cms_routes is not needed anymore.
|
198
|
-
Please remove it from config/routes.rb
|
199
|
-
EOS
|
200
|
-
end
|
201
|
-
|
202
|
-
def use_x_sendfile=(value)
|
203
|
-
raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\
|
204
|
-
' config.action_dispatch.x_sendfile_header = "X-Sendfile"'
|
205
|
-
end
|
206
|
-
|
207
188
|
def obj_formats
|
208
189
|
@obj_formats ||= {
|
209
190
|
'_default' => proc do |obj, user|
|
@@ -229,11 +210,41 @@ module Scrivito
|
|
229
210
|
end
|
230
211
|
end
|
231
212
|
|
213
|
+
# For test purposes only.
|
214
|
+
def reset_editing_auth_callback!
|
215
|
+
@editing_auth_callback = nil
|
216
|
+
end
|
217
|
+
|
218
|
+
def migration_path
|
219
|
+
'scrivito/migrate'
|
220
|
+
end
|
221
|
+
|
232
222
|
private
|
233
223
|
|
234
|
-
def
|
235
|
-
if
|
236
|
-
|
224
|
+
def default_editing_auth_callback
|
225
|
+
if Rails.env.development? || Rails.env.test?
|
226
|
+
->(_) { User.system_user }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def assert_configuration_key_present(key, value)
|
231
|
+
unless value
|
232
|
+
raise %{
|
233
|
+
Missing the required configuration key "#{key}".
|
234
|
+
|
235
|
+
You need to configure the "tenant" and the "api_key" in order to connect the application
|
236
|
+
to the Scrivito backend.
|
237
|
+
|
238
|
+
Either use the environment variables "SCRIVITO_TENANT" and "SCRIVITO_API_KEY" or set the
|
239
|
+
keys in an initializer:
|
240
|
+
|
241
|
+
Scrivito.configure do |config|
|
242
|
+
config.tenant = 'my_tenant'
|
243
|
+
config.api_key = 'secret123'
|
244
|
+
end
|
245
|
+
|
246
|
+
The values of the keys can be obtained from the dashboard at https://scrivito.com.
|
247
|
+
}
|
237
248
|
end
|
238
249
|
end
|
239
250
|
|