forest_liana 2.0.4 → 2.1.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/app/controllers/forest_liana/sessions_controller.rb +22 -1
- data/app/services/forest_liana/allowed_users_getter.rb +18 -36
- data/app/services/forest_liana/google_authorized_user_getter.rb +28 -0
- data/app/services/forest_liana/users_getter.rb +39 -0
- data/config/routes.rb +1 -0
- data/lib/forest_liana/version.rb +1 -1
- data/test/routing/route_test.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4db7e02922415856e04fdc54fb7b4557853d253
|
|
4
|
+
data.tar.gz: 392d8c62c9766398b3373b530a77877ee195a78f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e330eafe8a7a2c9e81fd37037ea2703bf671821de2161bccb8e903807028f0aa01299bc0cf3edea500bccb3b6ecd984f33e5d3d4cd69922659fe6394b7e9b57
|
|
7
|
+
data.tar.gz: 03d746ad20c557fcd7ee569c62ab7983103703b38edfff8bce6a968b471dfb49a73a7cd1745eb50c521f9c355bba027438378155a872232b42caf6544d8795d4
|
|
@@ -24,6 +24,27 @@ module ForestLiana
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def create_with_google
|
|
28
|
+
@error_message = nil
|
|
29
|
+
|
|
30
|
+
rendering_id = params['renderingId']
|
|
31
|
+
forest_token = params['forestToken']
|
|
32
|
+
|
|
33
|
+
user = GoogleAuthorizedUserGetter.new(rendering_id, forest_token).perform()
|
|
34
|
+
token = encode_token(user) if user
|
|
35
|
+
|
|
36
|
+
if token
|
|
37
|
+
render json: { token: token }, serializer: nil
|
|
38
|
+
else
|
|
39
|
+
if @error_message
|
|
40
|
+
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
|
|
41
|
+
[{ detail: @error_message }]), status: :unauthorized
|
|
42
|
+
else
|
|
43
|
+
head :unauthorized
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
27
48
|
private
|
|
28
49
|
|
|
29
50
|
def check_user
|
|
@@ -43,7 +64,7 @@ module ForestLiana
|
|
|
43
64
|
end
|
|
44
65
|
|
|
45
66
|
def fetch_allowed_users
|
|
46
|
-
AllowedUsersGetter.new
|
|
67
|
+
AllowedUsersGetter.new(params['renderingId']).perform()
|
|
47
68
|
end
|
|
48
69
|
|
|
49
70
|
def has_internal_authentication?
|
|
@@ -1,45 +1,27 @@
|
|
|
1
1
|
module ForestLiana
|
|
2
|
-
class AllowedUsersGetter
|
|
3
|
-
def
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
http.use_ssl = true if forest_url.start_with?('https')
|
|
7
|
-
|
|
8
|
-
begin
|
|
9
|
-
http.start do |client|
|
|
10
|
-
request = Net::HTTP::Get.new(uri.path)
|
|
11
|
-
request['Content-Type'] = 'application/json'
|
|
12
|
-
request['forest-secret-key'] = ForestLiana.env_secret
|
|
13
|
-
response = client.request(request)
|
|
2
|
+
class AllowedUsersGetter < UsersGetter
|
|
3
|
+
def initialize(rendering_id)
|
|
4
|
+
super('allowed-users', rendering_id)
|
|
5
|
+
end
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
def handle_service_response(response)
|
|
8
|
+
if response.is_a?(Net::HTTPOK)
|
|
9
|
+
body = JSON.parse(response.body)
|
|
10
|
+
ForestLiana.allowed_users = body['data'].map do |d|
|
|
11
|
+
user = d['attributes']
|
|
12
|
+
user['id'] = d['id']
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
elsif response.is_a?(Net::HTTPNotFound)
|
|
24
|
-
FOREST_LOGGER.error "Cannot retrieve the project you\'re trying " \
|
|
25
|
-
"to unlock. Can you check that you properly copied the Forest " \
|
|
26
|
-
"env_secret in the forest_liana initializer?"
|
|
27
|
-
else
|
|
28
|
-
FOREST_LOGGER.error "Cannot retrieve any users for the project " \
|
|
29
|
-
"you\'re trying to unlock. An error occured in Forest API."
|
|
30
|
-
[]
|
|
31
|
-
end
|
|
14
|
+
user
|
|
32
15
|
end
|
|
33
|
-
|
|
16
|
+
elsif response.is_a?(Net::HTTPNotFound)
|
|
17
|
+
FOREST_LOGGER.error "Cannot retrieve the project you\'re trying " \
|
|
18
|
+
"to unlock. Can you check that you properly copied the Forest " \
|
|
19
|
+
"env_secret in the forest_liana initializer?"
|
|
20
|
+
else
|
|
34
21
|
FOREST_LOGGER.error "Cannot retrieve any users for the project " \
|
|
35
|
-
"you\'re trying to unlock.
|
|
22
|
+
"you\'re trying to unlock. An error occured in Forest API."
|
|
23
|
+
[]
|
|
36
24
|
end
|
|
37
25
|
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def forest_url
|
|
42
|
-
ENV['FOREST_URL'] || 'https://forestadmin-server.herokuapp.com';
|
|
43
|
-
end
|
|
44
26
|
end
|
|
45
27
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module ForestLiana
|
|
2
|
+
class GoogleAuthorizedUserGetter < UsersGetter
|
|
3
|
+
def initialize(rendering_id, forest_token)
|
|
4
|
+
@forest_token = forest_token
|
|
5
|
+
super('google-authorization', rendering_id)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def handle_service_response(response)
|
|
9
|
+
if response.is_a?(Net::HTTPOK)
|
|
10
|
+
body = JSON.parse(response.body)
|
|
11
|
+
body['data']['attributes']
|
|
12
|
+
elsif response.is_a?(Net::HTTPNotFound)
|
|
13
|
+
FOREST_LOGGER.error "Cannot retrieve the project you\'re trying " \
|
|
14
|
+
"to unlock. Can you check that you properly copied the Forest " \
|
|
15
|
+
"env_secret in the forest_liana initializer?"
|
|
16
|
+
nil
|
|
17
|
+
elsif response.is_a?(Net::HTTPUnauthorized)
|
|
18
|
+
FOREST_LOGGER.error "Cannot retrieve the user for the project " \
|
|
19
|
+
"you\'re trying to unlock. The google user account seems invalid."
|
|
20
|
+
nil
|
|
21
|
+
else
|
|
22
|
+
FOREST_LOGGER.error "Cannot retrieve the user for the project " \
|
|
23
|
+
"you\'re trying to unlock. An error occured in Forest API."
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module ForestLiana
|
|
2
|
+
class UsersGetter
|
|
3
|
+
def initialize(endpoint, rendering_id)
|
|
4
|
+
@uri = URI.parse("#{forest_url}/forest/renderings/#{rendering_id}/#{endpoint}")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def perform
|
|
8
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
|
9
|
+
http.use_ssl = true if forest_url.start_with?('https')
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
http.start do |client|
|
|
13
|
+
request = Net::HTTP::Get.new(@uri.path)
|
|
14
|
+
request['Content-Type'] = 'application/json'
|
|
15
|
+
request['forest-secret-key'] = ForestLiana.env_secret
|
|
16
|
+
request['forest-token'] = @forest_token if @forest_token
|
|
17
|
+
response = client.request(request)
|
|
18
|
+
|
|
19
|
+
handle_service_response(response)
|
|
20
|
+
end
|
|
21
|
+
rescue => exception
|
|
22
|
+
puts exception
|
|
23
|
+
FOREST_LOGGER.error "Cannot retrieve any users for the project " \
|
|
24
|
+
"you\'re trying to unlock. Forest API seems to be down right now."
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def forest_url
|
|
32
|
+
ENV['FOREST_URL'] || 'https://api.forestadmin.com';
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def handle_service_response
|
|
36
|
+
raise 'Abstract class method, this method must be implemented.'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/forest_liana/version.rb
CHANGED
data/test/routing/route_test.rb
CHANGED
|
@@ -20,6 +20,11 @@ module ForestLiana
|
|
|
20
20
|
}, {
|
|
21
21
|
controller: 'forest_liana/sessions', action: 'create'
|
|
22
22
|
})
|
|
23
|
+
assert_routing({
|
|
24
|
+
method: 'post', path: 'sessions-google'
|
|
25
|
+
}, {
|
|
26
|
+
controller: 'forest_liana/sessions', action: 'create_with_google'
|
|
27
|
+
})
|
|
23
28
|
|
|
24
29
|
# Associations
|
|
25
30
|
assert_routing({
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_liana
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sandro Munda
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-01-
|
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -171,6 +171,7 @@ files:
|
|
|
171
171
|
- app/services/forest_liana/base_getter.rb
|
|
172
172
|
- app/services/forest_liana/belongs_to_updater.rb
|
|
173
173
|
- app/services/forest_liana/controller_factory.rb
|
|
174
|
+
- app/services/forest_liana/google_authorized_user_getter.rb
|
|
174
175
|
- app/services/forest_liana/has_many_associator.rb
|
|
175
176
|
- app/services/forest_liana/has_many_dissociator.rb
|
|
176
177
|
- app/services/forest_liana/has_many_getter.rb
|
|
@@ -200,6 +201,7 @@ files:
|
|
|
200
201
|
- app/services/forest_liana/stripe_sources_getter.rb
|
|
201
202
|
- app/services/forest_liana/stripe_subscription_getter.rb
|
|
202
203
|
- app/services/forest_liana/stripe_subscriptions_getter.rb
|
|
204
|
+
- app/services/forest_liana/users_getter.rb
|
|
203
205
|
- app/services/forest_liana/value_stat_getter.rb
|
|
204
206
|
- app/views/layouts/forest_liana/application.html.erb
|
|
205
207
|
- config/initializers/arel-helpers.rb
|