beyond_canvas 0.16.1.pre → 0.19.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/beyond_canvas_manifest.js +1 -0
  3. data/app/assets/images/icons/arrow_right.svg +1 -0
  4. data/app/assets/images/icons/close.svg +1 -0
  5. data/app/assets/images/icons/home.svg +1 -0
  6. data/app/assets/javascripts/beyond_canvas/base.js +120 -246
  7. data/app/assets/stylesheets/beyond_canvas/base.scss +10 -1
  8. data/app/assets/stylesheets/beyond_canvas/components/_action_bar.scss +28 -0
  9. data/app/assets/stylesheets/beyond_canvas/components/_breadcrumbs.scss +29 -0
  10. data/app/assets/stylesheets/beyond_canvas/components/_buttons.scss +1 -1
  11. data/app/assets/stylesheets/beyond_canvas/components/_debug.scss +10 -0
  12. data/app/assets/stylesheets/beyond_canvas/components/_forms.scss +11 -14
  13. data/app/assets/stylesheets/beyond_canvas/components/_grids.scss +12 -0
  14. data/app/assets/stylesheets/beyond_canvas/components/_inputs.scss +5 -0
  15. data/app/assets/stylesheets/beyond_canvas/components/_main.scss +12 -13
  16. data/app/assets/stylesheets/beyond_canvas/components/_margins.scss +12 -0
  17. data/app/assets/stylesheets/beyond_canvas/components/_menu.scss +50 -0
  18. data/app/assets/stylesheets/beyond_canvas/components/_modals.scss +35 -0
  19. data/app/assets/stylesheets/beyond_canvas/components/_scrollbox.scss +35 -0
  20. data/app/assets/stylesheets/beyond_canvas/components/_sidebar.scss +53 -0
  21. data/app/assets/stylesheets/beyond_canvas/components/_titles.scss +7 -0
  22. data/app/assets/stylesheets/beyond_canvas/settings/_variables.scss +64 -9
  23. data/app/controllers/beyond_canvas/application_controller.rb +2 -0
  24. data/app/controllers/beyond_canvas/authentications_controller.rb +37 -30
  25. data/app/controllers/concerns/beyond_canvas/authentication.rb +1 -12
  26. data/app/controllers/concerns/beyond_canvas/locale_management.rb +5 -4
  27. data/app/form_builders/beyond_canvas/form_builder.rb +8 -6
  28. data/app/helpers/beyond_canvas/authentications_helper.rb +28 -0
  29. data/app/helpers/beyond_canvas/cockpit_app_helper.rb +17 -0
  30. data/app/helpers/beyond_canvas/debug_helper.rb +9 -0
  31. data/app/helpers/beyond_canvas/locale_switch_helper.rb +5 -1
  32. data/app/javascript/beyond_canvas/base.js +3 -0
  33. data/app/javascript/beyond_canvas/initializers/buttons.js +65 -19
  34. data/app/javascript/beyond_canvas/initializers/flash.js +9 -2
  35. data/app/javascript/beyond_canvas/initializers/inputs.js +4 -1
  36. data/app/javascript/beyond_canvas/initializers/modals.js +14 -0
  37. data/app/views/beyond_canvas/authentications/new.html.erb +19 -10
  38. data/app/views/beyond_canvas/shared/_action_bar.html.erb +15 -0
  39. data/app/views/beyond_canvas/shared/_breadcrumbs.html.erb +14 -0
  40. data/app/views/beyond_canvas/shared/_flash.html.erb +22 -12
  41. data/app/views/beyond_canvas/shared/_locales.html.erb +8 -0
  42. data/app/views/beyond_canvas/shared/_menu.html.erb +31 -0
  43. data/app/views/beyond_canvas/shared/_modal.html.erb +6 -0
  44. data/app/views/beyond_canvas/shared/_sidebar.html.erb +16 -0
  45. data/app/views/layouts/beyond_canvas/application.html.erb +31 -0
  46. data/app/views/layouts/beyond_canvas/public.html.erb +10 -1
  47. data/config/locales/en.yml +5 -0
  48. data/config/routes.rb +5 -4
  49. data/lib/beyond_canvas.rb +12 -12
  50. data/lib/beyond_canvas/configuration.rb +11 -6
  51. data/lib/beyond_canvas/engine.rb +4 -2
  52. data/lib/beyond_canvas/menu_item_registration.rb +19 -0
  53. data/lib/beyond_canvas/parameter_sanitizer.rb +1 -1
  54. data/lib/beyond_canvas/rails/routes.rb +8 -7
  55. data/lib/beyond_canvas/version.rb +1 -1
  56. data/lib/generators/beyond_canvas/controller/controller_generator.rb +1 -2
  57. data/lib/generators/beyond_canvas/controller/templates/controller.erb +2 -19
  58. data/lib/generators/beyond_canvas/custom_menu/custom_menu_generator.rb +13 -0
  59. data/lib/generators/beyond_canvas/custom_menu/templates/beyond_canvas_custom_menu.html.erb +32 -0
  60. data/lib/generators/beyond_canvas/custom_styles/custom_styles_generator.rb +1 -1
  61. data/lib/generators/beyond_canvas/custom_styles/templates/beyond_canvas_custom_styles.scss +55 -9
  62. data/lib/generators/beyond_canvas/install/install_generator.rb +3 -5
  63. data/lib/generators/beyond_canvas/install/templates/beyond_canvas.rb.erb +51 -13
  64. data/lib/generators/beyond_canvas/{auth_model/auth_model_generator.rb → model/model_generator.rb} +4 -5
  65. data/lib/generators/beyond_canvas/{auth_model → model}/templates/migration.erb +2 -4
  66. data/lib/generators/beyond_canvas/{auth_model → model}/templates/model.erb +0 -0
  67. data/lib/generators/beyond_canvas/views/views_generator.rb +4 -6
  68. data/lib/models/concerns/authentication.rb +57 -0
  69. data/lib/models/concerns/utils.rb +79 -0
  70. data/lib/models/shop.rb +12 -0
  71. metadata +68 -27
  72. data/app/controllers/concerns/beyond_canvas/resource_management.rb +0 -33
  73. data/app/javascript/beyond_canvas/initializers/functions.js +0 -41
  74. data/app/views/beyond_canvas/locales/_edit.html.erb +0 -8
  75. data/lib/beyond_canvas/models/authentication.rb +0 -66
  76. data/lib/beyond_canvas/models/shop.rb +0 -28
  77. data/lib/beyond_canvas/models/utils.rb +0 -55
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondCanvas
4
+ module Models
5
+ module Shop # :nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ include ::BeyondCanvas::Models::Concerns::Authentication
9
+ include ::BeyondCanvas::Models::Concerns::Utils
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1.pre
4
+ version: 0.19.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
8
+ - Kathia Salazar
9
+ - German San Emeterio
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
13
+ date: 2020-10-20 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: attr_encrypted
@@ -38,20 +40,6 @@ dependencies:
38
40
  - - "~>"
