scrivito_sdk 0.66.0 → 0.70.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/blobs_controller.rb +5 -0
  3. data/app/controllers/scrivito/objs_controller.rb +2 -1
  4. data/app/controllers/scrivito/ui_controller.rb +33 -3
  5. data/app/helpers/scrivito_helper.rb +14 -20
  6. data/app/views/scrivito/objs/update.json.jbuilder +1 -1
  7. data/app/views/scrivito/ui/index.html.erb +1 -1
  8. data/app/views/scrivito/webservice/_workspace.json.jbuilder +2 -1
  9. data/config/ca-bundle.crt +1 -1
  10. data/config/precedence_routes.rb +3 -2
  11. data/lib/assets/javascripts/scrivito.js +46 -0
  12. data/lib/assets/javascripts/scrivito_ui.js +931 -501
  13. data/lib/assets/stylesheets/scrivito.css +1 -0
  14. data/lib/assets/stylesheets/scrivito_ui.css +1 -1
  15. data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +3 -3
  16. data/lib/generators/scrivito/page/page_generator.rb +3 -0
  17. data/lib/generators/scrivito/page/templates/model.erb +3 -0
  18. data/lib/generators/scrivito/widget/templates/model.erb +3 -0
  19. data/lib/generators/scrivito/widget/widget_generator.rb +3 -0
  20. data/lib/scrivito/attribute_content.rb +93 -60
  21. data/lib/scrivito/attribute_definition.rb +3 -3
  22. data/lib/scrivito/attribute_serializer.rb +2 -2
  23. data/lib/scrivito/backend/obj_data_cache.rb +22 -9
  24. data/lib/scrivito/basic_obj.rb +238 -130
  25. data/lib/scrivito/basic_widget.rb +32 -20
  26. data/lib/scrivito/binary.rb +74 -45
  27. data/lib/scrivito/binary_routing.rb +52 -0
  28. data/lib/scrivito/cache_middleware.rb +0 -5
  29. data/lib/scrivito/client_attribute_serializer.rb +134 -0
  30. data/lib/scrivito/cms_backend.rb +51 -33
  31. data/lib/scrivito/cms_data_cache.rb +1 -0
  32. data/lib/scrivito/cms_dispatch_controller.rb +1 -1
  33. data/lib/scrivito/cms_env.rb +1 -11
  34. data/lib/scrivito/cms_field_tag.rb +10 -7
  35. data/lib/scrivito/cms_rest_api/rate_limit.rb +5 -5
  36. data/lib/scrivito/cms_rest_api/request_timer.rb +27 -0
  37. data/lib/scrivito/cms_rest_api/widget_extractor.rb +8 -6
  38. data/lib/scrivito/cms_rest_api.rb +107 -54
  39. data/lib/scrivito/cms_routing.rb +13 -25
  40. data/lib/scrivito/configuration.rb +5 -2
  41. data/lib/scrivito/controller_actions.rb +68 -7
  42. data/lib/scrivito/controller_runtime.rb +8 -0
  43. data/lib/scrivito/date_attribute.rb +8 -0
  44. data/lib/scrivito/errors.rb +6 -3
  45. data/lib/scrivito/generator_helper.rb +13 -0
  46. data/lib/scrivito/image_tag.rb +24 -30
  47. data/lib/scrivito/layout_tags.rb +12 -6
  48. data/lib/scrivito/link.rb +46 -30
  49. data/lib/scrivito/log_subscriber.rb +15 -0
  50. data/lib/scrivito/membership.rb +3 -3
  51. data/lib/scrivito/membership_collection.rb +10 -10
  52. data/lib/scrivito/meta_data_collection.rb +22 -0
  53. data/lib/scrivito/model_library.rb +7 -1
  54. data/lib/scrivito/obj_collection.rb +18 -16
  55. data/lib/scrivito/obj_params_parser.rb +1 -1
  56. data/lib/scrivito/obj_search_enumerator.rb +35 -35
  57. data/lib/scrivito/page_config.rb +55 -0
  58. data/lib/scrivito/request_homepage.rb +23 -0
  59. data/lib/scrivito/routing_helper.rb +8 -8
  60. data/lib/scrivito/sdk_engine.rb +2 -3
  61. data/lib/scrivito/ui_config.rb +85 -0
  62. data/lib/scrivito/user.rb +30 -23
  63. data/lib/scrivito/user_definition.rb +48 -47
  64. data/lib/scrivito/widget_tag.rb +11 -0
  65. data/lib/scrivito/workspace.rb +93 -35
  66. data/lib/scrivito/workspace_selection_middleware.rb +8 -1
  67. data/lib/scrivito_sdk.rb +24 -24
  68. metadata +24 -33
  69. data/lib/assets/javascripts/scrivito_sdk.js +0 -57
  70. data/lib/assets/stylesheets/scrivito_sdk.css +0 -1
  71. data/lib/scrivito/client_config.rb +0 -113
  72. data/lib/scrivito/editing_context_helper.rb +0 -19
  73. data/lib/scrivito/named_link.rb +0 -39
