shopapp 0.2.58 → 0.2.59

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -7
  3. data/app/assets/images/flags/ad.png +0 -0
  4. data/app/assets/images/flags/ae.png +0 -0
  5. data/app/assets/images/flags/am.png +0 -0
  6. data/app/assets/images/flags/ar.png +0 -0
  7. data/app/assets/images/flags/at.png +0 -0
  8. data/app/assets/images/flags/au.png +0 -0
  9. data/app/assets/images/flags/ax.png +0 -0
  10. data/app/assets/images/flags/az.png +0 -0
  11. data/app/assets/images/flags/ba.png +0 -0
  12. data/app/assets/images/flags/bb.png +0 -0
  13. data/app/assets/images/flags/be.png +0 -0
  14. data/app/assets/images/flags/bg.png +0 -0
  15. data/app/assets/images/flags/bt.png +0 -0
  16. data/app/assets/images/flags/ca.png +0 -0
  17. data/app/assets/images/flags/ch.png +0 -0
  18. data/app/assets/images/flags/cl.png +0 -0
  19. data/app/assets/images/flags/cn.png +0 -0
  20. data/app/assets/images/flags/cr.png +0 -0
  21. data/app/assets/images/flags/cu.png +0 -0
  22. data/app/assets/images/flags/cz.png +0 -0
  23. data/app/assets/images/flags/de.png +0 -0
  24. data/app/assets/images/flags/dk.png +0 -0
  25. data/app/assets/images/flags/en.png +0 -0
  26. data/app/assets/images/flags/es.png +0 -0
  27. data/app/assets/images/flags/fi.png +0 -0
  28. data/app/assets/images/flags/fr.png +0 -0
  29. data/app/assets/images/flags/ge.png +0 -0
  30. data/app/assets/images/flags/gn.png +0 -0
  31. data/app/assets/images/flags/gr.png +0 -0
  32. data/app/assets/images/flags/gw.png +0 -0
  33. data/app/assets/images/flags/it.png +0 -0
  34. data/app/assets/images/flags/jm.png +0 -0
  35. data/app/assets/images/flags/jp.png +0 -0
  36. data/app/assets/images/flags/ne.png +0 -0
  37. data/app/assets/images/flags/ng.png +0 -0
  38. data/app/assets/images/flags/pr.png +0 -0
  39. data/app/assets/images/flags/sc.png +0 -0
  40. data/app/assets/images/flags/sd.png +0 -0
  41. data/app/assets/images/flags/se.png +0 -0
  42. data/app/assets/images/flags/sl.png +0 -0
  43. data/app/assets/images/flags/sr.png +0 -0
  44. data/app/assets/images/flags/td.png +0 -0
  45. data/app/assets/images/flags/tg.png +0 -0
  46. data/app/assets/images/flags/th.png +0 -0
  47. data/app/assets/images/flags/tj.png +0 -0
  48. data/app/assets/images/flags/tr.png +0 -0
  49. data/app/assets/images/flags/ua.png +0 -0
  50. data/app/assets/images/flags/uk.png +0 -0
  51. data/app/assets/images/flags/us.png +0 -0
  52. data/app/assets/images/flags/ve.png +0 -0
  53. data/app/assets/images/flags/vn.png +0 -0
  54. data/app/controllers/auth_controller.rb +9 -0
  55. data/app/controllers/concerns/shoplift_client.rb +23 -5
  56. data/app/controllers/user_authenticated_controller.rb +1 -1
  57. data/app/controllers/user_authenticated_or_api_controller.rb +1 -1
  58. data/app/views/shopapp/_shopapp3.html.haml +7 -0
  59. data/config/initializers/active_settings.rb +1 -1
  60. data/lib/shopapp/routes.rb +1 -0
  61. data/shopapp.gemspec +1 -1
  62. metadata +52 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a5642e3de1bfc4b78908970794bb1bdbcd67f114ea2371f4d3a14b621aff072
4
- data.tar.gz: 41fd31d1439768e50a56dab7fa2eb11ee0b836d95d0c9640f33eb74d64ca261a
3
+ metadata.gz: c3f32a8bb9da2ba3bde17d6a54bec3472a41427d9d39747d02ec23bd694eb1e8
4
+ data.tar.gz: f9f4637f3dbdb80dc9e711316361a81572f58d5f82229648ee6bdd92cf77f2db
5
5
  SHA512:
6
- metadata.gz: e7d1d3e32ce3db851986bbad5f8c3934bc627d39966a569391069bc5246a0931756cb04cd349d5a6f3d657c4099e36215ceeb20dcd29432da15e62d856783aa3
7
- data.tar.gz: b5dae765cce80eb8531df0c882873df4358e8bd790564cd70e34a747173d2002eabeeb21ac8ac62d72b6e7b4b52837939477fc2ff33973a14f6046096454fbae
6
+ metadata.gz: 05c578664bb08a36689302c52ae037d3d7e9c6fb709a9ec5166fc14814d19370aa4decd0bd78dcf5f6322ca5fd0c0c1e608ae56e2e5de70fa1eff49210abb6b7
7
+ data.tar.gz: f28cc6a9fcb1190681a8f5111e2ae4aeb2db8bff62988c14b80d0b8454c74d00c69f576b7f775df1ae44e90bb94b84202cbb16b447699936a40508370b2c0068
data/README.md CHANGED
@@ -4,15 +4,16 @@ Shopapp gem - gem for Shoplift clients.
4
4
 
5
5
  # Shoplift apps: ShopApps
6
6
 
7
- ShopApps are Shoplift applications, and if they are written in Rails, they can
8
- be made with Shopapp gem. It provides quick start, UI template and controllers
9
- that force authentication with Authlift, Shoplift OAuth provider.
7
+ ShopApps (or shopapps when refering to a set of them) are Shoplift applications,
8
+ and if they are written in Rails, they can be made with Shopapp gem. It provides
9
+ quick start, UI template and controllers that force authentication with Authlift,
10
+ Shoplift OAuth provider.
10
11
 
11
12
  # Development Setup
12
13
 
13
14
  * You must have account with Shoplift with membership for "zwr" company,
14
15
  which is used for all app development.
15
- * ShopApp will work on any \*nix, but is designed on and for OSX
16
+ * ShopApp will work on any \*nix, but is designed on and for development on OSX
16
17
  * Postgres (latest), typically via Brew
17
18
  * You will need Ruby 2.5.1, and typically via RVM, and few gems:
18
19
 
@@ -62,19 +63,34 @@ Following creates default remote (zwr/demolift), but does not push:
62
63
 
63
64
  skip_github_push=1 shopitapp demolift
64
65
 
66
+ # Developing shopapps
67
+
65
68
  ### Favicon
66
69
 
67
70
  Make a 610x610 PNG, for Z-ware colors use 7800a1 -> 7086d6. Then drag that icon
68
71
  to https://faviconit.com and copy all returned files except the instructions to
69
72
  /public/favicon/ folder.
70
73
 
71
- Add the following line to the header and make sure it does not contain anything
72
- else regarding favicons:
74
+ Add the following line to the head of your layouts and make sure it does not
75
+ contain anything else regarding favicons:
73
76
 
74
77
  = shopapp3_favicon
75
78
 
79
+ ### Localized shopapps
80
+
81
+ Shopapp gem and authlift provide all you need for localization. If you want your
82
+ shopapp to support i18n, add two methods to your ApplicationController:
83
+
84
+ * Create method supported_locales which should return an array of language codes, for
85
+ example ['fi', 'en', 'sv'].
86
+ * Override method set_locale, most likely like this:
87
+
88
+ def set_locale
89
+ I18n.locale = current_user['language'].to_sym || I18n.default_locale
90
+ end
91
+
76
92
  # Developing this gem
77
93
 
78
94
  To build new version of this gem, change the version in shopapp.gemspec and run:
79
95
 
80
- git push; gem build shopapp.gemspec ; gem push shopapp-0.2.58.gem; gem install shopapp
96
+ git push; gem build shopapp.gemspec ; gem push shopapp-0.2.59.gem; gem install shopapp
@@ -35,4 +35,13 @@ class AuthController < ActionController::Base
35
35
  signouttoken = session_cookie
36
36
  redirect_to "#{Rails.configuration.settings['authlift_url']}users/change_companyx/#{new_company_code}?change_company_token=#{signouttoken}"
37
37
  end