39
41
  - !ruby/object:Gem::Version
40
42
  version: '0.11'
41
- - !ruby/object:Gem::Dependency
42
- name: blind_index
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
55
43
  - !ruby/object:Gem::Dependency
56
44
  name: bourbon
57
45
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +158,34 @@ dependencies:
170
158
  - - "<"
171
159
  - !ruby/object:Gem::Version
172
160
  version: '4.1'
161
+ - !ruby/object:Gem::Dependency
162
+ name: loaf
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.9'
168
+ type: :runtime
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.9'
175
+ - !ruby/object:Gem::Dependency
176
+ name: jwt
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '2.2'
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '2.2'
173
189
  - !ruby/object:Gem::Dependency
174
190
  name: rubocop-rails
175
191
  requirement: !ruby/object:Gem::Requirement
@@ -188,7 +204,9 @@ description: |2
188
204
  Beyond Canvas is an open-source framework that provides CSS styles for apps
189
205
  designed and developed for the online shop software Beyond
190
206
  email:
191
- - u.abrisketa@epages.com
207
+ - uabrisketa@epages.com
208
+ - ksalazar@epages.com
209
+ - gsanemeterio@epages.com
192
210
  executables: []
193
211
  extensions: []
194
212
  extra_rdoc_files: []
@@ -197,36 +215,48 @@ files:
197
215
  - README.md