@@ -1,5 +1,5 @@
1
1
  module Scrivito
2
- # This class allows you to retrieve Objects from a specific working copy.
2
+ # This class allows you to retrieve CMS objects from a specific working copy.
3
3
  # You can get an instance by accessing {Workspace#objs}.
4
4
  # @api public
5
5
  class ObjCollection
@@ -9,8 +9,9 @@ module Scrivito
9
9
  @workspace = workspace
10
10
  end
11
11
 
12
- # Find a {BasicObj Obj} by its id.
13
- # If the parameter is an Array containing ids, return a list of corresponding Objs.
12
+ # Find an {BasicObj Obj} by its id.
13
+ # If the parameter is an Array containing ids, return a list of the
14
+ # corresponding {Scrivito::BasicObj Obj}s.
14
15
  # @param [String, Integer, Array<String, Integer>]id_or_list
15
16
  # @return [Obj, Array<Obj>]
16
17
  # @api public
@@ -19,8 +20,8 @@ module Scrivito
19
20
  end
20
21
 
21
22
  # Find a {BasicObj Obj} by its id.
22
- # If the parameter is an Array containing ids, return a list of corresponding Objs.
23
- # The results include deleted objects as well.
23
+ # If the parameter is an Array containing ids, return a list of the
24
+ # corresponding {Scrivito::BasicObj Obj}s. The results include deleted objects as well.
24
25
  # @param [String, Integer, Array<String, Integer>]id_or_list
25
26
  # @return [Obj, Array<Obj>]
26
27
  # @api public
@@ -28,8 +29,8 @@ module Scrivito
28
29
  find_using(id_or_list, :find_by_including_deleted)
29
30
  end
30
31
 
31
- # Find the {BasicObj Obj} with the given path.
32
- # Returns +nil+ if no matching Obj exists.
32
+ # Find the {BasicObj Obj} that has the given path.
33
+ # Returns +nil+ if no matching object exists.
33
34
  # @param [String] path Path of the {BasicObj Obj}.
34
35
  # @return [Obj]
35
36
  # @api public
@@ -37,7 +38,7 @@ module Scrivito
37
38
  find_by(:path, [path]).first.first
38
39
  end
39
40
 
40
- # Returns the {BasicObj Obj} with the given permalink, or +nil+ if no matching Obj exists.
41
+ # Returns the {BasicObj Obj} that has the given permalink, or +nil+ if no matching object exists.
41
42
  # @param [String] permalink The permalink of the {BasicObj Obj}.
42
43
  # @return [Obj]
43
44
  # @api public
@@ -45,11 +46,12 @@ module Scrivito
45
46
  find_by(:permalink, [permalink]).first.first
46
47
  end
47
48
 
48
- # Returns a {ObjSearchEnumerator} with the given initial subquery consisting of the four arguments.
49
+ # Returns an {ObjSearchEnumerator} with the given initial subquery consisting of the four arguments.
49
50
  #
50
- # Note that +field+ and +value+ can also be arrays for searching several fields or searching for several values.
51
+ # Note that +field+ and +value+ may also be arrays for searching several fields or searching for several values.
51
52
  #
