tramway-api 1.6 → 1.6.0.1

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: 01e0eb09865cd422bd78339ed17061bcb3e9783109877faf8c7d284386152696
4
- data.tar.gz: 805e37d122674f9a95e71b8dcc98b819b34dfcf3e5ab8f1b6fc34883f65e6c1a
3
+ metadata.gz: 0f21707e10ef82a1c378250e9c82339400ee41739d7a6009001ecd1c8a17c4e0
4
+ data.tar.gz: 22732d5ad75036e1bf59831171f4d82af30f95805432900df283566b2b24619c
5
5
  SHA512:
6
- metadata.gz: ee33d4fd776288f9ebe9159e8ac7387aa001a8687e32a6e91dff1b32d0786e7cc0ec58a19d597e0600c117785c234801fdad0adf9616cb00dc05f381af0314ce
7
- data.tar.gz: f8b7b35880e8f509cdd73d9d9e9a41f3c9f3bd7d669c399a8b97b649494d444323188493e9abcc768b490242792bf2d88c6cd63268cef3ade7f4aca6e2ca8b7f
6
+ metadata.gz: 313b31746731d79afe528f6100daa910260707e03c4d68d5c0961b6a046591d485006a58e3438b9b3bf4c1dcb7b79009511834b7a58905e293834d679c47bb66
7
+ data.tar.gz: 6b9a2570cd6b8e68d039de8706d9923651081c010f0a4cebce5347a06f442033b2c3833b7c07194bd4eea3b9bb3a2b7b81d629078d18380df4488f35b90ba63f
@@ -51,6 +51,12 @@ module Tramway
51
51
  def auth_params
52
52
  params[:auth]&.permit(:login, :password)
53
53
  end
54
+
55
+ def current_user
56
+ Tramway::Api.user_based_models.map do |user_based_model|
57
+ send("current_#{user_based_model.name.underscore}")
58
+ end.compact.first
59
+ end
54
60
  end
55
61
  end
56
62
  end
@@ -68,9 +68,7 @@ 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
- Tramway::Api.user_based_models.map do |user_based_model|
72
- send("current_#{user_based_model.name.underscore}").present?
73
- end.include? true
71
+ current_user
74
72
  end
75
73
  end
76
74
 
@@ -5,9 +5,9 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
5
5
  include Tramway::ClassNameHelpers
6
6
 
7
7
  def create
8
- user_form = sign_up_form_class_name(Tramway::Api.user_based_model).new Tramway::Api.user_based_model.new
8
+ user_form = sign_up_form_class_name(user_based_model).new user_based_model.new
9
9
  # Implement JSON API spec here
10
- if user_form.submit snake_case params[Tramway::Api.user_based_model.name.underscore]
10
+ if user_form.submit snake_case params[user_based_model.name.underscore]
11
11
  token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uid }).token
12
12
  # FIXME refactor this bullshit
13
13
  serialized_user = OpenStruct.new(
@@ -31,4 +31,8 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
31
31
  def sign_up_form_class_name(model_class)
32
32
  form_class_name "#{model_class}SignUp"
33
33
  end
34
+
35
+ def user_based_model
36
+ params[:user_based_model].constantize if params[:user_based_model].in? Tramway::Api.user_based_models.map(&:to_s)
37
+ end
34
38
  end
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '1.6'
3
+ VERSION = '1.6.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.6'
4
+ version: 1.6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov