locomotivecms_steam 1.3.0.rc2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -5
  3. data/Gemfile.lock +84 -82
  4. data/config/locales/de.yml +7 -5
  5. data/config/locales/el.yml +154 -0
  6. data/config/locales/en.yml +6 -1
  7. data/config/locales/es.yml +7 -1
  8. data/config/locales/et.yml +4 -0
  9. data/config/locales/fr.yml +6 -1
  10. data/config/locales/it.yml +7 -1
  11. data/config/locales/nb.yml +5 -1
  12. data/config/locales/nl.yml +8 -0
  13. data/config/locales/pl.yml +8 -0
  14. data/config/locales/pt-BR.yml +6 -0
  15. data/config/locales/ru.yml +9 -1
  16. data/lib/locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb +1 -1
  17. data/lib/locomotive/steam/decorators/template_decorator.rb +1 -1
  18. data/lib/locomotive/steam/entities/content_entry.rb +4 -0
  19. data/lib/locomotive/steam/entities/content_type.rb +4 -0
  20. data/lib/locomotive/steam/entities/site.rb +2 -1
  21. data/lib/locomotive/steam/liquid/drops/content_entry.rb +1 -1
  22. data/lib/locomotive/steam/liquid/drops/site.rb +1 -1
  23. data/lib/locomotive/steam/middlewares/auth.rb +29 -3
  24. data/lib/locomotive/steam/models/concerns/validation.rb +7 -8
  25. data/lib/locomotive/steam/models/i18n_field.rb +4 -2
  26. data/lib/locomotive/steam/repositories/content_entry_repository.rb +9 -1
  27. data/lib/locomotive/steam/services.rb +1 -1
  28. data/lib/locomotive/steam/services/asset_host_service.rb +21 -17
  29. data/lib/locomotive/steam/services/auth_service.rb +93 -9
  30. data/lib/locomotive/steam/services/content_entry_service.rb +4 -1
  31. data/lib/locomotive/steam/version.rb +1 -1
  32. data/locomotivecms_steam.gemspec +10 -10
  33. data/spec/fixtures/default/app/content_types/accounts.yml +2 -1
  34. data/spec/fixtures/default/app/content_types/songs.yml +2 -2
  35. data/spec/fixtures/default/app/views/pages/account/sign_up.liquid +52 -0
  36. data/spec/fixtures/default/config/translations.yml +4 -0
  37. data/spec/fixtures/default/data/accounts.yml +1 -1
  38. data/spec/fixtures/default/data/songs.yml +1 -0
  39. data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
  40. data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
  41. data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
  42. data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
  43. data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
  44. data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
  45. data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
  46. data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
  47. data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
  48. data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
  49. data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
  50. data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
  51. data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
  52. data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
  53. data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
  54. data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
  55. data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
  56. data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
  57. data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
  58. data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
  59. data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
  60. data/spec/integration/repositories/page_repository_spec.rb +2 -2
  61. data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
  62. data/spec/integration/repositories/translation_repository_spec.rb +1 -1
  63. data/spec/integration/server/assets_spec.rb +1 -1
  64. data/spec/integration/server/auth_spec.rb +70 -0
  65. data/spec/integration/services/content_entry_service_spec.rb +1 -1
  66. data/spec/support/helpers.rb +1 -1
  67. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +1 -1
  68. data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +7 -7
  69. data/spec/unit/adapters/filesystem/yaml_loaders/translation_spec.rb +1 -1
  70. data/spec/unit/entities/content_entry_spec.rb +9 -0
  71. data/spec/unit/entities/content_type_spec.rb +7 -0
  72. data/spec/unit/entities/site_spec.rb +15 -0
  73. data/spec/unit/liquid/drops/content_entry_spec.rb +41 -2
  74. data/spec/unit/liquid/drops/site_spec.rb +2 -1
  75. data/spec/unit/liquid/filters/html_spec.rb +58 -1
  76. data/spec/unit/models/i18n_field_spec.rb +8 -0
  77. data/spec/unit/repositories/content_entry_repository_spec.rb +13 -0
  78. data/spec/unit/services/asset_host_service_spec.rb +27 -3
  79. data/spec/unit/services/auth_service_spec.rb +134 -8
  80. data/spec/unit/services/content_entry_service_spec.rb +1 -1
  81. metadata +27 -24
@@ -12,6 +12,7 @@ en:
12
12
  es: Spanish
13
13
  ru: Russian
14
14
  et: Estonian
15
+ el: Greek
15
16
 
16
17
  errors:
17
18
  syntax:
@@ -27,7 +28,11 @@ en:
27
28
  session_assign: "Syntax Error in 'session_assign' - Valid syntax: session_assign [var] = [source]"
28
29
  messages:
29
30
  blank: "can't be blank"
30
- unique: "must be unique"
31
+ taken: "must be unique"
32
+ confirmation: doesn't match %{attribute}
33
+ too_short:
34
+ one: is too short (minimum is 1 character)
35
+ other: is too short (minimum is %{count} characters)
31
36
 
32
37
  pagination:
33
38
  previous: "« Previous"
@@ -12,10 +12,16 @@ es:
12
12
  es: Español
13
13
  ru: Ruso
14
14
  et: Estonio
15
+ el: Griego
15
16
 
16
17
  errors:
17
18
  messages:
18
19
  blank: "no puede estar en blanco"
20
+ taken: ya está en uso
21
+ confirmation: no coincide
22
+ too_short:
23
+ one: "es demasiado corto (1 carácter mínimo)"
24
+ other: "es demasiado corto (%{count} caracteres mínimo)"
19
25
 
20
26
  pagination:
21
27
  previous: "« Anterior"
@@ -130,4 +136,4 @@ es:
130
136
  skip_last_comma: true
131
137
  words_connector: ", "
132
138
  two_words_connector: " y "
133
- last_word_connector: " y "
139
+ last_word_connector: " y "
@@ -12,10 +12,14 @@ et:
12
12
  es: Hispaania
13
13
  ru: Vene
14
14
  et: Eesti
15
+ el: Kreeka
15
16
 
16
17
  errors:
17
18
  messages:
18
19
  blank: "tühi"
20
+ taken: on juba võetud
21
+ confirmation: ei vasta kinnitusele
22
+ too_short: on liiga lühike (miinimum on %{count} tähemärki)
19
23
 
20
24
  pagination:
21
25
  previous: "« Eelmine"
@@ -13,11 +13,16 @@ fr:
13
13
  ru: Russe
14
14
  et: Estonien
15
15
  ja: Japonais
16
+ el: Grecque
16
17
 
17
18
  errors:
18
19
  messages:
19
20
  blank: "doit être rempli(e)"
20
- unique: "doit être unique"
21
+ taken: n'est pas disponible
22
+ confirmation: "ne concorde pas avec %{attribute}"
23
+ too_short:
24
+ one: est trop court (au moins un caractère)
25
+ other: est trop court (au moins %{count} caractères)
21
26
 
22
27
  pagination:
23
28
  previous: "« Précédent"
@@ -12,10 +12,16 @@ it:
12
12
  es: Spagnolo
13
13
  ru: Russo
14
14
  et: Estone
15
+ el: Greco
15
16
 
16
17
  errors:
17
18
  messages:
18
19
  blank: "non può essere lasciato in bianco"
20
+ taken: è già presente
21
+ confirmation: non coincide con %{attribute}
22
+ too_short:
23
+ one: è troppo corto (il minimo è 1 carattere)
24
+ other: è troppo corto (il minimo è %{count} caratteri)
19
25
 
20
26
  pagination:
21
27
  previous: "« Precedente"
@@ -152,4 +158,4 @@ it:
152
158
  skip_last_comma: true
153
159
  words_connector: ", "
154
160
  two_words_connector: " e "
155
- last_word_connector: " e "
161
+ last_word_connector: " e "
@@ -12,6 +12,7 @@ nb:
12
12
  es: Spansk
13
13
  ru: Russisk
14
14
  et: Estisk
15
+ el: Gresk
15
16
 
16
17
  date:
17
18
  formats:
@@ -20,6 +21,9 @@ nb:
20
21
  errors:
21
22
  messages:
22
23
  blank: "kan ikke være blank"
24
+ taken: er allerede i bruk
25
+ confirmation: er ikke lik %{attribute}
26
+ too_short: er for kort (minimum %{count} tegn)
23
27
 
24
28
  pagination:
25
29
  previous: "« Previous"
@@ -188,4 +192,4 @@ nb:
188
192
 
189
193
  percentage:
190
194
  format:
191
- delimiter: ""
195
+ delimiter: ""
@@ -4,16 +4,24 @@ nl:
4
4
  en: Engels
5
5
  de: Duits
6
6
  fr: Frans
7
+ pl: Pools
7
8
  pt-BR: "Braziliaans Portugees"
8
9
  it: Italiaans
9
10
  nl: Nederlands
10
11
  nb: Noors
12
+ es: Spaans
11
13
  ru: Russisch
12
14
  et: Estlands
15
+ el: Grieks
13
16
 
14
17
  errors:
15
18
  messages:
16
19
  blank: "mag niet leeg zijn"
20
+ taken: is al in gebruik
21
+ confirmation: komt niet overeen met %{attribute}
22
+ too_short:
23
+ one: is te kort (minimaal %{count} teken)
24
+ other: is te kort (minimaal %{count} tekens)
17
25
 
18
26
  number:
19
27
  format:
@@ -12,10 +12,18 @@ pl:
12
12
  es: hiszpański
13
13
  ru: rosyjski
14
14
  et: estoński
15
+ el: Grecki
15
16
 
16
17
  errors:
17
18
  messages:
18
19
  blank: "nie może być puste"
20
+ taken: zostało już zajęte
21
+ confirmation: nie zgadza się z polem %{attribute}
22
+ too_short:
23
+ few: jest za krótkie (przynajmniej %{count} znaki)
24
+ many: jest za krótkie (przynajmniej %{count} znaków)
25
+ one: jest za krótkie (przynajmniej jeden znak)
26
+ other: jest za krótkie (przynajmniej %{count} znaków)
19
27
 
20
28
  date:
21
29
  formats:
@@ -12,10 +12,16 @@ pt-BR:
12
12
  es: Espanhol
13
13
  ru: Russo
14
14
  et: Estoniano
15
+ el: Grego
15
16
 
16
17
  errors:
17
18
  messages:
18
19
  blank: "não pode ficar em branco"
20
+ taken: já está em uso
21
+ confirmation: não é igual a %{attribute}
22
+ too_short:
23
+ one: 'é muito curto (mínimo: 1 caracter)'
24
+ other: 'é muito curto (mínimo: %{count} caracteres)'
19
25
 
20
26
  date:
21
27
  formats:
@@ -12,10 +12,18 @@ ru:
12
12
  es: Испанский
13
13
  ru: Русский
14
14
  et: Эстонский
15
+ el: Греческий
15
16
 
16
17
  errors:
17
18
  messages:
18
- blank: "can not be blank"
19
+ blank: не может быть пустым
20
+ taken: уже существует
21
+ confirmation: не совпадает со значением поля %{attribute}
22
+ too_short:
23
+ few: недостаточной длины (не может быть меньше %{count} символов)
24
+ many: недостаточной длины (не может быть меньше %{count} символов)
25
+ one: недостаточной длины (не может быть меньше %{count} символа)
26
+ other: недостаточной длины (не может быть меньше %{count} символа)
19
27
 
20
28
  pagination:
21
29
  previous: "« Предыдущая"
@@ -83,7 +83,7 @@ module Locomotive::Steam
83
83
  end
84
84
 
85
85
  def slugify(id, label, dataset, locale = nil)
86
- base, index = label.permalink(false), nil
86
+ base, index = label.to_s.permalink(false), nil
87
87
  _slugify = -> (i) { [base, i].compact.join('-') }
88
88
 
89
89
  while !is_slug_unique?(id, _slugify.call(index), dataset, locale)
@@ -36,7 +36,7 @@ module Locomotive
36
36
 
37
37
  def render_haml(source, template_path)
38
38
  begin
39
- Haml::Engine.new(source).render
39
+ Haml::Engine.new(source, escape_attrs: false).render
40
40
  rescue Haml::SyntaxError => e
41
41
  raise Steam::RenderError.new(e, template_path, source)
42
42
  end
@@ -64,6 +64,10 @@ module Locomotive::Steam
64
64
  self[content_type.label_field_name]
65
65
  end
66
66
 
67
+ def _label_of(name)
68
+ content_type.field_label_of(name)
69
+ end
70
+
67
71
  def localized_attributes
68
72
  @localized_attributes.tap do |hash|
69
73
  if hash && hash.has_key?(content_type.label_field_name.to_sym)
