scrivito_sdk 1.11.0 → 1.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1573d7607de4def110eeba58f89dfc3979bf6f3
4
- data.tar.gz: 184a0d601bd86625525adc9389bd8b55819023d8
3
+ metadata.gz: efd3bed6bd4541b87b1b2f29aca12b7f52b1987f
4
+ data.tar.gz: 50ec7bd514f1eb7753fad198e5e94fc76ccb5d24
5
5
  SHA512:
6
- metadata.gz: 0718021d9b1e40a36f516343bc5db251149163d94351b2ca7bb09213cb9932065c2b93e2b3a41f680b795ede481ead7ad79a6ac13becc5a7d71ab8ec0c02f59b
7
- data.tar.gz: e91555d9f7f889963b9ea417b85826d190c95ccdf926375d76f0701fcc35a0919f435d4d4bf73cea9f4a4186ae920864899b75e0d757546a4798aadc162c88c8
6
+ metadata.gz: b299c648eda1d976a51e0166cc21916af96b70df1e33c8e2109af73ea9e6c047b843d682371fdc8814ce0efa67a5a882fee1148a24c809ad8574ed84fdfda452
7
+ data.tar.gz: 3b96d94c18acf4e6c517922f57f64bed70aad55de66d76ed122048983a204f0a790e4a78f05b8e6676d8af8df04586b5d9287f49be1412f61ebdf7307bcba510
@@ -556,14 +556,14 @@ module AttributeContent
556
556
  # end
557
557
  # end
558
558
  #
559
+ # MyUser.find_by(email: 'alice@scrivito.com').preferences[:locale] # => 'en'
559
560
  # alice = Scrivito::User.define('alice@scrivito.com')
560
- # alice.preferences[:locale] # => 'en'
561
561
  #
562
562
  # my_page = MyPage.create({_path: '/de/test'}, alice)
563
563
  # my_page.title # => 'Your title here'
564
564
  #
565
+ # MyUser.find_by(email: 'bob@scrivito.com').preferences[:locale] # => 'de'
565
566
  # bob = Scrivito::User.define('bob@scrivito.com')
566
- # bob.preferences[:locale] # => 'de'
567
567
  #
568
568
  # my_page = MyPage.create({_path: '/en/test'}, bob)
569
569
  # my_page.title # => 'Hier den Titel eingeben'
@@ -59,7 +59,7 @@ module Scrivito
59
59
  include Associations
60
60
 
61
61
  def self.type_computer
62
- @_type_computer ||= TypeComputer.new(Scrivito::BasicObj, ::Obj)
62
+ @_type_computer ||= TypeComputer.new(BasicObj, ::Obj)
63
63
  end
64
64
 
65
65
  def self.reset_type_computer!
@@ -164,7 +164,7 @@ module Scrivito
164
164
  end
165
165
 
166
166
  private_class_method def self.assert_not_basic_obj(method_name)
167
- if self == Scrivito::BasicObj
167
+ if self == BasicObj
168
168
  raise ScrivitoError, "Can not call #{method_name} on Scrivito::BasicObj."\
169
169
  " Only call it on Obj or subclasses of Obj"
170
170
  end
@@ -264,7 +264,7 @@ module Scrivito
264
264
  # @api public
265
265
  def self.where(field, operator, value, boost = nil)
266
266
  assert_not_basic_obj('.where')
267
- if self == ::Obj
267
+ if type_computer.special_class?(self)
268
268
  Workspace.current.objs.where(field, operator, value, boost)
269
269
  else
270
270
  Workspace.current.objs.where(:_obj_class, :equals, name)
@@ -279,7 +279,7 @@ module Scrivito
279
279
  # @api public
280
280
  def self.all
281
281
  assert_not_basic_obj('.all')
282
- if self == ::Obj
282
+ if type_computer.special_class?(self)
283
283
  Workspace.current.objs.all
284
284
  else
285
285
  find_all_by_obj_class(name)