52
- # {ObjSearchEnumerator}s can be chained using one of the chainable methods (e.g. {ObjSearchEnumerator#and} and {ObjSearchEnumerator#and_not}).
53
+ # {ObjSearchEnumerator}s can be chained using one of the chainable methods
54
+ # (e.g. {ObjSearchEnumerator#and} and {ObjSearchEnumerator#and_not}).
53
55
  #
54
56
  # @param [Symbol, String, Array<Symbol, String>] field See {ObjSearchEnumerator#and} for details
55
57
  # @param [Symbol, String] operator See {ObjSearchEnumerator#and} for details
@@ -62,15 +64,15 @@ module Scrivito
62
64
  .and(field, operator, value, boost)
63
65
  end
64
66
 
65
- # Returns a {ObjSearchEnumerator} of all {BasicObj Obj}s.
67
+ # Returns an {ObjSearchEnumerator} of all {BasicObj Obj}s.
66
68
  # @return [ObjSearchEnumerator]
67
69
  # @api public
68
70
  def all
69
71
  ObjSearchEnumerator.new(workspace).batch_size(1000)
70
72
  end
71
73
 
72
- # Returns a {ObjSearchEnumerator} of all Objs with the given +obj_class+.
73
- # @param [String] obj_class name of the obj class.
74
+ # Returns an {ObjSearchEnumerator} of all {BasicObj Obj}s with the given +obj_class+.
75
+ # @param [String] obj_class name of the object class.
74
76
  # @return [ObjSearchEnumerator]
75
77
  # @api public
76
78
  def find_all_by_obj_class(obj_class)
@@ -115,8 +117,8 @@ module Scrivito
115
117
  end
116
118
  end
117
119
 
118
- # accepts the name of an "obj_by" - view, a list of keys
119
- # returns a list of lists of Objs: a list of Objs for each given keys.
120
+ # Accepts the name of an "obj_by" view, a list of keys.
121
+ # Returns a list of lists of Objs: a list of Objs for each given key.
120
122
  def find_by_including_deleted(view, keys)
121
123
  result = CmsBackend.instance.find_obj_data_by(
122
124
  workspace.revision,
@@ -51,7 +51,7 @@ module Scrivito
51
51
  end
52
52
 
53
53
  def parse_date_params(params)
54
- DateAttribute.parse(params)
54
+ DateAttribute.parse_iso8601(params)
55
55
  end
56
56
  end
57
57
  end
@@ -1,38 +1,38 @@
1
1
  # encoding: UTF-8
2
2
  module Scrivito
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-2.1.3/Enumerable.html <code>Enumerable</code> mixin},
3
+ # Provides an enumerator for iterating over the results of searches for CMS objects to retrieve instances of these objects.
4
+ # This is achieved through 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
- # This enumerator is lazy. If for example you are looking for {BasicObj Obj}s with the obj class "Publication",
8
- # and there are 93 objs in total, than <code>enum.take(10)</code> will fetch the first 10 objs only,
9
- # ignoring the other 83 objs.
10
- # This also means, that iterating multiple times over this enumerator causes the search results and objs to be fetched again.
11
- # If you want to get all objs at once, use <code>enum.to_a</code>.
7
+ # This enumerator is lazy. If, for example, you are looking for {BasicObj Obj}s whose object class is "Publication",
8
+ # and there are 93 objects in total, then <code>enum.take(10)</code> fetches the first 10 objects only,
9
+ # ignoring the other 83.
10
+ # This implies that repeatedly iterating over this enumerator causes the search results and the objects to be fetched again and again.
11
+ # If you want to get all objects at once, use <code>enum.to_a</code>.
12
12
  #
13
- # To start searching use one of the {BasicObj Obj} methods that returns an {ObjSearchEnumerator}. The preferred way is to start with {BasicObj.where Obj.where}.
13
+ # To start searching, use one of the {BasicObj Obj} methods that return an {ObjSearchEnumerator}. The preferred way is to start with {BasicObj.where Obj.where}.
14
14
  #
15
15
  # == Currently available fields and their values
16
16
  #
17
17
  # [+:*+] Searches all fields.
18
- # This is only possible with the operators +contais+ or +starts_with+.
18
+ # This is only possible with the +contains+ and +starts_with+ operators.
19
19
  # [+:id+] Id of an {BasicObj Obj}. This is a +string+ field.
20
20
  # [+:_path+] Path of an {BasicObj Obj}. This is a +string+ field.
21
21
  # [+:_name+] Name of an {BasicObj Obj}. This is a +string+ field.
22
22
  # [+:title+] Title of an {BasicObj Obj}. This is a +string+ field.
23
23
  # [+:body+] Body of an {BasicObj Obj}. This is an +html+ field. Thus, only the +contains+ and
24
24
  # +contains_prefix+ operators can be applied to this field.
25
- # [+:_obj_class+] obj class of an {BasicObj Obj}. This is a +string+ field.
25
+ # [+:_obj_class+] Object class of an {BasicObj Obj}. This is a +string+ field.
26
26
  # [+:_permalink+] Permalink of an {BasicObj Obj}. This is a +string+ field.
27
27
  # [+:_last_changed+] Date of last change of an {BasicObj Obj}.
28
28
  # [every <em><code>:custom_attribute</code></em>] Custom attribute of an {BasicObj Obj}. Note that
29
29
  # depending on the attribute type (e.g. an
30
- # +html+ field), some operators can not be applied.
30
+ # +html+ field), some operators cannot be applied.
31
31
  #
32
32
  # All values are stored as strings.
33
33
  #
34
34
  # Date values are stored in the format YYYYMMDDHHMMSS in UTC. For example, 2000-01-01 00:00:00 UTC is stored as "<code>20000101000000</code>".
35
- # This is relevant for string comparisons using the +is_less_than+ and +is_greater_than+ operators.
35
+ # This is relevant for string comparisons in which the +is_less_than+ and +is_greater_than+ operators are used.
36
36
  #
37
37
  # == Currently available operators
38
38
  #
@@ -48,7 +48,7 @@ module Scrivito
48
48
  # ✘ "behi clo" (not whole words)
49
49
  #
50
50
  # ✘ "behind everything" (second word does not match)
51
- # [+:contains_prefix+] Searches for one prefix. A whole word is also a prefix.
51
+ # [+:contains_prefix+] Searches for one prefix. A whole word also counts as a prefix.
52
52
  #
53
53
  # Example subquery values:
54
54
  #
@@ -118,16 +118,16 @@ module Scrivito
118
118
 
119
119
  # @group Chainable methods
120
120
 
121
- # Adds this additional AND subquery to this {ObjSearchEnumerator}.
121
+ # Adds the given AND subquery to this {ObjSearchEnumerator}.
122
122
  #
123
123
  # Compares the +field(s)+ with the +value(s)+ using the +operator+ of this subquery.
124
- # All objs to which this criterion applies remain in the result set.
124
+ # All CMS objects to which this criterion applies remain in the result set.
125
125
  #
126
126
  # @param [Symbol, String, Array<Symbol, String>] field Name(s) of the field(s) to be searched.
127
- # For arrays, the subquery matches, if one or more of these fields meet this criterion.
128
- # @param [Symbol, String] operator See "Currently available operators" at the top.
129
- # @param [String, Array<String>] value The value(s) with which the field value(s) are compared using the +operator+ of this subquery.
130
- # For arrays, the subquery matches, if the condition is met for one or more of the array elements.
127
+ # For arrays, the subquery matches if one or more of these fields meet this criterion.
128
+ # @param [Symbol, String] operator See "Currently available operators" above.
129
+ # @param [String, Array<String>] value The value(s) to compare with the field value(s) using the +operator+ of this subquery.
130
+ # For arrays, the subquery matches if the condition is met for one or more of the array elements.
131
131
  # @param [Hash] boost A hash where the keys are field names and their values are boosting factors.
132
132
  # Boosting factors must be in the range from 1 to 10.
133
133
  # Boosting can only be applied to subqueries in which the +contains+ or +contains_prefix+ operator is used.
