hubrise_app 1.1.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -5
  3. data/Rakefile +5 -4
  4. data/app/controllers/hubrise_app/application_controller/app_instance_methods.rb +28 -22
  5. data/app/controllers/hubrise_app/application_controller/hubrise_gateway_methods.rb +23 -18
  6. data/app/controllers/hubrise_app/application_controller/session_methods.rb +30 -25
  7. data/app/controllers/hubrise_app/application_controller.rb +1 -0
  8. data/app/controllers/hubrise_app/callback_controller/action_disconnect.rb +8 -3
  9. data/app/controllers/hubrise_app/callback_controller/action_event.rb +8 -3
  10. data/app/controllers/hubrise_app/callback_controller.rb +1 -0
  11. data/app/controllers/hubrise_app/oauth_controller/action_authorize_callback.rb +14 -9
  12. data/app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb +13 -8
  13. data/app/controllers/hubrise_app/oauth_controller/action_login_callback.rb +10 -5
  14. data/app/controllers/hubrise_app/oauth_controller.rb +3 -2
  15. data/app/controllers/hubrise_app/sessions_controller.rb +1 -0
  16. data/app/lib/hubrise_app/hubrise_gateway.rb +50 -47
  17. data/app/lib/hubrise_app/refresher/account.rb +14 -11
  18. data/app/lib/hubrise_app/refresher/app_instance.rb +22 -19
  19. data/app/lib/hubrise_app/refresher/base.rb +46 -41
  20. data/app/lib/hubrise_app/refresher/catalog.rb +12 -9
  21. data/app/lib/hubrise_app/refresher/customer_list.rb +12 -9
  22. data/app/lib/hubrise_app/refresher/location.rb +12 -9
  23. data/app/lib/hubrise_app/refresher/user.rb +15 -12
  24. data/app/lib/hubrise_app/services/assign_app_instance.rb +11 -6
  25. data/app/lib/hubrise_app/services/connect_app_instance.rb +8 -3
  26. data/app/lib/hubrise_app/services/resolve_app_instance.rb +8 -3
  27. data/app/models/account.rb +1 -0
  28. data/app/models/app_instance.rb +1 -0
  29. data/app/models/catalog.rb +1 -0
  30. data/app/models/customer_list.rb +1 -0
  31. data/app/models/hubrise_app/account_base.rb +1 -0
  32. data/app/models/hubrise_app/app_instance_base.rb +1 -0
  33. data/app/models/hubrise_app/application_record.rb +1 -0
  34. data/app/models/hubrise_app/catalog_base.rb +1 -0
  35. data/app/models/hubrise_app/customer_list_base.rb +1 -0
  36. data/app/models/hubrise_app/location_base.rb +1 -0
  37. data/app/models/hubrise_app/user_app_instance_base.rb +1 -0
  38. data/app/models/hubrise_app/user_base.rb +1 -0
  39. data/app/models/location.rb +1 -0
  40. data/app/models/user.rb +1 -0
  41. data/app/models/user_app_instance.rb +1 -0
  42. data/config/initializers/hubrise_app_config.rb +1 -0
  43. data/config/routes.rb +1 -0
  44. data/lib/hubrise_app/engine.rb +1 -0
  45. data/lib/hubrise_app/spec_support.rb +5 -2
  46. data/lib/hubrise_app/version.rb +2 -1
  47. data/lib/hubrise_app.rb +1 -0
  48. metadata +14 -15
  49. data/app/lib/hubrise_app/config_loader.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 752df0a174985157db351f3086761ff039dbeed5f8fc99e11aa9427438d1fdae
4
- data.tar.gz: 4e563cb2b305f54bc88cfe3e197c7b00eb537060b01aa1b703a0261ca8736835
3
+ metadata.gz: f60a817d70a55f7234ecdf8e886bc63c867c329c1e53f69f7a0356e049a1f266
4
+ data.tar.gz: d79c09f12c0f64a0e6d73baab22eb79cede8df9f73a90546cf93aefc5812f036
5
5
  SHA512:
6
- metadata.gz: 34248f447c609c2965bf013ead89c9399325d71578767aa21d1e5f9ccb4ceac2789dfa504f9dc25e030db89b11c537a9f0beb5abc2ef7bcaa3c8d535fd76db65
7
- data.tar.gz: b28e0a2d75bf14d46f300bbc2b78b5429c7a9c4baee544e69b78d9ec34a609b089e5c28a67113790f9c56e8c01cfed58c2d0f131ad267ef0071f306e22819e04
6
+ metadata.gz: 90c46db6e581ac2d9d46f66d24fafa37c40148459934213b3b406b193f86864f76855889c84261cfec88edc755b60e3429cd7a6e41e198902b6040c5e9a6da7d
7
+ data.tar.gz: e3c52b7505ed1b9acdc1202c873298366ac77ed705efb80ac4255171565d8dba1bf94685fc1d35619fd278a64275d880deb2f77cc4b075ba5f18650c57c4cb59
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  ![](https://github.com/hubrise/ruby-app/workflows/spec/badge.svg)
2
2
 
3
-
4
3
  ## Installation
5
4
 
6
5
  Refer to https://github.com/HubRise/ruby-app/tree/master/spec/dummy/ for examples
@@ -11,6 +10,7 @@ Refer to https://github.com/HubRise/ruby-app/tree/master/spec/dummy/ for example
11
10
  4. Mount engine routes with `mount HubriseApp::Engine => "/"`
12
11
  5. Define `hubrise_open_path` rails route (e.g. `get :hubrise_open, to: "application#open"`)
13
12
  6. Inherit your `ApplicationController` and apply fundamental `before_actions`:
13
+
14
14
  ```
15
15
  class ApplicationController < HubriseApp::ApplicationController
16
16
  before_action :ensure_authenticated!
@@ -28,6 +28,7 @@ This gem provides a framework for a Hubrise App with a Resource Based Access.
28
28
  This means that each Hubrise User will be able to create a connection (App Instance) to multiple Accounts and Locations. And this connection will be shared with any other Hubrise User that has access to the same reseources on Hubrise side automatically.
29
29
 
30
30
  ### Note
31
+
31
32
  The main app's scopes (`account_scope` and `location_scope`) must not include any kind of `profile` access. Otherwise it will make no sense to share the connection with other users.
32
33
 
33
34
  ## Documentation
@@ -36,6 +37,7 @@ The framework is based on 3 different Oauth Workflows: `Connect Workflow`, `Logi
36
37
  And 4 main entities: `User`, `AppInstance`, `Account`, `Location`.
37
38
 
38
39
  ### Connect Workflow
40
+
39
41
  Usualy this workflow gets triggered by clicking the "Install" button from the Hubrise App Market.
40
42
  It requests the main connection with the `location_scope` or `account_scope` (which are specified by developer during app creation).
41
43
 
@@ -47,16 +49,16 @@ Note: this workflow is not responsible for creating a `User` record, it **only**
47
49
 
48
50
  - If there's no user logged in - the `Login Workflow` is triggered right away by redirecting to login oauth url.
49
51
 
50
-
51
52
  Code: https://github.com/HubRise/ruby-app/tree/master/app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb
52
53
 
53
54
  ### Login Workflow
55
+
54
56
  Usualy this workflow gets triggered after `Connect Workflow` or by the `ensure_authenticated!` filter for any anon access.
55
57
  It requests `profile_with_email` scope.
56
58
  Once completed - a new `User` gets persisted in the DB with a profile `access_token` and redirected to `hubrise_open_path`.
57
59
 
58
-
59
60
  ### Authorize Workflow
61
+
60
62
  This workflow gets triggered by `ensure_app_instance_found!` whenever a logged in user does not have access (or it is expired) to `AppInstance` specified by `app_instance_id` param.
61
63
  If `app_instance_id` is not specified - its considered to be a broken request and a fatal error message is shown.
62
64
 
@@ -64,8 +66,8 @@ Note: when a user opens already installed app by clicking the button from Hubris
64
66
 
65
67
  This `app_instance_id` param is carried on from request to request using `default_url_options`: https://github.com/HubRise/ruby-app/tree/master/app/controllers/hubrise_app/application_controller/app_instance_methods.rb#L26
66
68
 
67
-
68
69
  A use case:
70
+
69
71
  1. UserA installs an app for Account1 - an `AppInstance` with `hr_id=abcd` being created
70
72
  2. UserA adds UserB as a manager to Account1 (via Hubrise Manager user roles table)
71
73
  3. UserB opens the installed app by clicking the button in the dashboard. It redirects to `open_url` with `app_instance_id=abcd`
@@ -73,9 +75,38 @@ A use case:
73
75
  5. UserB hits the `ensure_app_instance_found!` wall and agrees - a `UserAppInstace` being created for the user and `AppInstance` with `hr_id=abcd`
74
76
  6. UserB now has access to the `AppInstance`
75
77
 
76
-
77
78
  ## Extension
79
+
78
80
  TODO
79
81
 
82
+ ## Publish changes to this gem
83
+
84
+ 1. Make sure all local changes are committed.
85
+
86
+ 2. Increase version in `lib/hubrise_app/version.rb`
87
+
88
+ 3. Tag the repository:
89
+
90
+ ```bash
91
+ VERSION=1.2.1
92
+ bundle install
93
+ git add Gemfile.lock
94
+ git add lib/hubrise_app/version.rb
95
+ git commit -m "Version $VERSION"
96
+ git tag v$VERSION
97
+ git push --tags
98
+ git push
99
+ ```
100
+
101
+ 4. Build & publish:
102
+
103
+ ```bash
104
+ rm -f hubrise_app-*.gem
105
+ gem build hubrise_app
106
+ gem push hubrise_app-*.gem
107
+ rm -f hubrise_app-*.gem
108
+ ```
109
+
80
110
  ## License
111
+
81
112
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  begin
2
3
  require "bundler/setup"
3
4
  rescue LoadError
@@ -23,10 +24,10 @@ require "bundler/gem_tasks"
23
24
 
24
25
  require "rake/testtask"
25
26
 
26
- Rake::TestTask.new(:test) do |t|
27
- t.libs << "test"
28
- t.pattern = "test/**/*_test.rb"
27
+ Rake::TestTask.new(:spec) do |t|
28
+ t.libs << "spec"
29
+ t.pattern = "spec/**/*_spec.rb"
29
30
  t.verbose = false
30
31
  end
31
32
 
32
- task default: :test
33
+ task default: :spec
@@ -1,28 +1,34 @@
1
- module HubriseApp::ApplicationController::AppInstanceMethods
2
- extend ActiveSupport::Concern
3
- included do
4
- helper_method :current_app_instance
5
- end
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class ApplicationController
4
+ module AppInstanceMethods
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ helper_method :current_app_instance
8
+ end
6
9
 
7
- def hr_app_instance_id
8
- params[:app_instance_id]
9
- end
10
+ def hr_app_instance_id
11
+ params[:app_instance_id]
12
+ end
10
13
 
11
- def current_app_instance
12
- if current_user
13
- @app_instance ||= HubriseApp::Services::ResolveAppInstance.run(current_user.app_instances, hr_app_instance_id, self)
14
- end
15
- end
14
+ def current_app_instance
15
+ if current_user
16
+ @app_instance ||= HubriseApp::Services::ResolveAppInstance.run(current_user.app_instances, hr_app_instance_id,
17
+ self)
18
+ end
19
+ end
16
20
 
17
- def ensure_app_instance_found!
18
- if hr_app_instance_id.blank?
19
- render(plain: "Something went wrong. Please try to reopen from Hubrise Dashboard.")
20
- elsif current_app_instance.nil?
21
- redirect_to(build_hubrise_oauth_authorize_url, allow_other_host: true)
22
- end
23
- end
21
+ def ensure_app_instance_found!
22
+ if hr_app_instance_id.blank?
23
+ render(plain: "Something went wrong. Please try to reopen from Hubrise Dashboard.")
24
+ elsif current_app_instance.nil?
25
+ redirect_to(build_hubrise_oauth_authorize_url, allow_other_host: true)
26
+ end
27
+ end
24
28
 
25
- def default_url_options
26
- super.merge(app_instance_id: hr_app_instance_id || current_app_instance&.hr_id)
29
+ def default_url_options
30
+ super.merge(app_instance_id: hr_app_instance_id || current_app_instance&.hr_id)
31
+ end
32
+ end
27
33
  end
28
34
  end
@@ -1,25 +1,30 @@
1
- module HubriseApp::ApplicationController::HubriseGatewayMethods
2
- def hubrise_gateway
3
- @hubrise_gateway ||= HubriseApp::HubriseGateway.new
4
- end
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class ApplicationController
4
+ module HubriseGatewayMethods
5
+ def hubrise_gateway
6
+ @hubrise_gateway ||= HubriseApp::HubriseGateway.new
7
+ end
5
8
 
6
- def build_hubrise_oauth_login_url
7
- hubrise_gateway.build_login_authorization_url(build_hubrise_oauth_login_callback_url)
8
- end
9
+ def build_hubrise_oauth_login_url
10
+ hubrise_gateway.build_login_authorization_url(build_hubrise_oauth_login_callback_url)
11
+ end
9
12
 
10
- def build_hubrise_oauth_authorize_url
11
- hubrise_gateway.build_app_authorization_url(hr_app_instance_id, build_hubrise_oauth_authorize_callback_url)
12
- end
13
+ def build_hubrise_oauth_authorize_url
14
+ hubrise_gateway.build_app_authorization_url(hr_app_instance_id, build_hubrise_oauth_authorize_callback_url)
15
+ end
13
16
 
14
- def build_hubrise_oauth_login_callback_url
15
- hubrise_app.hubrise_oauth_login_callback_url
16
- end
17
+ def build_hubrise_oauth_login_callback_url
18
+ hubrise_app.hubrise_oauth_login_callback_url
19
+ end
17
20
 
18
- def build_hubrise_oauth_authorize_callback_url
19
- hubrise_app.hubrise_oauth_authorize_callback_url
20
- end
21
+ def build_hubrise_oauth_authorize_callback_url
22
+ hubrise_app.hubrise_oauth_authorize_callback_url
23
+ end
21
24
 
22
- def build_hubrise_open_url
23
- main_app.hubrise_open_path
25
+ def build_hubrise_open_url
26
+ main_app.hubrise_open_path
27
+ end
28
+ end
24
29
  end
25
30
  end
@@ -1,33 +1,38 @@
1
- module HubriseApp::ApplicationController::SessionMethods
2
- extend ActiveSupport::Concern
3
- included do
4
- protect_from_forgery with: :reset_session
5
- helper_method :current_user, :logged_in?
6
- end
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class ApplicationController
4
+ module SessionMethods
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ protect_from_forgery with: :reset_session
8
+ helper_method :current_user, :logged_in?
9
+ end
7
10
 
8
- def login(user)
9
- session[:user_id] = user.id
10
- @current_user = user
11
- end
11
+ def login(user)
12
+ session[:user_id] = user.id
13
+ @current_user = user
14
+ end
12
15
 
13
- def logout
14
- session[:user_id] = nil
15
- end
16
+ def logout
17
+ session[:user_id] = nil
18
+ end
16
19
 
17
- def current_user
18
- @current_user ||= User.where(id: session[:user_id]).take
19
- end
20
+ def current_user
21
+ @current_user ||= User.where(id: session[:user_id]).take
22
+ end
20
23
 
21
- def logged_in?
22
- !!current_user
23
- end
24
+ def logged_in?
25
+ !!current_user
26
+ end
24
27
 
25
- def ensure_authenticated!
26
- unless logged_in?
27
- redirect_to(build_hubrise_oauth_login_url, allow_other_host: true)
28
- return
29
- end
28
+ def ensure_authenticated!
29
+ unless logged_in?
30
+ redirect_to(build_hubrise_oauth_login_url, allow_other_host: true)
31
+ return
32
+ end
30
33
 
31
- yield if block_given?
34
+ yield if block_given?
35
+ end
36
+ end
32
37
  end
33
38
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class ApplicationController < ActionController::Base
3
4
  include AppInstanceMethods
@@ -1,5 +1,10 @@
1
- module HubriseApp::CallbackController::ActionDisconnect
2
- def disconnect
3
- head 200
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class CallbackController
4
+ module ActionDisconnect
5
+ def disconnect
6
+ head(200)
7
+ end
8
+ end
4
9
  end
5
10
  end
@@ -1,5 +1,10 @@
1
- module HubriseApp::CallbackController::ActionEvent
2
- def event
3
- head 200
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class CallbackController
4
+ module ActionEvent
5
+ def event
6
+ head(200)
7
+ end
8
+ end
4
9
  end
5
10
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class CallbackController < ApplicationController
3
4
  skip_before_action :verify_authenticity_token
@@ -1,12 +1,17 @@
1
- module HubriseApp::OauthController::ActionAuthorizeCallback
2
- # authorize access to specific app_instance (expirable)
3
- def authorize_callback
4
- ensure_authenticated! do
5
- if current_app_instance
6
- HubriseApp::Services::AssignAppInstance.run(current_user, current_app_instance, self)
7
- redirect_to(build_hubrise_open_url)
8
- else
9
- render(plain: "Something went wrong. Please try to reinstall the app")
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class OauthController
4
+ module ActionAuthorizeCallback
5
+ # authorize access to specific app_instance (expirable)
6
+ def authorize_callback
7
+ ensure_authenticated! do
8
+ if current_app_instance
9
+ HubriseApp::Services::AssignAppInstance.run(current_user, current_app_instance, self)
10
+ redirect_to(build_hubrise_open_url)
11
+ else
12
+ render(plain: "Something went wrong. Please try to reinstall the app")
13
+ end
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -1,12 +1,17 @@
1
- module HubriseApp::OauthController::ActionConnectCallback
2
- def connect_callback
3
- @app_instance = HubriseApp::Services::ConnectAppInstance.run(api_client_from_oauth_code, self)
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class OauthController
4
+ module ActionConnectCallback
5
+ def connect_callback
6
+ @app_instance = HubriseApp::Services::ConnectAppInstance.run(api_client_from_oauth_code, self)
4
7
 
5
- if logged_in?
6
- HubriseApp::Services::AssignAppInstance.run(current_user, @app_instance, self)
7
- redirect_to(build_hubrise_open_url)
8
- else
9
- redirect_to(build_hubrise_oauth_login_url, allow_other_host: true)
8
+ if logged_in?
9
+ HubriseApp::Services::AssignAppInstance.run(current_user, @app_instance, self)
10
+ redirect_to(build_hubrise_open_url)
11
+ else
12
+ redirect_to(build_hubrise_oauth_login_url, allow_other_host: true)
13
+ end
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -1,7 +1,12 @@
1
- module HubriseApp::OauthController::ActionLoginCallback
2
- def login_callback
3
- user = HubriseApp::Refresher::User.from_api_client(api_client_from_oauth_code)
4
- login(user)
5
- redirect_to(build_hubrise_open_url)
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class OauthController
4
+ module ActionLoginCallback
5
+ def login_callback
6
+ user = HubriseApp::Refresher::User.from_api_client(api_client_from_oauth_code)
7
+ login(user)
8
+ redirect_to(build_hubrise_open_url)
9
+ end
10
+ end
6
11
  end
7
12
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class OauthController < ApplicationController
3
4
  include ActionLoginCallback
@@ -8,8 +9,8 @@ module HubriseApp
8
9
 
9
10
  def current_app_instance
10
11
  @app_instance ||= HubriseApp::Services::ResolveAppInstance.run(
11
- AppInstance, api_client_from_oauth_code.app_instance_id, self
12
- )
12
+ AppInstance, api_client_from_oauth_code.app_instance_id, self
13
+ )
13
14
  end