@@ -300,7 +300,8 @@ module Scrivito
300
300
  # @return [Obj]
301
301
  # @api public
302
302
  def self.find_by_path(path)
303
- Workspace.current.objs.find_by_path(path)
303
+ Workspace.current.objs.find_one_by(:path, path,
304
+ obj_class_name: type_computer.obj_class_name_for_type(self))
304
305
  end
305
306
 
306
307
  # Find an {Scrivito::BasicObj Obj} with the given name.
@@ -327,7 +328,8 @@ module Scrivito
327
328
  # @return [Obj]
328
329
  # @api public
329
330
  def self.find_by_permalink(permalink)
330
- Workspace.current.objs.find_by_permalink(permalink)
331
+ Workspace.current.objs.find_one_by(:permalink, permalink,
332
+ obj_class_name: type_computer.obj_class_name_for_type(self))
331
333
  end
332
334
 
333
335
  # Returns the {Scrivito::BasicObj Obj} with the given permalink, or raises
@@ -337,8 +339,10 @@ module Scrivito
337
339
  # @return [Obj]
338
340
  # @api public
339
341
  def self.find_by_permalink!(permalink)
340
- find_by_permalink(permalink) or
341
- raise ResourceNotFound, "Could not find Obj with permalink '#{permalink}'"
342
+ find_by_permalink(permalink) or begin
343
+ model_name = type_computer.obj_class_name_for_type(self) || 'Obj'
344
+ raise ResourceNotFound, "Could not find #{model_name} with permalink '#{permalink}'"
345
+ end
342
346
  end
343
347
 
344
348
  # Hook method that lets you control which page classes are made available for pages with the given path.
@@ -18,7 +18,7 @@ module Scrivito
18
18
  end
19
19
 
20
20
  updated_attributes.each do |attribute_name, value|
21
- if value.is_a?(Array) && value.all? {|w| w.is_a?(BasicWidget)}
21
+ if value.is_a?(Array) && value.all? { |w| w.is_a?(BasicWidget) }
22
22
  value.each do |widget|
23
23
  unless widget.persisted?
24
24
  attach_widget_to_obj(widget, obj)
@@ -11,7 +11,7 @@ module Scrivito
11
11
  #
12
12
  DEFAULT_CA_FILE = File.expand_path('../../../../config/ca-bundle.crt', __FILE__)
13
13
 
14
- # Determine if current visitor is permitted to edit content.
14
+ # Determine if the current visitor is permitted to edit content.
15
15
  def self.find_user_proc=(value)
16
16
  @find_user_proc = value
17
17
  end
@@ -21,15 +21,15 @@ module Scrivito
21
21
  end
22
22
 
23
23
  #
24
- # Configures a callback to be invoked when the SDK determines whether current visitor is
24
+ # Configures a callback to be invoked when the SDK determines whether the current visitor is
25
25
  # permitted to edit content.
26
26
  #
27
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
28
+ # assume that the current visitor is {Scrivito::User.system_user}, who can always create
29
29
  # workspaces, can always read, write, publish, delete and invite to any workspace.
30
30
  #
31
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
32
+ # +staging+), then the SDK will assume that the current visitor is not permitted to edit
33
33
  # content.
34
34
  #
35
35
  # @api public
@@ -58,14 +58,14 @@ module Scrivito
58
58
  @editing_auth_callback || default_editing_auth_callback
59
59
  end
60
60
 
61
- # Configures how to find users for the in-place GUI.
61
+ # Configures how to find users for the in-place UI.
62
62
  # @api public
63
63
  # @param [Proc] find_user_proc proc for finding a user by the user id
64
64
  # @yieldparam [String] user_id id of the user
65
65
  # @yieldreturn [Scrivito::User] if the user with the given user id was found
66
66
  # @yieldreturn [NilClass] if the user with the given user id was not found
67
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
68
+ # @note This configuration key is optional. If it is not configured the in-place UI would
69
69
  # behave normally, but would not be able to find any users.