@@ -151,18 +151,18 @@ module Scrivito
151
151
  self
152
152
  end
153
153
 
154
- # Adds this additional negated AND subquery to this {ObjSearchEnumerator}.
154
+ # Adds the given negated AND subquery to this {ObjSearchEnumerator}.
155
155
  #
156
156
  # Compares the +field(s)+ with the +value(s)+ using the negated +operator+ of this subquery.
157
- # All objs to which this criterion applies are removed from the result set.
157
+ # All CMS objects to which this criterion applies are removed from the result set.
158
158
  #
159
159
  # @param [Symbol, String, Array<Symbol, String>] field Name(s) of the field(s) to be searched.
160
- # For arrays, the subquery matches, if one or more of these fields meet this criterion.
160
+ # For arrays, the subquery matches if one or more of these fields meet this criterion.
161
161
  # @param [Symbol, String] operator Only applicable to subqueries in which the +equals+,
162
- # +starts_with+, +is_greater_than+ and +is_less_than+ operator is used
163
- # (See "Currently available operators" at the top).
164
- # @param [String, Array<String>] value The value(s) with which the field value(s) are compared using the +operator+ of this subquery.
165
- # For arrays, the subquery matches, if the condition is met for one or more of the array elements.
162
+ # +starts_with+, +is_greater_than+ or +is_less_than+ operator is used.
163
+ # (See "Currently available operators" above).
164
+ # @param [String, Array<String>] value The value(s) to compare with the field value(s) using the +operator+ of this subquery.
165
+ # For arrays, the subquery matches if the condition is met for one or more of the array elements.
166
166
  # @return [ObjSearchEnumerator]
167
167
  # @api public
168
168
  def and_not(field, operator, value)
@@ -180,7 +180,7 @@ module Scrivito
180
180
  end
181
181
 
182
182
  # Orders the results by +field_name+.
183
- # @param [Symbol, String] field_name This parameter determines by which field the hits are sorted (e.g. +:_path+).
183
+ # @param [Symbol, String] field_name This parameter specifies the field by which the hits are sorted (e.g. +:_path+).
184
184
  # @return [ObjSearchEnumerator]
185
185
  # @api public
186
186
  def order(field_name)
@@ -189,7 +189,7 @@ module Scrivito
189
189
  self
190
190
  end
191
191
 
192
- # Reverses the order of the results. Requires {#order} to be specified before.
192
+ # Reverses the order of the results. Requires {#order} to be applied before.
193
193
  # @return [ObjSearchEnumerator]
194
194
  # @api public
195
195
  def reverse_order
@@ -201,7 +201,7 @@ module Scrivito
201
201
  end
202
202
 
203
203
  # Number of search results to be returned by each of the internal search requests.
204
- # The default is +10+. The server may limit a large batch size to a reasonable value.
204
+ # The default is +10+. The server may reduce large batches to a reasonable size.
205
205
  # @param [Integer] size A value in the range from +1+ to +100+.
206
206
  # @return [ObjSearchEnumerator]
207
207
  # @api public
@@ -212,7 +212,7 @@ module Scrivito
212
212
  end
213
213
 
214
214
 
215
- # Omits the first +amount+ number of {BasicObj Obj}s from the results. The default is +0+.
215
+ # Omits the first +amount+ of {BasicObj Obj}s from the results. The default is +0+.
216
216
  # @param [Integer] amount
217
217
  # @return [ObjSearchEnumerator]
218
218
  # @api public
@@ -272,10 +272,10 @@ module Scrivito
272
272
  @size ||= CmsBackend.instance.search_objs(workspace, size_query)['total'].to_i
273
273
  end
274
274
 
275
- # load a single batch of search results from the backend.
276
- # returns an array of Objs.
277
- # will usually return `batch_size` results if available,
278
- # but may occasionally return fewer than `batch_size` results (due to rate limit, for example).
275
+ # Loads a single batch of search results from the backend.
276
+ # @return [Array] of {BasicObj Obj}.
277
+ # Usually returns +batch_size+ results if available,
278
+ # but may occasionally return fewer than +batch_size+ results (due to rate limit, for example).
279
279
  # @api public