14
15
 
15
16
  def api_client_from_oauth_code
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class SessionsController < ApplicationController
3
4
  before_action :ensure_authenticated!
@@ -1,58 +1,61 @@
1
- class HubriseApp::HubriseGateway
2
- HUBRISE_LOGIN_SCOPE = "profile_with_email".freeze
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class HubriseGateway
4
+ HUBRISE_LOGIN_SCOPE = "profile_with_email"
3
5
 
4
- def initialize(config = HubriseApp::CONFIG)
5
- @config = config
6
- end
6
+ def initialize(config = HubriseApp::CONFIG)
7
+ @config = config
8
+ end
7
9
 
8
- def build_api_client(params = {})
9
- HubriseClient::V1.new(
10
- @config[:hubrise_client_id],
11
- @config[:hubrise_client_secret],
12
- params.merge(
13
- oauth_host: @config[:hubrise_oauth_host],
14
- oauth_port: @config[:hubrise_oauth_port],
15
- api_host: @config[:hubrise_api_host],
16
- api_port: @config[:hubrise_api_port],
17
- use_https: @config[:hubrise_use_https]
10
+ def build_api_client(params = {})
11
+ HubriseClient::V1.new(
12
+ @config[:hubrise_client_id],
13
+ @config[:hubrise_client_secret],
14
+ params.merge(
15
+ oauth_host: @config[:hubrise_oauth_host],
16
+ oauth_port: @config[:hubrise_oauth_port],
17
+ api_host: @config[:hubrise_api_host],
18
+ api_port: @config[:hubrise_api_port],
19
+ use_https: @config[:hubrise_use_https]
20
+ )
18
21
  )
19
- )
20
- end
22
+ end
21
23
 
22
- def build_api_client_from_app_instance(app_instance)
23
- build_api_client(
24
- access_token: app_instance.access_token,
25
- app_instance_id: app_instance.hr_id,
26
- account_id: app_instance.hr_account_id,
27
- location_id: app_instance.hr_location_id,
28
- catalog_id: app_instance.hr_catalog_id,
29
- customer_list_id: app_instance.hr_customer_list_id
30
- )
31
- end
24
+ def build_api_client_from_app_instance(app_instance)
25
+ build_api_client(
26
+ access_token: app_instance.access_token,
27
+ app_instance_id: app_instance.hr_id,
28
+ account_id: app_instance.hr_account_id,
29
+ location_id: app_instance.hr_location_id,
30
+ catalog_id: app_instance.hr_catalog_id,
31
+ customer_list_id: app_instance.hr_customer_list_id
32
+ )
33
+ end
32
34
 
33
- def build_api_client_from_authorization_code(authorization_code)
34
- build_api_client.tap do |api_client|
35
- api_client.authorize!(authorization_code)
35
+ def build_api_client_from_authorization_code(authorization_code)
36
+ build_api_client.tap do |api_client|
37
+ api_client.authorize!(authorization_code)
38
+ end
36
39
  end
37
- end
38
40
 
39
- def build_login_authorization_url(redirect_uri)
40
- build_api_client.build_authorization_url(redirect_uri, HUBRISE_LOGIN_SCOPE)
41
- end
41
+ def build_login_authorization_url(redirect_uri)
42
+ build_api_client.build_authorization_url(redirect_uri, HUBRISE_LOGIN_SCOPE)
43
+ end
42
44
 
43
- def build_app_authorization_url(hr_app_instance_id, redirect_uri)
44
- build_api_client.build_authorization_url(redirect_uri, nil, app_instance_id: hr_app_instance_id)
45
- end
45
+ def build_app_authorization_url(hr_app_instance_id, redirect_uri)
46
+ build_api_client.build_authorization_url(redirect_uri, nil, app_instance_id: hr_app_instance_id)
47
+ end
46
48
 
47
- def valid_hmac?(body, request_hmac)
48
- calculated_hmac = OpenSSL::HMAC.hexdigest(
49
- OpenSSL::Digest.new("sha256"),
50
- @config[:hubrise_client_secret],
51
- body
52
- )
53
- ActiveSupport::SecurityUtils.secure_compare(
54
- calculated_hmac,
55
- request_hmac || ""
56
- )
49
+ def valid_hmac?(body, request_hmac)
50
+ calculated_hmac = OpenSSL::HMAC.hexdigest(
51
+ OpenSSL::Digest.new("sha256"),
52
+ @config[:hubrise_client_secret],
53
+ body
54
+ )
55
+ ActiveSupport::SecurityUtils.secure_compare(
56
+ calculated_hmac,
57
+ request_hmac || ""
58
+ )
59
+ end
57
60
  end
58
61
  end
@@ -1,14 +1,17 @@
1
- module HubriseApp::Refresher
2
- class Account < Base
3
- class << self
4
- def fetch_attributes(resource, api_client)
5
- {
6
- api_data: if api_client.location_id
7
- api_client.get_location(api_client.location_id).data["account"]
8
- else
9
- api_client.get_account(resource.hr_id).data
10
- end.except("id")
11
- }
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class Account < Base
5
+ class << self
6
+ def fetch_attributes(resource, api_client)
7
+ {
8
+ api_data: if api_client.location_id
9
+ api_client.get_location(api_client.location_id).data["account"]
10
+ else
11
+ api_client.get_account(resource.hr_id).data
12
+ end.except("id"),
13
+ }
14
+ end
12
15
  end
13
16
  end
14
17
  end
@@ -1,23 +1,26 @@
1
- module HubriseApp::Refresher
2
- class AppInstance < Base
3
- class << self
4
- def run(resource, api_client, *refresher_args)
5
- resource.update!(
6
- access_token: api_client.access_token,
7
- account: HubriseApp::Refresher::Account.from_api_client(
8
- api_client, *refresher_args
9
- ),
10
- location: HubriseApp::Refresher::Location.from_api_client(
11
- api_client, *refresher_args
12
- ),
13
- catalog: HubriseApp::Refresher::Catalog.from_api_client(
14
- api_client, *refresher_args
15
- ),
16
- customer_list: HubriseApp::Refresher::CustomerList.from_api_client(
17
- api_client, *refresher_args
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class AppInstance < Base
5
+ class << self
6
+ def run(resource, api_client, *refresher_args)
7
+ resource.update!(
8
+ access_token: api_client.access_token,
9
+ account: HubriseApp::Refresher::Account.from_api_client(
10
+ api_client, *refresher_args
11
+ ),
12
+ location: HubriseApp::Refresher::Location.from_api_client(
13
+ api_client, *refresher_args
14
+ ),
15
+ catalog: HubriseApp::Refresher::Catalog.from_api_client(
16
+ api_client, *refresher_args
17
+ ),
18
+ customer_list: HubriseApp::Refresher::CustomerList.from_api_client(
19
+ api_client, *refresher_args
20
+ )
18
21
  )
19
- )
20
- resource
22
+ resource
23
+ end
21
24
  end
22
25
  end
23
26
  end
@@ -1,45 +1,50 @@
1
- class HubriseApp::Refresher::Base
2
- REFRESH_THRESHOLD = 1.day
3
-
4
- class << self
5
- def from_api_client(api_client, *args)
6
- hr_id = api_client.public_send(id_key)
7
- if hr_id
8
- run(
9
- model_factory.find_or_initialize_by(hr_id: hr_id),
10
- api_client,
11
- *args
12
- )
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class Base
5
+ REFRESH_THRESHOLD = 1.day
6
+
7
+ class << self
8
+ def from_api_client(api_client, *args)
9
+ hr_id = api_client.public_send(id_key)
10
+ if hr_id
11
+ run(
12
+ model_factory.find_or_initialize_by(hr_id:),
13
+ api_client,
14
+ *args
15
+ )
16
+ end
17
+ end
18
+
19
+ def run(resource, api_client, force: false)
20
+ return resource if !stale?(resource) && !force
21
+
22
+ resource.update!(
23
+ fetch_attributes(resource, api_client).merge(
24
+ refreshed_at: Time.now,
25
+ )
26
+ )
27
+ resource
28
+ end
29
+
30
+ protected
31
+
32
+ def fetch_attributes(_resource, _api_client)
33
+ {}
34
+ end
35
+
36
+ def stale?(resource)
37
+ resource.refreshed_at.nil? || Time.now - resource.refreshed_at > REFRESH_THRESHOLD
38
+ end
39
+
40
+ def model_factory
41
+ const_get("::" + name.demodulize)
42
+ end
43
+
44
+ def id_key
45
+ name.demodulize.underscore + "_id"
46
+ end
13
47
  end
14
48
  end
15
-
16
- def run(resource, api_client, force: false)
17
- return resource if !stale?(resource) && !force
18
-
19
- resource.update!(
20
- fetch_attributes(resource, api_client).merge(
21
- refreshed_at: Time.now,
22
- )
23
- )
24
- resource
25
- end
26
-
27
- protected
28
-
29
- def fetch_attributes(_resource, _api_client)
30
- {}
31
- end
32
-
33
- def stale?(resource)
34
- resource.refreshed_at.nil? || Time.now - resource.refreshed_at > REFRESH_THRESHOLD
35
- end
36
-
37
- def model_factory
38
- const_get("::" + self.name.demodulize)
39
- end
40
-
41
- def id_key
42
- self.name.demodulize.underscore + "_id"
43
- end
44
49
  end
45
50
  end
@@ -1,12 +1,15 @@
1
- module HubriseApp::Refresher
2
- class Catalog < Base
3
- class << self
4
- def fetch_attributes(resource, api_client)
5
- {
6
- api_data: api_client.get_catalog(resource.hr_id, hide_data: true)
7
- .data
8
- .except("id")
9
- }
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class Catalog < Base
5
+ class << self
6
+ def fetch_attributes(resource, api_client)
7
+ {
8
+ api_data: api_client.get_catalog(resource.hr_id, hide_data: true)
9
+ .data
10
+ .except("id"),
11
+ }
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -1,12 +1,15 @@
1
- module HubriseApp::Refresher
2
- class CustomerList < Base
3
- class << self
4
- def fetch_attributes(resource, api_client)
5
- {
6
- api_data: api_client.get_customer_list(resource.hr_id)
7
- .data
8
- .except("id")
9
- }
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class CustomerList < Base
5
+ class << self
6
+ def fetch_attributes(resource, api_client)
7
+ {
8
+ api_data: api_client.get_customer_list(resource.hr_id)
9
+ .data
10
+ .except("id"),
11
+ }
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -1,12 +1,15 @@
1
- module HubriseApp::Refresher
2
- class Location < Base
3
- class << self
4
- def fetch_attributes(resource, api_client)
5
- {
6
- api_data: api_client.get_location(resource.hr_id)
7
- .data
8
- .except("id", "account")
9
- }
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class Location < Base
5
+ class << self
6
+ def fetch_attributes(resource, api_client)
7
+ {
8
+ api_data: api_client.get_location(resource.hr_id)
9
+ .data
10
+ .except("id", "account"),
11
+ }
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -1,15 +1,18 @@
1
- module HubriseApp::Refresher
2
- class User < Base
3
- class << self
4
- def fetch_attributes(resource, api_client)
5
- api_data = api_client.get_user.data
6
- {
7
- access_token: api_client.access_token,
8
- email: api_data["email"],
9
- first_name: api_data["first_name"],
10
- last_name: api_data["last_name"],
11
- locales: api_data["locales"]
12
- }
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Refresher
4
+ class User < Base
5
+ class << self
6
+ def fetch_attributes(_resource, api_client)
7
+ api_data = api_client.get_user.data
8
+ {
9
+ access_token: api_client.access_token,
10
+ email: api_data["email"],
11
+ first_name: api_data["first_name"],
12
+ last_name: api_data["last_name"],
13
+ locales: api_data["locales"],
14
+ }
15
+ end
13
16
  end
14
17
  end
15
18
  end
@@ -1,8 +1,13 @@
1
- class HubriseApp::Services::AssignAppInstance
2
- def self.run(hr_user, hr_app_instance, _ctx)
3
- UserAppInstance.find_or_initialize_by(
4
- hr_app_instance_id: hr_app_instance.hr_id,
5
- hr_user_id: hr_user.hr_id
6
- ).update!(refreshed_at: Time.now)
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Services
4
+ class AssignAppInstance
5
+ def self.run(hr_user, hr_app_instance, _ctx)
6
+ UserAppInstance.find_or_initialize_by(
7
+ hr_app_instance_id: hr_app_instance.hr_id,
8
+ hr_user_id: hr_user.hr_id
9
+ ).update!(refreshed_at: Time.now)
10
+ end
11
+ end
7
12
  end
8
13
  end
@@ -1,5 +1,10 @@
1
- class HubriseApp::Services::ConnectAppInstance
2
- def self.run(api_client, _ctx)
3
- HubriseApp::Refresher::AppInstance.from_api_client(api_client)
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Services
4
+ class ConnectAppInstance
5
+ def self.run(api_client, _ctx)
6
+ HubriseApp::Refresher::AppInstance.from_api_client(api_client)
7
+ end
8
+ end
4
9
  end
5
10
  end
@@ -1,5 +1,10 @@
1
- class HubriseApp::Services::ResolveAppInstance
2
- def self.run(scope, id, _ctx)
3
- scope.where(hr_id: id).take
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ module Services
4
+ class ResolveAppInstance
5
+ def self.run(scope, id, _ctx)
6
+ scope.where(hr_id: id).take
7
+ end
8
+ end
4
9
  end
5
10
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class Account < HubriseApp::AccountBase
2
3
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class AppInstance < HubriseApp::AppInstanceBase
2
3
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class Catalog < HubriseApp::CatalogBase
2
3
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class CustomerList < HubriseApp::CustomerListBase
2
3
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class AccountBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class AppInstanceBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class ApplicationRecord < ActiveRecord::Base
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class CatalogBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class CustomerListBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class LocationBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class UserAppInstanceBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class UserBase < HubriseApp::ApplicationRecord
3
4
  self.abstract_class = true
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class Location < HubriseApp::LocationBase
2
3
  end
data/app/models/user.rb CHANGED
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class User < HubriseApp::UserBase
2
3
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class UserAppInstance < HubriseApp::UserAppInstanceBase
2
3
  end
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  HubriseApp::CONFIG = HubriseApp::ConfigLoader.load
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  HubriseApp::Engine.routes.draw do
2
3
  namespace :hubrise_oauth, controller: "/hubrise_app/oauth" do
3
4
  get :connect_callback
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
3
  class Engine < ::Rails::Engine
3
4
  isolate_namespace HubriseApp
@@ -1,3 +1,6 @@
1
- class HubriseApp::SpecSupport
2
- FACTORIES_PATH = File.expand_path("../../spec/factories", __dir__)
1
+ # frozen_string_literal: true
2
+ module HubriseApp
3
+ class SpecSupport
4
+ FACTORIES_PATH = File.expand_path("../../spec/factories", __dir__)
5
+ end
3
6
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module HubriseApp
2
- VERSION = "1.1.1".freeze
3
+ VERSION = "1.2.1"
3
4
  end
data/lib/hubrise_app.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "hubrise_app/engine"
2
3
  require "hubrise_client"
3
4
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubrise_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Monnier
8
8
  - Nick Save
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-21 00:00:00.000000000 Z
12
+ date: 2024-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hubrise_client
@@ -17,30 +17,30 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.0.6
20
+ version: 2.0.10
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.0.6
27
+ version: 2.0.10
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rails
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">"
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 5.2.2
34
+ version: 7.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">"
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 5.2.2
42
- description:
43
- email:
41
+ version: 7.0.0
42
+ description:
43
+ email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -62,7 +62,6 @@ files:
62
62
  - app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb
63
63
  - app/controllers/hubrise_app/oauth_controller/action_login_callback.rb
64
64
  - app/controllers/hubrise_app/sessions_controller.rb
65
- - app/lib/hubrise_app/config_loader.rb
66
65
  - app/lib/hubrise_app/hubrise_gateway.rb
67
66
  - app/lib/hubrise_app/refresher/account.rb
68
67
  - app/lib/hubrise_app/refresher/app_instance.rb
@@ -106,7 +105,7 @@ homepage: https://github.com/HubRise/ruby-app
106
105
  licenses:
107
106
  - MIT
108
107
  metadata: {}
109
- post_install_message:
108
+ post_install_message:
110
109
  rdoc_options: []
111
110
  require_paths:
112
111
  - lib
@@ -121,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
120
  - !ruby/object:Gem::Version
122
121
  version: '0'
123
122
  requirements: []
124
- rubygems_version: 3.1.2
125
- signing_key:
123
+ rubygems_version: 3.3.26
124
+ signing_key:
126
125
  specification_version: 4
127
126
  summary: Rails engine to bootstrap a HubRise-based application
128
127
  test_files: []
@@ -1,5 +0,0 @@
1
- class HubriseApp::ConfigLoader
2
- def self.load
3
- Rails.application.config_for("hubrise_app/config").deep_symbolize_keys
4
- end
5
- end