70
70
  # @example Return a "dummy" {Scrivito::User}
71
71
  # Scrivito.configure do |config|
@@ -110,10 +110,10 @@ module Scrivito
110
110
  #
111
111
  # Sets the second level cache.
112
112
  #
113
- # If it is set, then +Scrivito+ will additionaly store its cache in both: the filesystem cache
113
+ # If it is set, then +Scrivito+ will additionally store its cache in both: the filesystem cache
114
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.
115
+ # a search in the filesystem cache returns no results. If the second level cache returns
116
+ # results, then the results will be stored in the filesystem cache.
117
117
  #
118
118
  # By default it is not set.
119
119
  #
@@ -271,9 +271,12 @@ module Scrivito
271
271
  # Configures the in-place UI to use a locale different from the one used by the rest of the
272
272
  # application.
273
273
  #
274
+ # This configuration overrides the browser-based UI language detection.
275
+ # The per-user {UserDefinition#ui_locale UI language definition} overrides this.
276
+ #
274
277
  # @api public
275
278
  # @example
276
- # # The application will use +:de+ as locale.
279
+ # # The application will use +:de+ as the locale.
277
280
  # I18n.locale = :de
278
281
  #
279
282
  # Scrivito.configure do |config|
@@ -293,8 +296,8 @@ module Scrivito
293
296
  # @deprecated The legacy routing is deprecated and will be removed in the next major
294
297
  # version of Scrivito.
295
298
  #
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.
299
+ # Scrivito changed its routing to a slug-first url scheme. This configuration option
300
+ # allows you to switch back to the old id-first url scheme.
298
301
  def self.legacy_routing
299
302
  @legacy_routing
300
303
  end
@@ -364,7 +367,7 @@ scrivito_route '/*permalink', using: 'permalink', via: all
364
367
  # When delivering binary Objs, the default image transformation will be applied.
365
368
  #
366
369
  # 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.
370
+ # +Hash+). Set it to +false+ to disable the default image transformation completely.
368
371
  #
369
372
  # @param [Hash] value the {Scrivito::Binary#transform transformation definition}
370
373
  #
@@ -417,7 +420,7 @@ scrivito_route '/*permalink', using: 'permalink', via: all
417
420
 
418
421
  def self.register_obj_format(name, &block)
419
422
  if name.start_with? '_'
420
- raise InvalidFormatNameError.new('Format names starting with underscore are not allowed.')
423
+ raise InvalidFormatNameError, 'Format names starting with an underscore are not allowed.'
421
424
  else
422
425
  obj_formats[name] = block
423
426
  end
@@ -42,7 +42,7 @@ module Scrivito
42
42
  end
43
43
 
44
44
  #
45
- # Returns whether the GUI is in the +editable+ view.
45
+ # Returns whether the UI is in the +editable+ view.
46
46
  #
47
47
  # @api public
48
48
  #
@@ -43,7 +43,7 @@ module Scrivito
43
43
  # @return [NilClass] if no {Scrivito::BasicObj Obj} with the given +path+ exists.
44
44
  #
45
45
  def find_by_path(path)
46
- find_by(:path, [path]).first.min_by(&:id)
46
+ find_one_by(:path, path)
47
47
  end
48
48
 
49
49
  #
@@ -60,7 +60,7 @@ module Scrivito
60
60
  # @return [NilClass] if no {Scrivito::BasicObj Obj} with the given +permalink+ exists.
61
61
  #
62
62
  def find_by_permalink(permalink)
63
- find_by(:permalink, [permalink]).first.min_by(&:id)
63
+ find_one_by(:permalink, permalink)
64
64
  end
65
65
 
66
66
  # Returns an {ObjSearchEnumerator} with the given initial subquery consisting of the
@@ -98,6 +98,10 @@ module Scrivito
98
98
  all.and(:_obj_class, :equals, obj_class)
99
99
  end
100
100
 