280
280
  def load_batch
281
281
  next_batch = fetch_next_batch(options[:offset] || 0)
@@ -305,7 +305,7 @@ module Scrivito
305
305
  if value.is_a?(Time) || value.is_a?(Date)
306
306
  DateAttribute.serialize(value)
307
307
  else
308
- value
308
+ value.to_s
309
309
  end
310
310
  end
311
311
 
@@ -0,0 +1,55 @@
1
+ module Scrivito
2
+
3
+ class PageConfig < Struct.new(:obj, :editing_context, :lookup_context)
4
+
5
+ def initialize(**named_params)
6
+ named_params.each { |key, value| self[key] = value }
7
+ end
8
+
9
+ def to_json
10
+ {
11
+ current_page: current_page_config,
12
+ user_id: user_id_config,
13
+ }.to_json
14
+ end
15
+
16
+ private
17
+
18
+ def user_id_config
19
+ editor.id
20
+ end
21
+
22
+ def current_page_config
23
+ return {} unless obj
24
+ {
25
+ id: obj.id,
26
+ obj_class_name: obj.obj_class_name,
27
+ has_children: obj.children.any?,
28
+ has_conflict: obj.has_conflict?,
29
+ has_details_view: obj_has_details_view?,
30
+ modification: modification(obj),
31
+ restriction_messages: editor.restriction_messages_for(obj),
32
+ }
33
+ end
34
+
35
+ def obj_has_details_view?
36
+ lookup_context.find(obj.details_view_path).present?
37
+ rescue ActionView::MissingTemplate
38
+ false
39
+ end
40
+
41
+ def modification(obj_or_resource)
42
+ comparison = editing_context.comparison
43
+ if comparison.active?
44
+ comparison.modification(obj_or_resource)
45
+ else
46
+ obj_or_resource.modification
47
+ end
48
+ end
49
+
50
+ def editor
51
+ editing_context.editor
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,23 @@
1
+ module Scrivito
2
+ module RequestHomepage
3
+ HOMEPAGE_ENV_KEY = "SCRIVITO_HOMEPAGE"
4
+
5
+ class << self
6
+ def call(env)
7
+ env[HOMEPAGE_ENV_KEY] ||= fetch_homepage(env)
8
+ end
9
+
10
+ private
11
+
12
+ def fetch_homepage(env)
13
+ callback_result = Scrivito::Configuration.choose_homepage_callback.call(env)
14
+ if callback_result.is_a?(Obj)
15
+ callback_result
16
+ else
17
+ raise "choose_homepage callback did not return an Obj. "\
18
+ "Instead saw #{callback_result.class}."
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,21 +1,21 @@
1
1
  module Scrivito
2
2
  #
3
- # The helper contains methods to generate URLs to CMS content.
3
+ # This helper contains methods for generating URLs that point to CMS content.
4
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.
5
+ # redirecting to CMS objects. These methods are available in both your views and your controllers.
6
6
  #
7
7
  # @api public
8
8
  #
9
9
  module RoutingHelper
10
10
  #
11
- # Returns the (URL-)path for a cms object.
11
+ # Returns the (URL-)path of a CMS object.
12
12
  #
13
13
  # @api public
14
14
  #
15
15
  # @param target [Obj, Link, Array<Link>, Binary]
16
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.
17
+ # Only the first {Link} of the +Array+ is used.
18
+ # @param options [Hash] include url settings such as path parameters or the protocol.
19
19
  #
20
20
  # @return [String]
21
21
  #
@@ -24,14 +24,14 @@ module Scrivito
24
24
  end
25
25
 
26
26
  #
27
- # Returns the absolute URL for a cms object.
27
+ # Returns the absolute URL of a CMS object.
28
28
  #
29
29
  # @api public
30
30
  #
31
31
  # @param target [Obj, Link, Array<Link>, Binary]
32
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.
33
+ # Only the first {Link} of the +Array+ is used.
34
+ # @param options [Hash] include url settings such as path parameters or the protocol.
35
35
  #
36
36
  # @return [String]
37
37
  #