@@ -52,6 +52,10 @@ module Locomotive::Steam
52
52
  (self[:label_field_name] || fields.first.name).to_sym
53
53
  end
54
54
 
55
+ def field_label_of(name)
56
+ fields_by_name[name].label.downcase
57
+ end
58
+
55
59
  def order_by
56
60
  name = self[:order_by] == 'manually' ? '_position' : self[:order_by]
57
61
 
@@ -18,7 +18,8 @@ module Locomotive::Steam
18
18
  private_access: false,
19
19
  password: nil,
20
20
  metafields_schema: {},
21
- metafields: nil
21
+ metafields: nil,
22
+ asset_host: nil
22
23
  }.merge(attributes))
23
24
  end
24
25
 
@@ -67,7 +67,7 @@ module Locomotive
67
67
  @_source.content_type.fields_by_name.each do |name, field|
68
68
  case field.type
69
69
  when :belongs_to
70
- hash[name] = liquify_entry(@_source.send(name))._slug
70
+ hash[name] = liquify_entry(@_source.send(name))._slug if hash["#{name}_id"].present?
71
71
  when :many_to_many
72
72
  hash[name] = (@_source.send(name) || []).all.map { |e| liquify_entry(e)._slug }.compact
73
73
  when :file
@@ -4,7 +4,7 @@ module Locomotive
4
4
  module Drops
5
5
  class Site < I18nBase
6
6
 
7
- delegate :name, :domains, :seo_title, :meta_keywords, :meta_description, to: :@_source
7
+ delegate :name, :domains, :seo_title, :meta_keywords, :meta_description, :asset_host, to: :@_source
8
8
 
9
9
  def index
10
10
  @index ||= repository.root.to_liquid
@@ -2,6 +2,7 @@ module Locomotive::Steam
2
2
  module Middlewares
3
3
 
4
4
  # Process all the authentication actions:
5
+ # - sign up
5
6
  # - sign in
6
7
  # - new reset password
7
8
  # - reset password
@@ -26,10 +27,25 @@ module Locomotive::Steam
26
27
 
27
28
  private
28
29
 
30
+ def sign_up(options)
31
+ return if authenticated?
32
+
33
+ status, entry = services.auth.sign_up(options, default_liquid_context, request)
34
+
35
+ if status == :entry_created
36
+ store_authenticated(entry)
37
+ redirect_to options.callback || mounted_on
38
+ else
39
+ liquid_assigns['auth_entry'] = entry
40
+ end
41
+
42
+ append_message(status)
43
+ end
44
+
29
45
  def sign_in(options)
30
46
  return if authenticated?
31
47
 
32
- status, entry = services.auth.sign_in(options)
48
+ status, entry = services.auth.sign_in(options, request)
33
49
 
34
50
  if status == :signed_in
35
51
  store_authenticated(entry)
@@ -42,6 +58,8 @@ module Locomotive::Steam
42
58
  def sign_out(options)
43
59
  return unless authenticated?
44
60
 
61
+ services.auth.sign_out(load_authenticated_entry, request)
62
+
45
63
  store_authenticated(nil)
46
64
 
47
65
  append_message(:signed_out)
@@ -102,7 +120,7 @@ module Locomotive::Steam
102
120
 
103
121
  class AuthOptions
104
122
 
105
- ACTIONS = %w(sign_in sign_out forgot_password reset_password)
123
+ ACTIONS = %w(sign_up sign_in sign_out forgot_password reset_password)
106
124
 
107
125
  attr_reader :site, :params
108
126
 
@@ -131,7 +149,7 @@ module Locomotive::Steam
131
149
  end
132
150
 
133
151
  def id
134
- params[:auth_id]
152
+ params[:auth_entry].try(:[], id_field) || params[:auth_id]
135
153
  end
136
154
 
137
155
  def password
@@ -162,6 +180,14 @@ module Locomotive::Steam
162
180
  params[:auth_email_handle]
163
181
  end
164
182
 
183
+ def disable_email
184
+ [1, '1', 'true', true].include?(params[:auth_disable_email])
185
+ end
186
+
187
+ def entry
188
+ params[:auth_entry]
189
+ end
190
+
165
191
  def smtp
166
192
  name = params[:auth_email_smtp_namespace] || 'smtp'
167
193
  namespace = site.metafields.try(:[], name)
