hubrise_app 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -5
- data/Rakefile +5 -4
- data/app/controllers/hubrise_app/application_controller/app_instance_methods.rb +28 -22
- data/app/controllers/hubrise_app/application_controller/hubrise_gateway_methods.rb +23 -18
- data/app/controllers/hubrise_app/application_controller/session_methods.rb +30 -25
- data/app/controllers/hubrise_app/application_controller.rb +1 -0
- data/app/controllers/hubrise_app/callback_controller/action_disconnect.rb +8 -3
- data/app/controllers/hubrise_app/callback_controller/action_event.rb +8 -3
- data/app/controllers/hubrise_app/callback_controller.rb +1 -0
- data/app/controllers/hubrise_app/oauth_controller/action_authorize_callback.rb +14 -9
- data/app/controllers/hubrise_app/oauth_controller/action_connect_callback.rb +13 -8
- data/app/controllers/hubrise_app/oauth_controller/action_login_callback.rb +10 -5
- data/app/controllers/hubrise_app/oauth_controller.rb +3 -2
- data/app/controllers/hubrise_app/sessions_controller.rb +1 -0
- data/app/lib/hubrise_app/hubrise_gateway.rb +50 -47
- data/app/lib/hubrise_app/refresher/account.rb +14 -11
- data/app/lib/hubrise_app/refresher/app_instance.rb +22 -19
- data/app/lib/hubrise_app/refresher/base.rb +46 -41
- data/app/lib/hubrise_app/refresher/catalog.rb +12 -9
- data/app/lib/hubrise_app/refresher/customer_list.rb +12 -9
- data/app/lib/hubrise_app/refresher/location.rb +12 -9
- data/app/lib/hubrise_app/refresher/user.rb +15 -12
- data/app/lib/hubrise_app/services/assign_app_instance.rb +11 -6
- data/app/lib/hubrise_app/services/connect_app_instance.rb +8 -3
- data/app/lib/hubrise_app/services/resolve_app_instance.rb +8 -3
- data/app/models/account.rb +1 -0
- data/app/models/app_instance.rb +1 -0
- data/app/models/catalog.rb +1 -0
- data/app/models/customer_list.rb +1 -0
- data/app/models/hubrise_app/account_base.rb +1 -0
- data/app/models/hubrise_app/app_instance_base.rb +1 -0
- data/app/models/hubrise_app/application_record.rb +1 -0
- data/app/models/hubrise_app/catalog_base.rb +1 -0
- data/app/models/hubrise_app/customer_list_base.rb +1 -0
- data/app/models/hubrise_app/location_base.rb +1 -0
- data/app/models/hubrise_app/user_app_instance_base.rb +1 -0
- data/app/models/hubrise_app/user_base.rb +1 -0
- data/app/models/location.rb +1 -0
- data/app/models/user.rb +1 -0
- data/app/models/user_app_instance.rb +1 -0
- data/config/initializers/hubrise_app_config.rb +1 -0
- data/config/routes.rb +1 -0
- data/lib/hubrise_app/engine.rb +1 -0
- data/lib/hubrise_app/spec_support.rb +5 -2
- data/lib/hubrise_app/version.rb +2 -1
- data/lib/hubrise_app.rb +1 -0
- metadata +14 -15
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc1ad8b133e071ede39b2475c6d4e661312914183c5c19d7c88d92fe8ead7aa8
|
4
|
+
data.tar.gz: 380e301179f96683fedb6035290683fc2ed159136edd3b76eadee3510e6afe51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b19fa296bf31607a5665c2da87fe82496bbc06ed863867ff273b0e8f2491ebaaa694ed708cf5fd4d4ea1366cea8e7dbab4276ef9b90f3e5a0d445f11e31a724
|
7
|
+
data.tar.gz: fa56d7c3ca097348fc38854e93d7e5270080b53ecf8c645bf17159c89f88c9390400bb767da8d27cca41a45b94cbc68508333e71b75ed334f5b61af8f6394b53
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|

|
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,36 @@ 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.0
|
92
|
+
git add lib/hubrise_app/version.rb
|
93
|
+
git commit -m "Version $VERSION"
|
94
|
+
git tag v$VERSION
|
95
|
+
git push --tags
|
96
|
+
git push
|
97
|
+
```
|
98
|
+
|
99
|
+
4. Build & publish:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
rm -f hubrise_app-*.gem
|
103
|
+
gem build hubrise_app
|
104
|
+
gem push hubrise_app-*.gem
|
105
|
+
rm -f hubrise_app-*.gem
|
106
|
+
```
|
107
|
+
|
80
108
|
## License
|
109
|
+
|
81
110
|
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(:
|
27
|
-
t.libs << "
|
28
|
-
t.pattern = "
|
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: :
|
33
|
+
task default: :spec
|
@@ -1,28 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def hr_app_instance_id
|
11
|
+
params[:app_instance_id]
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def build_hubrise_oauth_login_callback_url
|
18
|
+
hubrise_app.hubrise_oauth_login_callback_url
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def build_hubrise_oauth_authorize_callback_url
|
22
|
+
hubrise_app.hubrise_oauth_authorize_callback_url
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def login(user)
|
12
|
+
session[:user_id] = user.id
|
13
|
+
@current_user = user
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
def logout
|
17
|
+
session[:user_id] = nil
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
def current_user
|
21
|
+
@current_user ||= User.where(id: session[:user_id]).take
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
def logged_in?
|
25
|
+
!!current_user
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
34
|
+
yield if block_given?
|
35
|
+
end
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
@@ -1,12 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
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,58 +1,61 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module HubriseApp
|
3
|
+
class HubriseGateway
|
4
|
+
HUBRISE_LOGIN_SCOPE = "profile_with_email"
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
def initialize(config = HubriseApp::CONFIG)
|
7
|
+
@config = config
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
api_client,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
+
resource
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -1,45 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
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
|
data/app/models/account.rb
CHANGED
data/app/models/app_instance.rb
CHANGED
data/app/models/catalog.rb
CHANGED
data/app/models/customer_list.rb
CHANGED
data/app/models/location.rb
CHANGED
data/app/models/user.rb
CHANGED
data/config/routes.rb
CHANGED
data/lib/hubrise_app/engine.rb
CHANGED
data/lib/hubrise_app/version.rb
CHANGED
data/lib/hubrise_app.rb
CHANGED
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.
|
4
|
+
version: 1.2.0
|
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:
|
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.
|
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.
|
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:
|
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:
|
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.
|
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: []
|