tramway-api 1.6.3 → 1.7.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0ea77a64960468cd8a38627fe4400e78d591810d3123dd5b59672fcd1f37da3
4
- data.tar.gz: 6e952b9555a2be85d5a0676ac527a7c8fff3027dfcb984a38fce99d2e145089b
3
+ metadata.gz: 94170f0f2f5bf4138fc21cc86290ac51092fd6580d98ec9ee01e143e3a846f8e
4
+ data.tar.gz: c610745ab3cd6eb82116c9720d846ac17a7bf7bef5a5f496f850cbd6bad8f793
5
5
  SHA512:
6
- metadata.gz: 3bdd5d17648fac5814452ff4d1873b6085cdff3f776a37b9ac73224a56189989876832d9ad841d082ca1b2cdb6acf05c51eb4fb2cd1ec87d0db84f64b1b5286e
7
- data.tar.gz: 7004e9ade3569be69ad1ca94058533d425b9dea39e746ccc189034e95374be2553682658ff2768208f1f41e97f1e26f2c6937a7c12eb457c7f0413d3bc3d79ce
6
+ metadata.gz: 214f6b56a98a0a4fcbc02431178c77cbf0e0d2eafb020e2183a8266398266fc72c2e193327616f36b5293a1c386a2286ad3fe018e478ebbd57c00a24d34745ee
7
+ data.tar.gz: 5b3f18221ede26fb67bacb212ecd93794b379fd69d40723eb5f771b686b967f9bb5d1a83a191ee7fc5c2de44adc3a951f57b8a5abf513fe69cfc0221a1b52753
@@ -5,7 +5,7 @@ module Tramway
5
5
  class ApplicationController < ::Tramway::Core::ApplicationController
6
6
  include ::Knock::Authenticable
7
7
  protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' }
8
- rescue_from ActiveRecord::RecordNotFound, with: :not_found
8
+ rescue_from ActiveRecord::RecordNotFound, with: :not_found if Rails.env.production?
9
9
 
10
10
  private
11
11
 
@@ -19,6 +19,7 @@ module Tramway
19
19
 
20
20
  def authenticate
21
21
  return if current_user || params[:user_based_model].in?(Tramway::Api.user_based_models)
22
+
22
23
  unauthorized
23
24
  end
24
25
 
@@ -28,7 +29,7 @@ module Tramway
28
29
  if entity.respond_to? :to_token_payload
29
30
  ::Knock::AuthToken.new payload: entity.to_token_payload
30
31
  else
31
- ::Knock::AuthToken.new payload: { sub: entity.uid }
32
+ ::Knock::AuthToken.new payload: { sub: entity.uuid }
32
33
  end
33
34
  end
34
35
 
@@ -18,6 +18,7 @@ module Tramway::Api::V1
18
18
  def create
19
19
  record_form = form_class.new model_class.new
20
20
  if record_form.submit snake_case params[:data][:attributes]
21
+ record_form.model.reload
21
22
  render json: record_form.model,
22
23
  serializer: serializer_class,
23
24
  include: '*',
@@ -28,7 +29,7 @@ module Tramway::Api::V1
28
29
  end
29
30
 
30
31
  def update
31
- record_form = form_class.new model_class.active.find params[:id]
32
+ record_form = form_class.new model_class.active.find_by uuid: params[:id]
32
33
  if record_form.submit snake_case params[:data][:attributes]
33
34
  render json: record_form.model,
34
35
  serializer: serializer_class,
@@ -40,7 +41,7 @@ module Tramway::Api::V1
40
41
  end
41
42
 
42
43
  def show
43
- record = model_class.active.find params[:id]
44
+ record = model_class.active.find_by uuid: params[:id]
44
45
  render json: record,
45
46
  serializer: serializer_class,
46
47
  include: '*',
@@ -48,7 +49,7 @@ module Tramway::Api::V1
48
49
  end
49
50
 
50
51
  def destroy
51
- record = model_class.active.find params[:id]
52
+ record = model_class.active.find_by uuid: params[:id]
52
53
  record.remove
53
54
  render json: record,
54
55
  serializer: serializer_class,
@@ -69,7 +70,9 @@ module Tramway::Api::V1
69
70
  end
70
71
 
71
72
  def authenticate_user_if_needed
72
- head :unauthorized and return if action_name.in?(Tramway::Api.available_models[model_class.to_s][:closed]&.map(&:to_s) || []) && !current_user
73
+ if action_name.in?(Tramway::Api.available_models[model_class.to_s][:closed]&.map(&:to_s) || []) && !current_user
74
+ head(:unauthorized) && return
75
+ end
73
76
  end
74
77
 
75
78
  def model_class
@@ -8,8 +8,7 @@ class Tramway::Api::V1::UserTokensController < ::Tramway::Api::V1::ApplicationCo
8
8
  auth_token: token,
9
9
  user: {
10
10
  email: @entity.email,
11
- uid: @entity.uid,
12
- id: @entity.id
11
+ uuid: @entity.uuid
13
12
  }
14
13
  }, status: :created
15
14
  else
@@ -10,13 +10,12 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
10
10
  user_form = sign_up_form_class_name(user_based_model).new user_based_model.new
11
11
  # Implement JSON API spec here
12
12
  if user_form.submit snake_case params[:data][:attributes]
13
- token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uid }).token
13
+ token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uuid }).token
14
14
  # FIXME: refactor this bullshit
15
15
  serialized_user = OpenStruct.new(
16
16
  user_form.model.attributes.merge(
17
17
  authentication_token: token,
18
- uid: user_form.model.uid,
19
- id: user_form.model.id
18
+ uuid: user_form.model.uuid
20
19
  )
21
20
  )
22
21
  render json: serialized_user, status: :created
@@ -3,6 +3,12 @@
3
3
  class Tramway::Api::V1::ApplicationSerializer < ActiveModel::Serializer
4
4
  include ::Tramway::Core::Concerns::AttributesDecoratorHelper
5
5
 
6
+ attribute :id
7
+
8
+ def id
9
+ object.uuid
10
+ end
11
+
6
12
  def created_at
7
13
  object.created_at.iso8601
8
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.6.3'
5
+ VERSION = '1.7.0.3'
6
6
  end
7
7
  end
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.6.3
4
+ version: 1.7.0.3
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-12-12 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers