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
@@ -3,7 +3,7 @@ module Scrivito
|
|
3
3
|
class Migrator
|
4
4
|
class << self
|
5
5
|
def migrations_path
|
6
|
-
Rails.root +
|
6
|
+
Rails.root + Scrivito::Configuration.migration_path
|
7
7
|
end
|
8
8
|
|
9
9
|
def determine_migrations(paths)
|
@@ -76,8 +76,7 @@ module Scrivito
|
|
76
76
|
workspace_lock.validate(workspace)
|
77
77
|
end
|
78
78
|
else
|
79
|
-
|
80
|
-
workspace = migration_workspace
|
79
|
+
workspace = Workspace.create(title: 'Migration Working Copy', id: 'rtc')
|
81
80
|
workspace_lock.write(workspace)
|
82
81
|
end
|
83
82
|
|
data/lib/scrivito/obj_class.rb
CHANGED
@@ -49,11 +49,16 @@ module Scrivito
|
|
49
49
|
# to set as values. Attributes can be either given as {Scrivito::Attribute} instances or as
|
50
50
|
# an attribute property hash.
|
51
51
|
#
|
52
|
-
# @example Create a
|
53
|
-
# ObjClass.create(name: 'Homepage',
|
52
|
+
# @example Create a obj class
|
53
|
+
# ObjClass.create(name: 'Homepage', attributes: [
|
54
|
+
# { name: 'title', type: :string },
|
55
|
+
# { name: 'body', type: :widget }
|
56
|
+
# ])
|
54
57
|
#
|
55
58
|
# @example Create a binary obj class.
|
56
|
-
# ObjClass.create(name: 'Image',
|
59
|
+
# ObjClass.create(name: 'Image', attributes: [
|
60
|
+
# { name: 'blob', type: :binary }
|
61
|
+
# ])
|
57
62
|
#
|
58
63
|
# @example Create an obj class with attributes passed in as an Array of attribute property hashes.
|
59
64
|
# ObjClass.create(name: 'Blog', attributes: [
|
@@ -69,19 +74,23 @@ module Scrivito
|
|
69
74
|
#
|
70
75
|
# @param [Hash] properties
|
71
76
|
# @option properties [String] :name The name of the obj class.
|
72
|
-
# @option properties [Boolean] :is_binary Is this a binary or non-binary obj class?
|
73
77
|
# @option properties [Boolean] :is_active Is it possible to create instances of this obj class?
|
74
78
|
# @option properties [Array<Scrivito::Attribute>, Array<Hash>] :attributes A list of
|
75
79
|
# attributes for this obj class. Can be either a list of attribute instances or attribute
|
76
80
|
# property hashes.
|
77
81
|
#
|
82
|
+
# @note the +is_binary+ option is deprecated
|
83
|
+
#
|
78
84
|
# @return [Scrivito::ObjClass]
|
79
85
|
def create(properties)
|
80
86
|
properties = properties.with_indifferent_access
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
'
|
88
|
+
if properties.key?(:is_binary)
|
89
|
+
Scrivito::Deprecation.warn(
|
90
|
+
"`is_binary' is deprecated and should not be used anymore."\
|
91
|
+
"Please remove the parameter and specify all attributes you need "\
|
92
|
+
"including the previously provided attributes 'title', 'body', 'blob'"
|
93
|
+
)
|
85
94
|
end
|
86
95
|
|
87
96
|
if properties[:attributes]
|
@@ -129,6 +138,15 @@ module Scrivito
|
|
129
138
|
@workspace = workspace
|
130
139
|
end
|
131
140
|
|
141
|
+
# @api public
|
142
|
+
# Returns true if this ObjClass was created with a +is_binary+ option.
|
143
|
+
# Creating ObjClass with this option is deprecated and will be removed.
|
144
|
+
#
|
145
|
+
# @return [Boolean]
|
146
|
+
def legacy_type?
|
147
|
+
!!obj_class_data.type
|
148
|
+
end
|
149
|
+
|
132
150
|
# @!attribute [r] id
|
133
151
|
# @api public
|
134
152
|
# @return [String] unique identifier of this obj class
|
@@ -138,10 +156,20 @@ module Scrivito
|
|
138
156
|
# @!attribute [r] is_active
|
139
157
|
# @api public
|
140
158
|
# @return [Boolean] whether instances can be created with this obj class
|
141
|
-
|
142
|
-
|
143
|
-
#
|
144
|
-
|
159
|
+
delegate :id, :name, :is_active, to: :obj_class_data
|
160
|
+
|
161
|
+
# @api public
|
162
|
+
# @return [Boolean] whether instances of this class are binary, e.g. images or PDFs
|
163
|
+
# @deprecated Please create objects without using the +is_binary+ option
|
164
|
+
# @raise [ScrivitoError] if the method is called on a non-legacy-type ObjClass
|
165
|
+
def is_binary
|
166
|
+
if legacy_type?
|
167
|
+
obj_class_data.is_binary
|
168
|
+
else
|
169
|
+
raise ScrivitoError,
|
170
|
+
%(`is_binary' and `binary?' can only be called on ObjClasses with a legacy_type.)
|
171
|
+
end
|
172
|
+
end
|
145
173
|
|
146
174
|
alias_method :active?, :is_active
|
147
175
|
alias_method :binary?, :is_binary
|
@@ -165,14 +193,31 @@ module Scrivito
|
|
165
193
|
# end
|
166
194
|
attr_reader :attributes
|
167
195
|
|
168
|
-
# Updates this obj class and persists the changes in the CMS. It is not possible to
|
169
|
-
# update the +name+ or +is_binary+ property.
|
170
|
-
#
|
171
196
|
# @api public
|
197
|
+
# Updates this obj class and persists the changes in the CMS. It is not possible to
|
198
|
+
# update the +name+.
|
172
199
|
#
|
173
200
|
# See {Scrivito::ObjClass.create} for a detailed overview of
|
174
201
|
# what properties are allowed and how to set them.
|
175
202
|
#
|
203
|
+
# The +is_binary+ option can only be removed. By passing +nil+ for the
|
204
|
+
# +is_binary+ option to update, you can convert legacy objects. This conversion
|
205
|
+
# removes the fields +title+, +body+ (if +is_binary+ was +false+) or +blob+ (if
|
206
|
+
# +is_binary+ was +true+). If you add the fields in the same request the values
|
207
|
+
# will be kept for all objs.
|
208
|
+
#
|
209
|
+
# @example Removing +is_binary+ but keeping the previously predefined fields
|
210
|
+
# ObjClass.find('Homepage').update(is_binary: nil, attributes: [
|
211
|
+
# {name: 'title', type: 'string'},
|
212
|
+
# {name: 'body', type: 'html'}
|
213
|
+
# ])
|
214
|
+
#
|
215
|
+
# # Binary ObjClass
|
216
|
+
# ObjClass.find('Image').update(is_binary: nil, attributes: [
|
217
|
+
# {name: 'title', type: 'string'},
|
218
|
+
# {name: 'blob', type: 'binary'}
|
219
|
+
# ])
|
220
|
+
#
|
176
221
|
# @param [Hash] properties
|
177
222
|
#
|
178
223
|
# @raise [ScrivitoError] Raised when trying to change +name+ or +is_binary+.
|
@@ -182,8 +227,11 @@ module Scrivito
|
|
182
227
|
params = properties.with_indifferent_access
|
183
228
|
|
184
229
|
if params.has_key?(:is_binary)
|
185
|
-
|
186
|
-
|
230
|
+
if params[:is_binary].nil?
|
231
|
+
params[:type] = params.delete(:is_binary)
|
232
|
+
else
|
233
|
+
raise ScrivitoError, "#{self.class} only supports removing the `is_binary' property"
|
234
|
+
end
|
187
235
|
end
|
188
236
|
|
189
237
|
if params.has_key?(:name)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Scrivito
|
3
3
|
# Provides an enumerator for iterating over obj search results and retrieving obj instances.
|
4
|
-
# This is done using the {http://ruby-doc.org/core-1.
|
4
|
+
# This is done using the {http://ruby-doc.org/core-2.1.3/Enumerable.html <code>Enumerable</code> mixin},
|
5
5
|
# which provides methods such as <code>map</code>, <code>select</code> or <code>take</code>.
|
6
6
|
#
|
7
7
|
# This enumerator is lazy. If for example you are looking for {BasicObj Obj}s with the ObjClass "Publication",
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Scrivito
|
2
|
+
#
|
3
|
+
# The helper contains methods to generate URLs to CMS content.
|
4
|
+
# Use {Scrivito::RoutingHelper#scrivito_path} or {Scrivito::RoutingHelper#scrivito_url} when linking or
|
5
|
+
# redirecting to CMS objects. These methods are available in boths your views and your controllers.
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
#
|
9
|
+
module RoutingHelper
|
10
|
+
#
|
11
|
+
# Returns the (URL-)path for a cms object.
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
#
|
15
|
+
# @param target [Obj, Link, Array<Link>]
|
16
|
+
# If +target+ is an +Array+ of +Links+, it must be non-empty.
|
17
|
+
# The first {Link} from the +Array+ will be used.
|
18
|
+
# @param options [Hash] include url settings such as path parameters or protocol.
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
#
|
22
|
+
def scrivito_path(target, options = {})
|
23
|
+
CmsRouting.new(request, main_app).path_or_url(target, "path", options)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns the absolute URL for a cms object.
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
#
|
31
|
+
# @param target [Obj, Link, Array<Link>]
|
32
|
+
# If +target+ is an +Array+ of +Links+, it must be non-empty.
|
33
|
+
# The first {Link} from the +Array+ will be used.
|
34
|
+
# @param options [Hash] include url settings such as path parameters or protocol.
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
def scrivito_url(target, options = {})
|
39
|
+
CmsRouting.new(request, main_app).path_or_url(target, "url", options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require "action_view"
|
3
|
-
require "active_model"
|
1
|
+
require 'rails'
|
4
2
|
|
3
|
+
require 'jbuilder'
|
5
4
|
require 'jquery-rails'
|
6
|
-
|
7
|
-
require 'scrivito/configuration'
|
5
|
+
require 'net/http/post/multipart'
|
8
6
|
|
9
7
|
module ::Scrivito
|
10
|
-
class
|
8
|
+
class SdkEngine < Rails::Engine
|
11
9
|
config.to_prepare { Scrivito::Configuration.to_prepare }
|
12
10
|
|
13
11
|
# make sure our exceptions cause an adequate error page and http status code
|
@@ -20,37 +18,25 @@ module ::Scrivito
|
|
20
18
|
|
21
19
|
# Expose Scrivito SDK runtime to controller for logging.
|
22
20
|
initializer "scrivito.log_runtime" do |app|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rescue NameError
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
if runtime
|
31
|
-
Scrivito::LogSubscriber.attach_to :scrivito
|
32
|
-
ActiveSupport.on_load(:action_controller) do
|
33
|
-
include runtime
|
34
|
-
end
|
21
|
+
Scrivito::LogSubscriber.attach_to :scrivito
|
22
|
+
ActiveSupport.on_load(:action_controller) do
|
23
|
+
include Scrivito::ControllerRuntime
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
38
|
-
initializer "scrivito.configure_database", :before => :load_config_initializers do |app|
|
39
|
-
Scrivito::Configuration.configure_cms_database
|
40
|
-
end
|
41
|
-
|
42
27
|
initializer "scrivito.routing_helpers" do
|
43
|
-
|
44
|
-
|
45
|
-
|
28
|
+
ActiveSupport.on_load(:action_controller) do
|
29
|
+
if Rails.env == 'test'
|
30
|
+
ActionDispatch::TestRequest.__send__(:include, Scrivito::TestRequest)
|
31
|
+
end
|
46
32
|
|
47
|
-
|
48
|
-
|
33
|
+
include Scrivito::RoutingHelper
|
34
|
+
end
|
49
35
|
end
|
50
36
|
|
51
|
-
initializer
|
37
|
+
initializer 'scrivito.add_sdk_assets' do |app|
|
52
38
|
# Specify which file should be precompiled for packaging
|
53
|
-
app.config.assets.precompile += %w(
|
39
|
+
app.config.assets.precompile += %w(scrivito_sdk.js scrivito_sdk.css)
|
54
40
|
app.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
|
55
41
|
end
|
56
42
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Scrivito
|
2
|
+
|
3
|
+
module TagRenderer
|
4
|
+
|
5
|
+
VOID_TAGS = %w[area base br col command embed hr img input keygen
|
6
|
+
link meta param source track wbr]
|
7
|
+
|
8
|
+
def render(given_options = {}, &block)
|
9
|
+
TagRenderer.render(view, self, given_options, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def render(view, tag, given_options, &block)
|
15
|
+
tag_name = tag.tag_name
|
16
|
+
options = given_options.merge(formatted_options(tag))
|
17
|
+
|
18
|
+
if VOID_TAGS.include?(tag_name.to_s)
|
19
|
+
view.tag(tag_name, options)
|
20
|
+
else
|
21
|
+
view.content_tag(tag_name, tag.content(&block), options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def formatted_options(tag)
|
28
|
+
formatted_options = {}
|
29
|
+
tag.options.each do |key, value|
|
30
|
+
formatted_options["data-scrivito-#{key}"] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
formatted_options
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Scrivito
|
2
|
+
#
|
3
|
+
# @api public
|
4
|
+
#
|
5
|
+
module TestRequest
|
6
|
+
#
|
7
|
+
# Make a test request to act as a CMS request.
|
8
|
+
# This is necessary for testing controllers that include {Scrivito::ControllerActions}, because
|
9
|
+
# these controllers do not have explicit routes by default.
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
# @param [Scrivito::BasicObj Obj] test_obj requested +Obj+
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# class MyPageControllerTest < ActionController::TestCase
|
16
|
+
# test 'should respond with success' do
|
17
|
+
# request.for_scrivito_obj
|
18
|
+
# get :index
|
19
|
+
# assert_response :success
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
def for_scrivito_obj(test_obj = nil)
|
24
|
+
# prepare the env as if the given obj was loaded by Scrivito::CmsEnv
|
25
|
+
env[Scrivito::CmsEnv::OBJ_ENV_KEY] = test_obj if test_obj
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def assign_parameters(routes, controller_path, action, parameters = {})
|
29
|
+
super(routes, controller_path, action, parameters)
|
30
|
+
rescue ActionController::RoutingError, AbstractController::ActionNotFound => e
|
31
|
+
begin
|
32
|
+
super(routes, "scrivito/cms_dispatch", action, parameters)
|
33
|
+
rescue ActionController::RoutingError, AbstractController::ActionNotFound
|
34
|
+
raise e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -3,11 +3,10 @@ module Scrivito
|
|
3
3
|
class TypeComputer
|
4
4
|
def initialize(base_class, fallback_class)
|
5
5
|
@base_class, @fallback_class = base_class, fallback_class
|
6
|
-
@type_cache = {}
|
7
6
|
end
|
8
7
|
|
9
8
|
def compute_type(obj_class)
|
10
|
-
|
9
|
+
load_class(obj_class) || @fallback_class
|
11
10
|
end
|
12
11
|
|
13
12
|
def special_class?(klass)
|
@@ -16,10 +15,6 @@ class TypeComputer
|
|
16
15
|
|
17
16
|
private
|
18
17
|
|
19
|
-
def calculate_type(obj_class)
|
20
|
-
load_class(obj_class) || @fallback_class
|
21
|
-
end
|
22
|
-
|
23
18
|
def load_class(obj_class)
|
24
19
|
klass = obj_class.constantize
|
25
20
|
klass if inherits_from_base?(klass)
|
data/lib/scrivito/user.rb
CHANGED
@@ -46,17 +46,20 @@ module Scrivito
|
|
46
46
|
# end
|
47
47
|
# end
|
48
48
|
# end
|
49
|
-
def define(id)
|
49
|
+
def define(id, &block)
|
50
50
|
assert_valid_id(id)
|
51
|
-
|
52
|
-
yield user_definition if block_given?
|
53
|
-
user_definition.user
|
51
|
+
define_user(id, &block)
|
54
52
|
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
#
|
55
|
+
# Returns an anonymous system user, who can always create workspaces, can always read, write,
|
56
|
+
# publish, delete and invite to any workspace.
|
57
|
+
#
|
58
|
+
# @api public
|
59
|
+
# @return [Scrivito::User] the system user
|
60
|
+
#
|
61
|
+
def system_user
|
62
|
+
define_user { |user| user.is_admin! }
|
60
63
|
end
|
61
64
|
|
62
65
|
def unknown_user(id)
|
@@ -73,6 +76,12 @@ module Scrivito
|
|
73
76
|
|
74
77
|
private
|
75
78
|
|
79
|
+
def define_user(id = nil)
|
80
|
+
user_definition = UserDefinition.new(id)
|
81
|
+
yield user_definition if block_given?
|
82
|
+
user_definition.user
|
83
|
+
end
|
84
|
+
|
76
85
|
def assert_valid_id(id)
|
77
86
|
raise ScrivitoError.new('User id can not be blank') if id.blank?
|
78
87
|
raise ScrivitoError.new('User id is too long (max length 64)') if id.length > 64
|
@@ -99,7 +108,8 @@ module Scrivito
|
|
99
108
|
|
100
109
|
def can?(verb, workspace)
|
101
110
|
assert_valid_verb(verb)
|
102
|
-
|
111
|
+
verb == :read && workspace.published? || can_always?(verb, :workspace) ||
|
112
|
+
owner_of?(workspace) && !can_never?(verb, :workspace)
|
103
113
|
end
|
104
114
|
|
105
115
|
def can_always?(verb, subject)
|
@@ -152,7 +162,7 @@ module Scrivito
|
|
152
162
|
|
153
163
|
def suggest_users(input)
|
154
164
|
if suggest_users_proc
|
155
|
-
suggested_users =
|
165
|
+
suggested_users = sandbox_suggest_user_proc(input)
|
156
166
|
suggested_users.nil? ? [] : suggested_users
|
157
167
|
else
|
158
168
|
user = self.class.find(input)
|
@@ -160,11 +170,9 @@ module Scrivito
|
|
160
170
|
end
|
161
171
|
end
|
162
172
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
description: description,
|
167
|
-
}
|
173
|
+
# Per convention only anonymous admin has a nil id.
|
174
|
+
def system_user?
|
175
|
+
id.nil?
|
168
176
|
end
|
169
177
|
|
170
178
|
private
|
@@ -176,5 +184,15 @@ module Scrivito
|
|
176
184
|
def assert_valid_verb(verb)
|
177
185
|
raise ScrivitoError.new("Invalid verb '#{verb}'") unless VERBS.include?(verb)
|
178
186
|
end
|
187
|
+
|
188
|
+
def sandbox_suggest_user_proc(input)
|
189
|
+
suggest_users_proc.call(input)
|
190
|
+
rescue Exception => e
|
191
|
+
Rails.logger.error(%{
|
192
|
+
Method `suggest_users' of the user "#{id}" raised an error on input "#{input}": #{e}
|
193
|
+
#{e.backtrace.join("\n")}
|
194
|
+
})
|
195
|
+
nil
|
196
|
+
end
|
179
197
|
end
|
180
198
|
end
|