38
+
39
+ def change_language
40
+ authenticate_user!
41
+ return if current_user.blank?
42
+ new_language_code = params.except(:_method, :authenticity_token).permit(:new_language_code)[:new_language_code]
43
+
44
+ signouttoken = session_cookie
45
+ redirect_to "#{Rails.configuration.settings['authlift_url']}users/change_languagex/#{new_language_code}?change_language_token=#{signouttoken}&return_to=#{request.base_url}"
46
+ end
38
47
  end
@@ -14,6 +14,7 @@ module ShopliftClient
14
14
  attr_reader :search_path
15
15
  attr_accessor :search_placeholder
16
16
  helper_method :company_logo_path_defined
17
+ helper_method :supported_locales_defined
17
18
  helper_method :home_link_path
18
19
  end
19
20
 
@@ -125,16 +126,24 @@ module ShopliftClient
125
126
  @current_company ||= Company.find_or_create_by! code: code do |new_company|
126
127
  fail if parameters.empty?
127
128
  new_company.name = parameters[:name]
128
- new_company.info = parameters.to_json
129
+ # following is an ugly yet backwards conpatible and safe way to store
130
+ # the company info if and in the best way possible, until all the apps
131
+ # are updated to have json there.
132
+ case new_company.column_for_attribute('info').type
133
+ when :json
134
+ new_company.info = parameters
135
+ when :string
136
+ new_company.info = parameters.to_json
137
+ end
129
138
  end
130
139
  rescue ActiveRecord::StatementInvalid
131
140
  if $!.cause.is_a? PG::UndefinedTable
132
141
  fail <<-ERROR.strip_heredoc
133
142
  You have not defined a company, and that is compulsory even if
134
- you are not planning to add any additional fields. You do not need to
135
- seed it, so following is enough forever:
143
+ you are not planning to add any additional fields. You do not
144
+ need to seed it, so following is enough forever:
136
145
 
137
- rails g model company code:string; rake db:migrate
146
+ rails g model company code:string name:string info:json; rake db:migrate
138
147
  ERROR
139
148
  end
140
149
  end
@@ -146,6 +155,7 @@ module ShopliftClient
146
155
  begin
147
156
  x = srv.get '/api/users/profile'
148
157
  @current_user_json_hash = @current_user = JSON.parse x.response.body
158
+
149
159
  unless @current_user['scopes'].is_a? String
150
160
  user_scopes = @current_user['scopes']
151
161
  else
@@ -279,13 +289,21 @@ module ShopliftClient
279
289
  end
280
290
 
281
291
  def company_logo_path_defined
282
- if defined? self.company_logo_path
292
+ if defined? self.company_logo_path
283
293
  company_logo_path
284
294
  else
285
295
  "https://media.shoplift.fi/company_logos/#{@current_user_json_hash['company']['logo_code']}_company_logo_24.png"
286
296
  end
287
297
  end
288
298
 
299
+ def supported_locales_defined
300
+ if defined? self.supported_locales
301
+ supported_locales
302
+ else
303
+ []
304
+ end
305
+ end
306
+
289
307
  def home_link_path
290
308
  root_path
291
309
  end
@@ -1,5 +1,5 @@
1
1
  class UserAuthenticatedController < ApplicationController
2
2
  include ShopliftClient
3
3
  protect_from_forgery with: :exception
4
- before_action :authenticate_user!
4
+ prepend_before_action :authenticate_user!
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class UserAuthenticatedOrApiController < ApplicationController
2
2
  include ShopliftClient
3
3
  protect_from_forgery with: :exception
4
- before_action :authenticate_user_or_api!
4
+ prepend_before_action :authenticate_user_or_api!
5
5
  end
@@ -23,6 +23,13 @@
23
23
  .dropdown-header
24
24
  %strong Company:
25
25
  =@current_user_json_hash['company']['name']
26
+ - if supported_locales_defined.present?
27
+ .dropdown-divider
28
+ .dropdown-header Change language
29
+ %span.px-3.py-2(display="block" clear="none" style="width: 32px; margin-right: 6px;")
30
+ - supported_locales_defined.each do |loc|
31
+ = link_to change_language_path(loc), method: :post, class: 'mr-2' do
32
+ = image_tag "flags/#{loc}.png", style: "height: 24; width: 36px;"
26
33
  - if (@current_user_json_hash['memberships'] || []).reject { |c| @current_user_json_hash['company']['code'] == c['code'] }.present?