@@ -1,7 +1,6 @@
1
1
  require 'rails'
2
2
 
3
3
  require 'jbuilder'
4
- require 'jquery-rails'
5
4
  require 'net/http/post/multipart'
6
5
 
7
6
  module ::Scrivito
@@ -43,8 +42,8 @@ module ::Scrivito
43
42
  initializer 'scrivito.add_sdk_assets' do |app|
44
43
  # Specify which file should be precompiled for packaging
45
44
  app.config.assets.precompile += %w[
46
- scrivito_sdk.css
47
- scrivito_sdk.js
45
+ scrivito.css
46
+ scrivito.js
48
47
  scrivito_ui.css
49
48
  scrivito_ui.js
50
49
  ]
@@ -0,0 +1,85 @@
1
+ module Scrivito
2
+
3
+ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extension_tags)
4
+ def initialize(**named_params)
5
+ named_params.each { |key, value| self[key] = value }
6
+ end
7
+
8
+ def to_json
9
+ {
10
+ editing_context: editing_context_config,
11
+ i18n: i18n_config,
12
+ is_development_mode: Rails.env.development?,
13
+ resource_dialog: resource_dialog_config,
14
+ user: user_config,
15
+ user_permissions: user_permissions_config,
16
+ app_extension_tags: app_extension_tags,
17
+ }.to_json
18
+ end
19
+
20
+ private
21
+
22
+ def editing_context_config
23
+ {
24
+ display_mode: editing_context.display_mode,
25
+ selected_workspace: workspace_config(selected_workspace),
26
+ visible_workspace: workspace_config(visible_workspace),
27
+ }
28
+ end
29
+
30
+ def workspace_config(workspace)
31
+ {
32
+ id: workspace.id,
33
+ memberships: workspace.memberships.map do |membership|
34
+ {
35
+ user_id: membership.user_id,
36
+ role: membership.role,
37
+ description: membership.user.description
38
+ }
39
+ end,
40
+ outdated: workspace.outdated?,
41
+ title: workspace.title,
42
+ }
43
+ end
44
+
45
+ def i18n_config
46
+ {locale: Scrivito::Configuration.ui_locale || I18n.locale}
47
+ end
48
+
49
+ def resource_dialog_config
50
+ return {} unless resource
51
+ {
52
+ obj: Configuration.obj_formats.fetch('_default').call(resource, editor),
53
+ return_to: return_to,
54
+ }
55
+ end
56
+
57
+ def user_permissions_config
58
+ {
59
+ create_workspace: editor.can?(:create, :workspace),
60
+ publish_workspace: editor.can?(:publish, selected_workspace),
61
+ }
62
+ end
63
+
64
+ def user_config
65
+ {
66
+ current: {
67
+ id: editor.id
68
+ }
69
+ }
70
+ end
71
+
72
+ def editor
73
+ editing_context.editor
74
+ end
75
+
76
+ def selected_workspace
77
+ editing_context.selected_workspace
78
+ end
79
+
80
+ def visible_workspace
81
+ editing_context.visible_workspace
82
+ end
83
+ end
84
+
85
+ end
data/lib/scrivito/user.rb CHANGED
@@ -22,9 +22,9 @@ module Scrivito
22
22
  #
23
23
  # @api public
24
24
  #
25
- # @param [String] id the unique, unalterable id of the user.
25
+ # @param [String] id The unique, unalterable id of the user.
26
26
  # The user id is used to associate the user with the corresponding CMS resources.
27
- # It will be persisted in the CMS.
27
+ # It is persisted in the CMS.
28
28
  #
29
29
  # @raise [Scrivito::ScrivitoError] if id is blank
30
30
  # @raise [Scrivito::ScrivitoError] if id is more than 64 characters long
@@ -38,21 +38,21 @@ module Scrivito
38
38
  # @see Scrivito::UserDefinition#suggest_users
39
39
  #
40
40
  # @example
41
- # Scrivito::User.define('alice') do |user|
42
- # user.description { 'Alice Almighty' }
41
+ # Scrivito::User.define('alice') do |user_definition|
42
+ # user_definition.description { 'Alice Almighty' }
43
43
  #
44
- # user.can_always(:read, :workspace)
45
- # user.can_always(:write, :workspace)
46
- # user.can_always(:publish, :workspace, 'You can always publish workspaces.')
44
+ # user_definition.can_always(:read, :workspace)
45
+ # user_definition.can_always(:write, :workspace)
46
+ # user_definition.can_always(:publish, :workspace, 'You can always publish workspaces.')
47
47
  # end
48
48
  #
49
- # Scrivito::User.define('bob') do |user|
50
- # user.description('Bob Doe')
49
+ # Scrivito::User.define('bob') do |user_definition|
50
+ # user_definition.description('Bob Doe')
51
51
  #
52
- # user.can_never(:create, :workspace, 'You are not allowed to create workspaces.')
53
- # user.can_always(:read, :workspace)
52
+ # user_definition.can_never(:create, :workspace, 'You are not allowed to create workspaces.')
53
+ # user_definition.can_always(:read, :workspace)
54
54
  #
55
- # user.restrict_obj_publish(using: :_obj_class_name) do |obj_class_name|
55
+ # user_definition.restrict_obj_publish(using: :_obj_class_name) do |obj_class_name|
56
56
  # if obj_class_name == 'BlogPost'
57
57
  # false
58
58
  # else
@@ -67,8 +67,15 @@ module Scrivito
67
67
  end
68
68
 
69
69
  #
70
- # Returns an anonymous system user, who can always create workspaces, can always read, write,
71
- # publish, delete and invite to any workspace.
70
+ # Returns an anonymous system user who can always create workspaces, can always read, write,
71
+ # publish, delete, and invite others to collaborate on any workspace.
72
+ # @example Check whether the user may publish a particular object:
73
+ # Scrivito::User.system_user.can_publish?(Obj.root)
74
+ # # => true
75
+ #
76
+ # @example Get the notification messages for publishing restrictions. An empty array indicates that no restrictions exist.
77
+ # Scrivito::User.system_user.restriction_messages_for(Obj.root)
78
+ # # => []
72
79
  #
73
80
  # @api public
74
81
  # @return [Scrivito::User] the system user
@@ -145,24 +152,24 @@ module Scrivito
145
152
  end
146
153
 
147
154
  #
148
- # Verifies if the User is able to publish changes to a certain {BasicObj Obj}
155
+ # Checks whether the User may publish changes to a specific {Scrivito::BasicObj Obj}.
149
156
  #
150
157
  # @api public
151
- # @param [BasicObj] obj the obj that should be published
152
- # @return [Boolean] true if the user is allowed to publish otherwise false
158
+ # @param [BasicObj] obj the object to be published
159
+ # @return [Boolean] true if the user is allowed to publish the object, otherwise false
153
160
  #
154
161
  def can_publish?(obj)
155
162
  restriction_messages_for(obj).empty?
156
163
  end
157
164
 
158
165
  #
159
- # Checks if the User is able to publish changes and returns the message
160
- # specified in a {UserDefinition#restrict_obj_publish} callback if they are not
161
- # If the user can publish the obj an empty array is returned
166
+ # Checks whether the User may publish changes to an {Scrivito::BasicObj Obj} and returns
167
+ # the message specified in a {UserDefinition#restrict_obj_publish} callback if they may not.
168
+ # If the user may publish the CMS object, an empty array is returned.
162
169
  #
163
170
  # @api public
164
- # @param [BasicObj] obj the obj that should be published
165
- # @return [Array<String>] Hints why the user can't publish
171
+ # @param [BasicObj] obj the object to be published
172
+ # @return [Array<String>] Hints on why the user cannot publish the object
166
173
  #
167
174
  def restriction_messages_for(obj)
168
175
  assert_restrictions_applicable(obj)
@@ -193,7 +200,7 @@ module Scrivito
193
200
  end
194
201
  end
195
202
 
196
- # Per convention only anonymous admin has a nil id.
203
+ # By convention, only the anonymous admin user has a +nil+ id.
197
204
  def system_user?
198
205
  id.nil?
199
206
  end