198
216
  - Rakefile
199
217
  - app/assets/config/beyond_canvas_manifest.js
218
+ - app/assets/images/icons/arrow_right.svg
200
219
  - app/assets/images/icons/checkbox_checked.svg
201
220
  - app/assets/images/icons/checkbox_unchecked.svg
221
+ - app/assets/images/icons/close.svg
202
222
  - app/assets/images/icons/file.svg
203
223
  - app/assets/images/icons/flash_checkbox.svg
204
224
  - app/assets/images/icons/flash_close.svg
205
225
  - app/assets/images/icons/flash_error.svg
206
226
  - app/assets/images/icons/flash_info.svg
207
227
  - app/assets/images/icons/flash_warning.svg
228
+ - app/assets/images/icons/home.svg
208
229
  - app/assets/images/icons/radiobutton_checked.svg
209
230
  - app/assets/images/icons/radiobutton_unchecked.svg
210
231
  - app/assets/javascripts/beyond_canvas/base.js
211
232
  - app/assets/stylesheets/beyond_canvas/base.scss
233
+ - app/assets/stylesheets/beyond_canvas/components/_action_bar.scss
212
234
  - app/assets/stylesheets/beyond_canvas/components/_actions.scss
235
+ - app/assets/stylesheets/beyond_canvas/components/_breadcrumbs.scss
213
236
  - app/assets/stylesheets/beyond_canvas/components/_buttons.scss
214
237
  - app/assets/stylesheets/beyond_canvas/components/_cards.scss
215
238
  - app/assets/stylesheets/beyond_canvas/components/_comments.scss
216
239
  - app/assets/stylesheets/beyond_canvas/components/_containers.scss
240
+ - app/assets/stylesheets/beyond_canvas/components/_debug.scss
217
241
  - app/assets/stylesheets/beyond_canvas/components/_flash.scss
218
242
  - app/assets/stylesheets/beyond_canvas/components/_forms.scss
243
+ - app/assets/stylesheets/beyond_canvas/components/_grids.scss
219
244
  - app/assets/stylesheets/beyond_canvas/components/_inputs.scss
220
245
  - app/assets/stylesheets/beyond_canvas/components/_layouts.scss
221
246
  - app/assets/stylesheets/beyond_canvas/components/_links.scss
222
247
  - app/assets/stylesheets/beyond_canvas/components/_main.scss
223
248
  - app/assets/stylesheets/beyond_canvas/components/_margins.scss
224
249
  - app/assets/stylesheets/beyond_canvas/components/_markdown.scss
250
+ - app/assets/stylesheets/beyond_canvas/components/_menu.scss
251
+ - app/assets/stylesheets/beyond_canvas/components/_modals.scss
225
252
  - app/assets/stylesheets/beyond_canvas/components/_notices.scss
226
253
  - app/assets/stylesheets/beyond_canvas/components/_relative.scss
254
+ - app/assets/stylesheets/beyond_canvas/components/_scrollbox.scss
255
+ - app/assets/stylesheets/beyond_canvas/components/_sidebar.scss
227
256
  - app/assets/stylesheets/beyond_canvas/components/_spinner.scss
228
257
  - app/assets/stylesheets/beyond_canvas/components/_tables.scss
229
258
  - app/assets/stylesheets/beyond_canvas/components/_texts.scss
259
+ - app/assets/stylesheets/beyond_canvas/components/_titles.scss
230
260
  - app/assets/stylesheets/beyond_canvas/mailer.scss
231
261
  - app/assets/stylesheets/beyond_canvas/settings/_breakpoints.scss
232
262
  - app/assets/stylesheets/beyond_canvas/settings/_reset_css.scss
@@ -240,26 +270,34 @@ files:
240
270
  - app/controllers/concerns/beyond_canvas/authentication.rb
241
271
  - app/controllers/concerns/beyond_canvas/locale_management.rb
242
272
  - app/controllers/concerns/beyond_canvas/request_validation.rb
243
- - app/controllers/concerns/beyond_canvas/resource_management.rb
244
273
  - app/controllers/concerns/beyond_canvas/status_codes.rb
245
274
  - app/form_builders/beyond_canvas/form_builder.rb