101
+ def find_one_by(view, value, **options)
102
+ find_by(view, [value], options).first.min_by(&:id)
103
+ end
104
+
101
105
  def find_by_parent_path(path)
102
106
  find_by(:ppath, [path]).first
103
107
  end
@@ -134,24 +138,24 @@ module Scrivito
134
138
  end
135
139
  end
136
140
 
137
- def find_by(view, keys)
138
- find_by_including_deleted(view, keys).map do |list|
139
- list.reject(&:deleted?)
140
- end
141
+ def find_by(view, keys, **options)
142
+ find_by_including_deleted(view, keys, options).each { |objs| objs.reject!(&:deleted?) }
141
143
  end
142
144
 
143
145
  # Accepts the name of an "obj_by" view, a list of keys.
144
146
  # Returns a list of lists of Objs: a list of Objs for each given key.
145
- def find_by_including_deleted(view, keys)
146
- result = CmsBackend.find_obj_data_by(
147
- workspace.revision,
148
- view,
149
- keys)
150
-
151
- result.map do |list|
152
- list.map do |obj_data|
147
+ def find_by_including_deleted(view, keys, obj_class_name: nil)
148
+ revision = workspace.revision
149
+ CmsBackend.find_obj_data_by(revision, view, keys).map do |obj_datas|
150
+ if obj_class_name
151
+ obj_datas = obj_datas.select do |obj_data|
152
+ obj_class_name == obj_data.value_of('_obj_class')
153
+ end
154
+ end
155
+
156
+ obj_datas.map do |obj_data|
153
157
  obj = BasicObj.instantiate(obj_data)
154
- obj.revision = workspace.revision
158
+ obj.revision = revision
155
159
 
156
160
  obj
157
161
  end
@@ -18,9 +18,7 @@ module Scrivito
18
18
  #
19
19
  # @return [String]
20
20
  # @api public
21
- def name
22
- @name
23
- end
21
+ attr_reader :name
24
22
 
25
23
  # Total number of Objs available that have this value.
26
24
  #
@@ -29,9 +27,7 @@ module Scrivito
29
27
  #
30
28
  # @return [Integer]
31
29
  # @api public
32
- def count
33
- @count
34
- end
30
+ attr_reader :count
35
31
 
36
32
  # The Objs that were included in this search.
37
33
  #
@@ -41,9 +37,7 @@ module Scrivito
41
37
  #
42
38
  # @return [Array<BasicObj>]
43
39
  # @api public
44
- def included_objs
45
- @included_objs
46
- end
40
+ attr_reader :included_objs
47
41
 
48
42
  end
49
43
  end
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
 
3
3
  require 'jbuilder'
4
+ require 'jquery-rails'
4
5
  require 'net/http/post/multipart'
5
6
  require_relative './legacy_switch'
6
7
  require_relative './errors'
@@ -5,8 +5,8 @@ class TypeComputer
5
5
  @base_class, @fallback_class = base_class, fallback_class
6
6
  end
7
7
 
8
- def compute_type(obj_class)
9
- load_class(obj_class) || @fallback_class
8
+ def compute_type(obj_class_name)
9
+ load_class(obj_class_name) || @fallback_class
10
10
  end
11
11
 
12
12
  def compute_type_without_fallback(obj_class_name)
@@ -21,17 +21,19 @@ class TypeComputer
21
21
  klass == @base_class || klass == @fallback_class
22
22
  end
23
23
 
24
+ def obj_class_name_for_type(klass)
25
+ unless special_class?(klass)
26
+ klass.name
27
+ end
28
+ end
29
+
24
30
  private
25
31
 
26
32
  def load_class(obj_class)
27
33
  klass = obj_class.constantize
28
- klass if inherits_from_base?(klass)
34
+ klass if klass < @base_class
29
35
  rescue NameError
30
36
  end
31
-
32
- def inherits_from_base?(klass)
33
- klass.ancestors.include?(@base_class) && klass != @base_class
34
- end
35
37
  end