27
34
  .dropdown-divider
28
35
  .dropdown-header Change company
@@ -36,4 +36,4 @@ GravatarImageTag.configure do |config|
36
36
  config.secure = true # Set this to true if you require secure images on your pages.
37
37
  end
38
38
 
39
- Rails.application.config.assets.precompile += %w( shopapp3/*.svg )
39
+ Rails.application.config.assets.precompile += %w( shopapp3/*.svg flags/*.png )
@@ -2,6 +2,7 @@ class ActionDispatch::Routing::Mapper
2
2
  def shoplift_single_sign_on
3
3
  get 'auth', to: 'auth#auth'
4
4
  post 'auth/change_company/:new_company_code', to: 'auth#change_company', as: 'change_company'
5
+ post 'auth/change_language/:new_language_code', to: 'auth#change_language', as: 'change_language'
5
6
  delete 'auth', to: 'auth#destroy', as: 'logout'
6
7
  end
7
8
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'shopapp'
3
- s.version = '0.2.58'
3
+ s.version = '0.2.59'
4
4
  s.date = '2019-05-24'
5
5
  s.summary = 'Do a shoplift.'
6
6
  s.description = 'Ha! Art thou Bedlam? Dost thou thirst base Trojan, to have me fold up Parca\'s fatal web? Hence!\
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.58
4
+ version: 0.2.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeljko
@@ -334,6 +334,57 @@ files:
334
334
  - app/assets/images/blue_icon.svg
335
335
  - app/assets/images/dot.svg
336
336
  - app/assets/images/empty.svg
337
+ - app/assets/images/flags/ad.png
338
+ - app/assets/images/flags/ae.png
339
+ - app/assets/images/flags/am.png
340
+ - app/assets/images/flags/ar.png
341
+ - app/assets/images/flags/at.png
342
+ - app/assets/images/flags/au.png
343
+ - app/assets/images/flags/ax.png
344
+ - app/assets/images/flags/az.png
345
+ - app/assets/images/flags/ba.png
346
+ - app/assets/images/flags/bb.png
347
+ - app/assets/images/flags/be.png
348
+ - app/assets/images/flags/bg.png
349
+ - app/assets/images/flags/bt.png
350
+ - app/assets/images/flags/ca.png
351
+ - app/assets/images/flags/ch.png
352
+ - app/assets/images/flags/cl.png
353
+ - app/assets/images/flags/cn.png
354
+ - app/assets/images/flags/cr.png
355
+ - app/assets/images/flags/cu.png
356
+ - app/assets/images/flags/cz.png
357
+ - app/assets/images/flags/de.png
358
+ - app/assets/images/flags/dk.png
359
+ - app/assets/images/flags/en.png
360
+ - app/assets/images/flags/es.png
361
+ - app/assets/images/flags/fi.png
362
+ - app/assets/images/flags/fr.png
363
+ - app/assets/images/flags/ge.png
364
+ - app/assets/images/flags/gn.png
365
+ - app/assets/images/flags/gr.png
366
+ - app/assets/images/flags/gw.png
367
+ - app/assets/images/flags/it.png
368
+ - app/assets/images/flags/jm.png
369
+ - app/assets/images/flags/jp.png
370
+ - app/assets/images/flags/ne.png
371
+ - app/assets/images/flags/ng.png
372
+ - app/assets/images/flags/pr.png
373
+ - app/assets/images/flags/sc.png
374
+ - app/assets/images/flags/sd.png
375
+ - app/assets/images/flags/se.png
376
+ - app/assets/images/flags/sl.png
377
+ - app/assets/images/flags/sr.png
378
+ - app/assets/images/flags/td.png
379
+ - app/assets/images/flags/tg.png
380
+ - app/assets/images/flags/th.png
381
+ - app/assets/images/flags/tj.png
382
+ - app/assets/images/flags/tr.png
383
+ - app/assets/images/flags/ua.png
384
+ - app/assets/images/flags/uk.png
385
+ - app/assets/images/flags/us.png
386
+ - app/assets/images/flags/ve.png
387
+ - app/assets/images/flags/vn.png
337
388
  - app/assets/images/lamppu.jpg
338
389
  - app/assets/images/logo.png
339
390
  - app/assets/images/purple_icon.svg