246
275
  - app/helpers/beyond_canvas/application_helper.rb
276
+ - app/helpers/beyond_canvas/authentications_helper.rb
277
+ - app/helpers/beyond_canvas/cockpit_app_helper.rb
278
+ - app/helpers/beyond_canvas/debug_helper.rb
247
279
  - app/helpers/beyond_canvas/locale_switch_helper.rb
248
280
  - app/javascript/beyond_canvas/base.js
249
281
  - app/javascript/beyond_canvas/initializers/buttons.js
250
282
  - app/javascript/beyond_canvas/initializers/flash.js
251
- - app/javascript/beyond_canvas/initializers/functions.js
252
283
  - app/javascript/beyond_canvas/initializers/inputs.js
284
+ - app/javascript/beyond_canvas/initializers/modals.js
253
285
  - app/views/beyond_canvas/authentications/new.html.erb
254
286
  - app/views/beyond_canvas/custom/_public_head.html.erb
255
- - app/views/beyond_canvas/locales/_edit.html.erb
256
287
  - app/views/beyond_canvas/mailer/_button.html.erb
257
288
  - app/views/beyond_canvas/mailer/_footer.html.erb
258
289
  - app/views/beyond_canvas/mailer/_header.html.erb
259
290
  - app/views/beyond_canvas/mailer/_text.html.erb
291
+ - app/views/beyond_canvas/shared/_action_bar.html.erb
292
+ - app/views/beyond_canvas/shared/_breadcrumbs.html.erb
260
293
  - app/views/beyond_canvas/shared/_flash.html.erb
261
294
  - app/views/beyond_canvas/shared/_head.html.erb
295
+ - app/views/beyond_canvas/shared/_locales.html.erb
262
296
  - app/views/beyond_canvas/shared/_logo.html.erb
297
+ - app/views/beyond_canvas/shared/_menu.html.erb
298
+ - app/views/beyond_canvas/shared/_modal.html.erb
299
+ - app/views/beyond_canvas/shared/_sidebar.html.erb
300
+ - app/views/layouts/beyond_canvas/application.html.erb
263
301
  - app/views/layouts/beyond_canvas/mailer.html.erb
264
302
  - app/views/layouts/beyond_canvas/public.html.erb
265
303
  - config/initializers/beyond_canvas/filter_parameter_logging.rb
@@ -270,30 +308,33 @@ files:
270
308
  - lib/beyond_canvas/asset_registration.rb
271
309
  - lib/beyond_canvas/configuration.rb
272
310
  - lib/beyond_canvas/engine.rb
273
- - lib/beyond_canvas/models/authentication.rb
274
- - lib/beyond_canvas/models/shop.rb
275
- - lib/beyond_canvas/models/utils.rb
311
+ - lib/beyond_canvas/menu_item_registration.rb
276
312
  - lib/beyond_canvas/parameter_sanitizer.rb
277
313
  - lib/beyond_canvas/rails/routes.rb
278
314
  - lib/beyond_canvas/version.rb
279
315
  - lib/generators/beyond_canvas/assets/assets_generator.rb
280
316
  - lib/generators/beyond_canvas/assets/templates/beyond_canvas.js
281
317
  - lib/generators/beyond_canvas/assets/templates/beyond_canvas.scss
282
- - lib/generators/beyond_canvas/auth_model/auth_model_generator.rb
283
- - lib/generators/beyond_canvas/auth_model/templates/migration.erb
284
- - lib/generators/beyond_canvas/auth_model/templates/model.erb
285
318
  - lib/generators/beyond_canvas/beyond_api/beyond_api_generator.rb
286
319
  - lib/generators/beyond_canvas/controller/controller_generator.rb
287
320
  - lib/generators/beyond_canvas/controller/templates/controller.erb
321
+ - lib/generators/beyond_canvas/custom_menu/custom_menu_generator.rb
322
+ - lib/generators/beyond_canvas/custom_menu/templates/beyond_canvas_custom_menu.html.erb
288
323
  - lib/generators/beyond_canvas/custom_styles/custom_styles_generator.rb
289
324
  - lib/generators/beyond_canvas/custom_styles/templates/beyond_canvas_custom_styles.scss