36
38
 
37
39
  end
@@ -22,7 +22,8 @@ class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extens
22
22
  private
23
23
 
24
24
  def i18n_config
25
- {locale: Scrivito::Configuration.ui_locale || I18n.locale}
25
+ locale = editor.try!(:ui_locale) || Scrivito::Configuration.ui_locale
26
+ {locale: locale}
26
27
  end
27
28
 
28
29
  def obj_class_config
@@ -131,14 +131,20 @@ module Scrivito
131
131
  end
132
132
  end
133
133
 
134
- attr_reader :id, :explicit_rules, :description_proc, :suggest_users_proc, :restriction_set
134
+ attr_reader :id
135
+ attr_reader :description_proc
136
+ attr_reader :explicit_rules
137
+ attr_reader :restriction_set
138
+ attr_reader :suggest_users_proc
139
+ attr_reader :ui_locale
135
140
 
136
141
  def initialize(options)
137
142
  @id = options[:id]
138
- @explicit_rules = options[:explicit_rules]
139
143
  @description_proc = options[:description_proc]
140
- @suggest_users_proc = options[:suggest_users_proc]
144
+ @explicit_rules = options[:explicit_rules]
141
145
  @restriction_set = options[:restriction_set]
146
+ @suggest_users_proc = options[:suggest_users_proc]
147
+ @ui_locale = options[:ui_locale]
142
148
 
143
149
  @explicit_rules.each { |rule| assert_valid_verb(rule.second) }
144
150
  @explicit_rules_set = Set.new(@explicit_rules.map { |rule| rule.take(3) })
@@ -22,7 +22,7 @@ module Scrivito
22
22
  #
23
23
  # @param [Symbol] verb the verb of the action (see {Scrivito::User::VERBS}).
24
24
  # @param [Symbol] subject the subject of the action. Currently, only +:workspace+ is supported.
25
- # @param [String] message optional message to be displayed in the UI.
25
+ # @param [String] message an optional message to be displayed in the UI.
26
26
  #
27
27
  # @raise [Scrivito::ScrivitoError] if the given verb is invalid
28
28
  # @raise [Scrivito::ScrivitoError] if the specified rule conflicts with a
@@ -57,7 +57,7 @@ module Scrivito
57
57
  #
58
58
  # @param [Symbol] verb the verb of the action (see {Scrivito::User::VERBS}).
59
59
  # @param [Symbol] subject the subject of the action. Currently, only +:workspace+ is supported.
60
- # @param [String] message optional message to be displayed in the UI.
60
+ # @param [String] message an optional message to be displayed in the UI.
61
61
  #
62
62
  # @raise [Scrivito::ScrivitoError] if the given verb is invalid
63
63
  # @raise [Scrivito::ScrivitoError] if the specified rule conflicts with a
@@ -82,7 +82,7 @@ module Scrivito
82
82
  end
83
83
 
84
84
  #
85
- # Enable the user to create workspaces, to read from, write to, publish, delete workspaces,
85
+ # Enables the user to create workspaces, to read from, write to, publish, delete workspaces,
86
86
  # and to invite others to collaborate on any workspace.
87
87
  #
88
88
  # @api public
@@ -92,21 +92,21 @@ module Scrivito
92
92
  end
93
93
 
94
94
  #
95
- # Defines the user description to be displayed in the in-place GUI, e.g. in the workspace menu.
95
+ # Defines the user description to be displayed in the in-place UI, e.g. in the workspace menu.
96
96
  #
97
97
  # @api public
98
98
  #
99
99
  # @param [String] description_string the description, defaults to the the user id.
100
- # @param [Proc] description_proc proc to calculate the description, defaults to the the user id.
100
+ # @param [Proc] description_proc a proc to calculate the description, defaults to the user id.
101
101
  #
102
- # @note The description is calculated "lazyly". The calculated description is cached.
102
+ # @note The description is calculated "lazily". The calculated description is cached.
103
103
  #
104
104
  # @see Scrivito::User.define
105
105
  #
106
- # @example Display the user +alice+ as "alice" in the in-place GUI:
106
+ # @example Displays the user +alice+ as "alice" in the in-place UI:
107
107
  # alice = Scrivito::User.define('alice')
108
108
  #
109
- # @example Display the user +bob+ as "Bob Doe" in the in-place GUI:
109
+ # @example Displays the user +bob+ as "Bob Doe" in the in-place UI:
110
110
  # bob = Scrivito::User.define('bob') do |user|
111
111
  # user.description('Bob Doe')
112
112
  # end
@@ -126,17 +126,17 @@ module Scrivito
126
126
  end
127
127
 
128
128
  #
129
- # Defines the proc for fetching users for autocompletion purposes in the in-place GUI.
129
+ # Defines the proc for fetching users for autocompletion purposes in the in-place UI.
130
130
  # User autocompletion is used in the settings dialog of a workspace.
131
131
  # If the proc is not set, {Scrivito::User.find} is used to fetch the suggested users,
132
132
  # assuming the input is part of the user id.
133
133
  #
134
134
  # @api public
135
135
  #
136
- # @note Only the first 20 users returned are displayed in the in-place GUI.
136
+ # @note Only the first 20 users returned are displayed in the in-place UI.
137
137
  # @note +suggest_users_proc+ may also be invoked with an empty string.
138
138
  #
139
- # @param [Proc] suggest_users_proc proc for fetching users to be suggested in the in-place GUI
139
+ # @param [Proc] suggest_users_proc proc for fetching users to be suggested in the in-place UI
140
140
  # @yieldparam [String] input an arbitrary string originating from the user autocompletion input field,
141
141
  # e.g. the first letters of a user name
142
142
  # @yieldreturn [Array<Scrivito::User>] users that were found on account of the given input string
@@ -168,7 +168,7 @@ module Scrivito
168
168
  # with this attribute.
169
169
  #
170
170
  # @param [Hash] options
171
- # @option options [Symbol] :using the attribute you with to refer to in the callback
171
+ # @option options [Symbol] :using the attribute you wish to refer to in the callback
172
172
  # @yield [attribute] the value of the specified attribute
173
173
  # @yieldreturn [String, false] either return a message for the user or +false+ if
174
174
  # no restriction applies
@@ -200,13 +200,35 @@ module Scrivito
200
200
  restriction_set.add(options, &block)
201
201
  end
202
202
 
203
+ #
204
+ # Lets you specify the user's in-place UI language.
205
+ #
206
+ # Overrides auto-detection from browser language.
207
+ # Overrides the application-wide scrivito {Configuration.ui_locale UI locale configuration}.
208
+ #
209
+ # @api public
210
+ #
211
+ # @param [String] language a language code (e.g. 'en')
212
+ #
213
+ # @see Scrivito::User.define
214
+ #
215
+ # @example Have +robert+ use a UI with German titles:
216
+ # robert = Scrivito::User.define('robert') do |user|
217
+ # user.ui_locale('de')
218
+ # end
219
+ #
220
+ def ui_locale(language)
221
+ @ui_locale = language
222
+ end
223
+
203
224
  def user
204
225
  User.new(
205
226
  id: @user_id,
206
227
  explicit_rules: @explicit_rules,
207
228
  description_proc: @description_proc,
208
229
  suggest_users_proc: @suggest_users_proc,
209
- restriction_set: restriction_set
230
+ restriction_set: restriction_set,
231
+ ui_locale: @ui_locale,
210
232
  )
211
233
  end
212
234
 
@@ -265,9 +265,7 @@ class Workspace
265
265
  # Returns the id of the workspace.
266
266
  # @api public
267
267
  # @return [String]
268
- def id
269
- @id
270
- end
268
+ attr_reader :id
271
269
 
272
270
  def revision_id
273
271
  data.revision_id