@@ -36,16 +36,15 @@ module Locomotive
36
36
  add(attribute, :blank) if value.blank?
37
37
  end
38
38
 
39
- def add(attribute, message)
40
- (@messages[attribute] ||= []) << generate_message(message)
39
+ def add(attribute, message, options = {})
40
+ (@messages[attribute] ||= []) << generate_message(message, options)
41
41
  end
42
42
 
43
- def generate_message(message)
44
- case message
45
- when :blank, :unique then I18n.t(message, scope: 'errors.messages')
46
- else
47
- message
48
- end
43
+ def generate_message(message, options = {})
44
+ I18n.t(message, {
45
+ scope: 'errors.messages',
46
+ default: message
47
+ }.merge(options))
49
48
  end
50
49
 
51
50
  end
@@ -40,8 +40,10 @@ module Locomotive::Steam
40
40
  end
41
41
 
42
42
  def blank?
43
- @translations.blank? ||
44
- @translations.values.all? { |v| v.blank? }
43
+ @translations.default.blank? && (
44
+ @translations.blank? ||
45
+ @translations.values.all? { |v| v.blank? }
46
+ )
45
47
  end
46
48
 
47
49
  def apply(&block)
@@ -137,7 +137,15 @@ module Locomotive
137
137
  def prepare_conditions(*conditions)
138
138
  _conditions = Conditions.new(conditions.first, self.content_type.fields, simple_clone).prepare
139
139
 
140
- super({ _visible: true }, _conditions)
140
+ super(_conditions).tap do |final_conditions|
141
+ # skip the default visible condition (_visible: true) by just passing nil
142
+ skip_visible = final_conditions.stringify_keys.fetch('_visible', true).nil?
143
+
144
+ # clean it
145
+ final_conditions.delete(:_visible) || final_conditions.delete('_visible')
146
+
147
+ final_conditions[:_visible] = true unless skip_visible
148
+ end
141
149
  end
142
150
 
143
151
  def simple_clone
@@ -123,7 +123,7 @@ module Locomotive
123
123
  end
124
124
 
125
125
  register :auth do
126
- Steam::AuthService.new(content_entry, email)
126
+ Steam::AuthService.new(current_site, content_entry, email)
127
127
  end
128
128
 
129
129
  register :cache do
@@ -3,12 +3,10 @@ module Locomotive
3
3
 
4
4
  class AssetHostService
5
5
 
6
- attr_reader :request, :site, :host
6
+ attr_reader :request, :site
7
7
 
8
- def initialize(request, site, host)
9
- @request, @site = request, site
10
-
11
- @host = build_host(host, request, site)
8
+ def initialize(request, site, default_host)
9
+ @request, @site, @default_host = request, site, default_host
12
10
  end
13
11
 
14
12
  def compute(source, timestamp = nil)
@@ -23,6 +21,20 @@ module Locomotive
23
21
  add_timestamp_suffix(url, timestamp)
24
22
  end
25
23
 
24
+ def host
25
+ return @host if @host
26
+
27
+ @host = if site.try(:asset_host).present?
28
+ build_host_with_protocol(site.asset_host)
29
+ elsif @default_host.respond_to?(:call)
30
+ @default_host.call(request, site)
31
+ elsif @default_host.present?
32
+ build_host_with_protocol(@default_host)
33
+ else
34
+ nil
35
+ end
36
+ end
37
+
26
38
  private
27
39
 
28
40
  def build_url(host, source)
@@ -30,18 +42,6 @@ module Locomotive
30
42
  URI.join(host, clean_source).to_s
31
43
  end
32
44
 
33
- def build_host(host, request, site)
34
- if host
35
- if host.respond_to?(:call)
36
- host.call(request, site)
37
- else
38
- host =~ Steam::IsHTTP ? host : "https://#{host}"
39
- end
40
- else
41
- nil
42
- end
43
- end
44
-
45
45
  def add_timestamp_suffix(source, timestamp)
46
46
  if timestamp.nil? || timestamp == 0 || source.include?('?')
47
47
  source
@@ -50,6 +50,10 @@ module Locomotive
50
50
  end
51
51
  end
52
52
 
53
+ def build_host_with_protocol(host)
54
+ host =~ Steam::IsHTTP ? host : "https://#{host}"
55
+ end
56
+
53
57
  end
54
58
 
55
59
  end