tramway-api 1.5.0.2 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01e0eb09865cd422bd78339ed17061bcb3e9783109877faf8c7d284386152696
|
4
|
+
data.tar.gz: 805e37d122674f9a95e71b8dcc98b819b34dfcf3e5ab8f1b6fc34883f65e6c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee33d4fd776288f9ebe9159e8ac7387aa001a8687e32a6e91dff1b32d0786e7cc0ec58a19d597e0600c117785c234801fdad0adf9616cb00dc05f381af0314ce
|
7
|
+
data.tar.gz: f8b7b35880e8f509cdd73d9d9e9a41f3c9f3bd7d669c399a8b97b649494d444323188493e9abcc768b490242792bf2d88c6cd63268cef3ade7f4aca6e2ca8b7f
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ module Tramway
|
|
18
18
|
protected
|
19
19
|
|
20
20
|
def authenticate
|
21
|
-
return unauthorized
|
21
|
+
return unauthorized if current_user.nil? || !params[:user_based_model].in?(Tramway::Api.user_based_models)
|
22
22
|
end
|
23
23
|
|
24
24
|
def auth_token
|
@@ -30,17 +30,19 @@ module Tramway
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def entity
|
33
|
+
user_based_model = params[:user_based_model].constantize
|
33
34
|
@entity ||=
|
34
|
-
if
|
35
|
-
|
35
|
+
if user_based_model.respond_to? :from_token_request
|
36
|
+
user_based_model.active.from_token_request request
|
36
37
|
else
|
37
38
|
params[:auth] && find_user_by_auth_attributes
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
def find_user_by_auth_attributes
|
42
|
-
|
43
|
-
|
43
|
+
user_based_model = params[:user_based_model].constantize
|
44
|
+
Tramway::Api.auth_attributes[user_based_model].each do |attribute|
|
45
|
+
object = user_based_model.active.where.not(attribute => nil).find_by(attribute => auth_params[:login])
|
44
46
|
return object if object
|
45
47
|
end
|
46
48
|
nil
|
@@ -68,7 +68,9 @@ module Tramway::Api::V1
|
|
68
68
|
|
69
69
|
def authenticate_user_if_needed
|
70
70
|
if action_name.in? Tramway::Api::available_models[model_class.to_s][:closed]&.map(&:to_s) || []
|
71
|
-
|
71
|
+
Tramway::Api.user_based_models.map do |user_based_model|
|
72
|
+
send("current_#{user_based_model.name.underscore}").present?
|
73
|
+
end.include? true
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
data/lib/tramway/api/version.rb
CHANGED
data/lib/tramway/api.rb
CHANGED
@@ -4,19 +4,27 @@ module Tramway
|
|
4
4
|
module Api
|
5
5
|
class << self
|
6
6
|
def auth_config
|
7
|
-
@@auth_config ||= { user_model: ::Tramway::User::User, auth_attributes: :email }
|
7
|
+
@@auth_config ||= [{ user_model: ::Tramway::User::User, auth_attributes: :email }]
|
8
8
|
end
|
9
9
|
|
10
|
-
def auth_config=(
|
11
|
-
|
10
|
+
def auth_config=(params)
|
11
|
+
if params.is_a? Hash
|
12
|
+
@@auth_config = [params]
|
13
|
+
elsif params.is_a? Array
|
14
|
+
@@auth_config = params
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
@@auth_config
|
18
|
+
def user_based_models
|
19
|
+
@@auth_config.map do |conf|
|
20
|
+
conf[:user_model]
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
def auth_attributes
|
19
|
-
@@auth_config
|
25
|
+
@@auth_config.reduce({}) do |hash, conf|
|
26
|
+
hash.merge! conf[:user_model] => conf[:auth_attributes]
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
def set_available_models(**models)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knock
|