forest_liana 1.1.35 → 1.2.1
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/application_controller.rb +9 -3
- data/app/controllers/forest_liana/sessions_controller.rb +37 -0
- data/app/controllers/forest_liana/stats_controller.rb +4 -16
- data/app/serializers/forest_liana/session_serializer.rb +33 -0
- data/app/services/forest_liana/activity_logger.rb +6 -11
- data/app/services/forest_liana/resources_getter.rb +1 -1
- data/config/routes.rb +3 -0
- data/lib/forest_liana.rb +8 -1
- data/lib/forest_liana/bootstraper.rb +17 -2
- data/lib/forest_liana/engine.rb +2 -0
- data/lib/forest_liana/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ac7636dfc1feb757f7c5c1632617b8526c55d8
|
4
|
+
data.tar.gz: cdbec10534de350dfe9ab812a2895d637fc089aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 956f4acbc70dac684dadb23eb47db50e0304fe2846f9b6691c3d1b7e32f708102a3ec226db8b4215756fdaa29a8be4116cbc5a543f8c4aed17620c00787a2a5b
|
7
|
+
data.tar.gz: dcb47a3daa227866faa6b6fd2529952c0974f8bd916a03ffe44cc45a5dcb5d67a55108589ec06aa18add6504a51291fe8b5b24e4a4ce8f185ae75e179e4a0fef
|
@@ -32,9 +32,15 @@ module ForestLiana
|
|
32
32
|
|
33
33
|
def authenticate_user_from_jwt
|
34
34
|
if request.headers['Authorization']
|
35
|
-
|
36
|
-
request.headers['Authorization'].split
|
37
|
-
ForestLiana.
|
35
|
+
begin
|
36
|
+
token = request.headers['Authorization'].split.second
|
37
|
+
@jwt_decoded_token = JWT.decode(token, ForestLiana.auth_key, true, {
|
38
|
+
algorithm: 'HS256',
|
39
|
+
leeway: 30
|
40
|
+
}).try(:first)
|
41
|
+
rescue JWT::ExpiredSignature, JWT::VerificationError
|
42
|
+
render json: { error: 'expired_token' }, status: 401
|
43
|
+
end
|
38
44
|
else
|
39
45
|
render nothing: true, status: 401
|
40
46
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class SessionsController < ActionController::Base
|
3
|
+
|
4
|
+
def create
|
5
|
+
user = ForestLiana.allowed_users.find do |allowed_user|
|
6
|
+
allowed_user['email'] == params['email'] &&
|
7
|
+
BCrypt::Password.new(allowed_user['password']) == params['password']
|
8
|
+
end
|
9
|
+
|
10
|
+
if user
|
11
|
+
token = JWT.encode({
|
12
|
+
exp: Time.now.to_i + 2.weeks.to_i,
|
13
|
+
data: serialized_user(user)
|
14
|
+
} , ForestLiana.auth_key, 'HS256')
|
15
|
+
|
16
|
+
render json: { token: token }
|
17
|
+
else
|
18
|
+
render nothing: true, status: 401
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def serialized_user(user)
|
25
|
+
{
|
26
|
+
type: 'users',
|
27
|
+
id: user[:id],
|
28
|
+
data: {
|
29
|
+
email: user[:email],
|
30
|
+
first_name: user[:'first-name'] ,
|
31
|
+
last_name: user[:'last-name']
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -3,13 +3,13 @@ module ForestLiana
|
|
3
3
|
before_filter :find_resource
|
4
4
|
|
5
5
|
def show
|
6
|
-
case
|
6
|
+
case params[:type].try(:downcase)
|
7
7
|
when 'value'
|
8
|
-
stat = ValueStatGetter.new(@resource,
|
8
|
+
stat = ValueStatGetter.new(@resource, params)
|
9
9
|
when 'pie'
|
10
|
-
stat = PieStatGetter.new(@resource,
|
10
|
+
stat = PieStatGetter.new(@resource, params)
|
11
11
|
when 'line'
|
12
|
-
stat = LineStatGetter.new(@resource,
|
12
|
+
stat = LineStatGetter.new(@resource, params)
|
13
13
|
end
|
14
14
|
|
15
15
|
stat.perform
|
@@ -29,18 +29,6 @@ module ForestLiana
|
|
29
29
|
render json: {status: 404}, status: :not_found
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
def stat_params
|
34
|
-
# Avoid to warn/crash if there's no filters.
|
35
|
-
params[:stat].delete(:filters) if params[:stat][:filters].blank?
|
36
|
-
|
37
|
-
params.require(:stat).permit(:type, :collection, :aggregate, :time_range,
|
38
|
-
:aggregate_field, :group_by_field,
|
39
|
-
:group_by_date_field, :filters => [
|
40
|
-
:field, :value
|
41
|
-
])
|
42
|
-
end
|
43
|
-
|
44
32
|
end
|
45
33
|
end
|
46
34
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class SessionSerializer
|
3
|
+
include JSONAPI::Serializer
|
4
|
+
|
5
|
+
attribute :first_name
|
6
|
+
attribute :last_name
|
7
|
+
attribute :email
|
8
|
+
|
9
|
+
def type
|
10
|
+
'users'
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_name(attribute_name)
|
14
|
+
attribute_name.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def unformat_name(attribute_name)
|
18
|
+
attribute_name.to_s.underscore
|
19
|
+
end
|
20
|
+
|
21
|
+
def self_link
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def relationship_self_link(attribute_name)
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def relationship_related_link(attribute_name)
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -2,21 +2,20 @@ require 'jwt'
|
|
2
2
|
|
3
3
|
class ForestLiana::ActivityLogger
|
4
4
|
|
5
|
-
def perform(
|
6
|
-
|
7
|
-
uri = URI.parse("#{forest_url}/api/projects/#{project_id(user)}/activity-logs")
|
5
|
+
def perform(session, action, collection_name, resource_id)
|
6
|
+
uri = URI.parse("#{forest_url}/api/activity-logs")
|
8
7
|
http = Net::HTTP.new(uri.host, uri.port)
|
9
8
|
http.use_ssl = true if forest_url.start_with?('https')
|
10
9
|
|
11
10
|
http.start do |client|
|
12
11
|
request = Net::HTTP::Post.new(uri.path)
|
13
|
-
request['Content-Type'] = 'application/json'
|
14
|
-
request['
|
12
|
+
request['Content-Type'] = 'application/vnd.api+json'
|
13
|
+
request['forest-secret-key'] = ForestLiana.secret_key
|
15
14
|
request.body = {
|
16
|
-
session: user['session'],
|
17
15
|
action: action,
|
18
16
|
collection: collection_name,
|
19
|
-
resource: resource_id
|
17
|
+
resource: resource_id,
|
18
|
+
user: session['data']['id']
|
20
19
|
}.to_json
|
21
20
|
|
22
21
|
client.request(request)
|
@@ -25,10 +24,6 @@ class ForestLiana::ActivityLogger
|
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
|
-
def project_id(user)
|
29
|
-
user['session']['data']['relationships']['project']['data']['id'];
|
30
|
-
end
|
31
|
-
|
32
27
|
def forest_url
|
33
28
|
ENV['FOREST_URL'] || 'https://forestadmin-server.herokuapp.com';
|
34
29
|
end
|
data/config/routes.rb
CHANGED
data/lib/forest_liana.rb
CHANGED
@@ -4,8 +4,15 @@ module ForestLiana
|
|
4
4
|
module UserSpace
|
5
5
|
end
|
6
6
|
|
7
|
-
mattr_accessor :
|
7
|
+
mattr_accessor :secret_key
|
8
|
+
mattr_accessor :auth_key
|
8
9
|
mattr_accessor :integrations
|
9
10
|
mattr_accessor :apimap
|
11
|
+
mattr_accessor :allowed_users
|
12
|
+
|
13
|
+
# Legacy.
|
14
|
+
mattr_accessor :jwt_signing_key
|
15
|
+
|
10
16
|
self.apimap = []
|
17
|
+
self.allowed_users = []
|
11
18
|
end
|
@@ -4,12 +4,21 @@ module ForestLiana
|
|
4
4
|
def initialize(app)
|
5
5
|
@app = app
|
6
6
|
@logger = Logger.new(STDOUT)
|
7
|
+
|
8
|
+
if ForestLiana.jwt_signing_key
|
9
|
+
warn "DEPRECATION WARNING: the use of ForestLiana.jwt_signing_key \
|
10
|
+
(config/initializers/forest_liana.rb) is deprecated. Use \
|
11
|
+
ForestLiana.secret_key and ForestLiana.auth_key instead. \
|
12
|
+
More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
|
13
|
+
ForestLiana.secret_key = ForestLiana.jwt_signing_key
|
14
|
+
ForestLiana.auth_key = ForestLiana.jwt_signing_key
|
15
|
+
end
|
7
16
|
end
|
8
17
|
|
9
18
|
def perform
|
10
19
|
create_serializers
|
11
20
|
|
12
|
-
if ForestLiana.
|
21
|
+
if ForestLiana.secret_key
|
13
22
|
create_apimap
|
14
23
|
send_apimap
|
15
24
|
end
|
@@ -61,12 +70,18 @@ module ForestLiana
|
|
61
70
|
request = Net::HTTP::Post.new(uri.path)
|
62
71
|
request.body = json.to_json
|
63
72
|
request['Content-Type'] = 'application/json'
|
64
|
-
request['forest-secret-key'] = ForestLiana.
|
73
|
+
request['forest-secret-key'] = ForestLiana.secret_key
|
65
74
|
response = client.request(request)
|
66
75
|
|
67
76
|
if response.is_a?(Net::HTTPNotFound)
|
68
77
|
@logger.warn "Forest cannot find your project secret key. " \
|
69
78
|
"Please, run `rails g forest_liana:install`."
|
79
|
+
else
|
80
|
+
ForestLiana.allowed_users = JSON.parse(response.body)['data'].map do |d|
|
81
|
+
user = d['attributes']
|
82
|
+
user['id'] = d['id']
|
83
|
+
user
|
84
|
+
end
|
70
85
|
end
|
71
86
|
end
|
72
87
|
end
|
data/lib/forest_liana/engine.rb
CHANGED
data/lib/forest_liana/version.rb
CHANGED
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: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: bcrypt
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Forest Rails Liana
|
140
154
|
email:
|
141
155
|
- sandro@munda.me
|
@@ -154,6 +168,7 @@ files:
|
|
154
168
|
- app/controllers/forest_liana/associations_controller.rb
|
155
169
|
- app/controllers/forest_liana/intercom_controller.rb
|
156
170
|
- app/controllers/forest_liana/resources_controller.rb
|
171
|
+
- app/controllers/forest_liana/sessions_controller.rb
|
157
172
|
- app/controllers/forest_liana/stats_controller.rb
|
158
173
|
- app/controllers/forest_liana/stripe_controller.rb
|
159
174
|
- app/deserializers/forest_liana/resource_deserializer.rb
|
@@ -166,6 +181,7 @@ files:
|
|
166
181
|
- app/serializers/forest_liana/intercom_attribute_serializer.rb
|
167
182
|
- app/serializers/forest_liana/intercom_conversation_serializer.rb
|
168
183
|
- app/serializers/forest_liana/serializer_factory.rb
|
184
|
+
- app/serializers/forest_liana/session_serializer.rb
|
169
185
|
- app/serializers/forest_liana/stat_serializer.rb
|
170
186
|
- app/serializers/forest_liana/stripe_card_serializer.rb
|
171
187
|
- app/serializers/forest_liana/stripe_invoice_serializer.rb
|