290
325
  - lib/generators/beyond_canvas/install/install_generator.rb
291
326
  - lib/generators/beyond_canvas/install/templates/beyond_canvas.rb.erb
327
+ - lib/generators/beyond_canvas/model/model_generator.rb
328
+ - lib/generators/beyond_canvas/model/templates/migration.erb
329
+ - lib/generators/beyond_canvas/model/templates/model.erb
292
330
  - lib/generators/beyond_canvas/views/views_generator.rb
293
331
  - lib/generators/beyond_canvas/webpacker/plugins/jquery.js
294
332
  - lib/generators/beyond_canvas/webpacker/templates/beyond_canvas.js
295
333
  - lib/generators/beyond_canvas/webpacker/templates/beyond_canvas.scss
296
334
  - lib/generators/beyond_canvas/webpacker/webpacker_generator.rb
335
+ - lib/models/concerns/authentication.rb
336
+ - lib/models/concerns/utils.rb
337
+ - lib/models/shop.rb
297
338
  homepage: https://github.com/ePages-de/beyond_canvas
298
339
  licenses:
299
340
  - MIT
@@ -313,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
354
  - !ruby/object:Gem::Version
314
355
  version: 1.3.1
315
356
  requirements: []
316
- rubygems_version: 3.1.2
357
+ rubygems_version: 3.1.4
317
358
  signing_key:
318
359
  specification_version: 4
319
360
  summary: Open-source framework that provides CSS styles
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BeyondCanvas
4
- module ResourceManagement # :nodoc:
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- # Share some methods defined in the controller to make them available for the view
9
- if respond_to?(:helper_method)
10
- helpers = %w[resource resource_name resource_class]
11
- helper_method(*helpers)
12
- end
13
- end
14
-
15
- protected
16
-
17
- def resource_name
18
- BeyondCanvas.auth_model
19
- end
20
-
21
- def resource
22
- instance_variable_get(:"@#{resource_name}")
23
- end
24
-
25
- def resource=(new_resource)
26
- instance_variable_set(:"@#{resource_name}", new_resource)
27
- end
28
-
29
- def resource_class
30
- resource_name.classify.constantize
31
- end
32
- end
33
- end
@@ -1,41 +0,0 @@
1
- const SPINNER_ANIMATION_TIMEOUT = 125;
2
-
3
- export function showSpinner(button) {
4
- // Adjust the width of the button
5
- button.width(button.width() + $('.spinner').outerWidth(true));
6
- // Show the spinner
7
- setTimeout(function () {
8
- button.find('.spinner').css('display', 'flex');
9
- }, SPINNER_ANIMATION_TIMEOUT);
10
- }
11
-
12
- export function hideSpinner() {
13
- $('button[class^="button"]').each(function (_, button) {
14
- setTimeout(function () {
15
- // Hide the spinner
16
- $(button).find('.spinner').hide();
17
- // Adjust the width of the button
18
- $(button).width($(button).data('oldWidth'));
19
- }, SPINNER_ANIMATION_TIMEOUT);
20
- });
21
- }
22
-
23
- export function disableActionElements() {
24
- $('a, input[type="submit"], input[type="button"], input[type="reset"], button').each(function (_, button) {
25
- $(button).addClass('actions--disabled');
26
- });
27
- }
28
- export function enableActionElements() {
29
- $('a, input[type="submit"], input[type="button"], input[type="reset"], button').each(function (_, button) {
30
- $(button).removeClass('actions--disabled');
31
- });
32
- }
33
-
34
- export function closeAlert() {
35
- $('.flash')
36
- .removeClass('flash--shown')
37
- .delay(700)
38
- .queue(function () {
39
- $(this).remove();
40
- });
41
- }
@@ -1,8 +0,0 @@
1
- <% if defined?(I18n) && I18n.available_locales.count > 1 %>
2
- <%= form_for :system, url: beyond_canvas.update_locale_path, method: :put do |f| %>
3
- <%= f.select :locale, I18n.available_locales.collect { |l| [translate_locale(l), l] },
4
- { selected: cookies[:locale] },
5
- class: 'select--locale',
6
- onchange: 'this.form.submit()' %>
7
- <% end %>
8
- <% end %>
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BeyondCanvas
4
- module Models
5
- module Authentication # :nodoc:
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- attr_accessor :code, :signature, :access_token_url
10
-
11
- ##############################################################################
12
- # Encrypted attribute configuration
13
- ##############################################################################
14
-
15
- attr_encrypted :beyond_api_url, key: [BeyondCanvas.configuration.encryption_key].pack('H*')
16
- attr_encrypted :beyond_access_token, key: [BeyondCanvas.configuration.encryption_key].pack('H*')
17
- attr_encrypted :beyond_refresh_token, key: [BeyondCanvas.configuration.encryption_key].pack('H*')
18
-
19
- blind_index :beyond_api_url, key: [BeyondCanvas.configuration.blind_index_key].pack('H*')
20
-
21
- ##############################################################################
22
- # Validations
23
- ##############################################################################
24
-
25
- # Callback url params
26
-
27
- validates :code,
28
- presence: true,
29
- on: :create
30
- validates :signature,
31
- presence: true,
32
- on: :create
33
- validates :access_token_url,
34
- presence: true,
35
- on: :create
36
-
37
- # Database fields
38
-
39
- validates :beyond_api_url,
40
- presence: true
41
- validates :beyond_access_token,
42
- presence: true,
43
- unless: -> { encrypted_beyond_access_token_was.blank? }
44
- validates :beyond_refresh_token,
45
- presence: true,
46
- unless: -> { encrypted_beyond_refresh_token_was.blank? }
47
-
48
- ##############################################################################
49
- # Instance methods
50
- ##############################################################################
51
-
52
- #
53
- # Get and save access_token and refresh_token using the authentication code
54
- # NOTE: This method is used during the shop creation, as it is the only point
55
- # we know about the authentication code
56
- #
57
- def authenticate
58
- session = BeyondApi::Session.new(api_url: beyond_api_url)
59
- session.token.create(code)
60
- update(beyond_access_token: session.access_token,
61
- beyond_refresh_token: session.refresh_token)
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BeyondCanvas
4
- module Models
5
- module Shop # :nodoc:
6
- extend ActiveSupport::Concern
7
- include BeyondCanvas::Models::Authentication
8
- include BeyondCanvas::Models::Utils
9
-
10
- included do
11
- attr_accessor :api_url, :return_url
12
-
13
- ##############################################################################
14
- # Validations
15
- ##############################################################################
16
-
17
- # Callback url params
18
-
19
- validates :api_url,
20
- presence: true,
21
- on: :create
22
- validates :return_url,
23
- presence: true,
24
- on: :create
25
- end
26
- end
27
- end
28
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BeyondCanvas
4
- module Models
5
- module Utils # :nodoc:
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- ##############################################################################
10
- # Instance methods
11
- ##############################################################################
12
-
13
- #
14
- # Generates a new access_token and refresh_token
15
- #
16
- def refresh_token
17
- beyond_session = BeyondApi::Session.new(api_url: beyond_api_url, refresh_token: beyond_refresh_token)
18
- beyond_session.token.refresh
19
-
20
- update(beyond_access_token: beyond_session.access_token,
21
- beyond_refresh_token: beyond_session.refresh_token)
22
- end
23
-
24
- #
25
- # Generates a new access_token and refresh_token if they have expired
26
- #
27
- def refresh_token_if_needed
28
- token_timestamp = JWT.decode(beyond_access_token, nil, false).first['exp']
29
- current_timestamp = DateTime.now.to_i
30
- return unless token_timestamp - current_timestamp <= 3600
31
-
32
- refresh_token
33
- end
34
-
35
- #
36
- # Returns a BeyondApi::Session object with api_url, access_token and refresh_token attributes
37
- #
38
- def to_session
39
- BeyondApi::Session.new(api_url: beyond_api_url,
40
- access_token: beyond_access_token,
41
- refresh_token: beyond_refresh_token)
42
- end
43
-
44
- ##############################################################################
45
- # Class methods
46
- ##############################################################################
47
-
48
- def self.find_session(id)
49
- shop = find(id)
50
- shop.to_session
51
- end
52
- end
53
- end
54
- end
55
- end