tramway-api 1.6.3 → 1.7.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/tramway/api/application_controller.rb +3 -2
- data/app/controllers/tramway/api/v1/records_controller.rb +7 -4
- data/app/controllers/tramway/api/v1/user_tokens_controller.rb +1 -2
- data/app/controllers/tramway/api/v1/users_controller.rb +2 -3
- data/app/serializers/tramway/api/v1/application_serializer.rb +6 -0
- data/lib/tramway/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94170f0f2f5bf4138fc21cc86290ac51092fd6580d98ec9ee01e143e3a846f8e
|
4
|
+
data.tar.gz: c610745ab3cd6eb82116c9720d846ac17a7bf7bef5a5f496f850cbd6bad8f793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
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
|
-
|
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
|
@@ -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.
|
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
|
-
|
19
|
-
id: user_form.model.id
|
18
|
+
uuid: user_form.model.uuid
|
20
19
|
)
|
21
20
|
)
|
22
21
|
render json: serialized_user, status: :created
|
data/lib/tramway/api/version.rb
CHANGED
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.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:
|
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
|