tramway-api 1.8.7.2 → 2.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/app/controllers/tramway/api/application_controller.rb +4 -4
- data/app/controllers/tramway/api/v1/application_controller.rb +7 -7
- data/app/controllers/tramway/api/v1/records_controller.rb +1 -1
- data/app/controllers/tramway/api/v1/users_controller.rb +1 -1
- data/lib/tramway/api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5ab385b1f17e7f65727c6601d470043e3c76c393409f38b914d79c05e6df524
|
4
|
+
data.tar.gz: d82903e94875d6a00eb3c885ccf0b28b11c62e1183abec7e5ff1d646b1b8224d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226e85b0c6f7ce0f46ab03f0ae1be2bad0ef7ac645a45498473520b86d4e36ab05ef56d02c3fa3a0f2dc57e50d1a99ca4b6fe934072df8938ee55ebd33875688
|
7
|
+
data.tar.gz: e14d07574e5d6cc8603707ec5b95f46f2b9ddcff0f7be5d5ee127db0e72daefb02cbe9de1f1d0bf7410051b9aec6c249e6e0f7f3f8b92a390b3a02d9241992cc
|
data/README.md
CHANGED
@@ -257,7 +257,7 @@ RSpec.describe 'Post creating user', type: :feature do
|
|
257
257
|
|
258
258
|
it 'returns created status' do
|
259
259
|
post '/api/v1/user', params: { user: attributes }
|
260
|
-
expect(response
|
260
|
+
expect(response[:status]).to eq 201
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'returns no errors' do
|
@@ -275,17 +275,17 @@ end
|
|
275
275
|
require 'rails_helper'
|
276
276
|
|
277
277
|
RSpec.describe 'Post generate token', type: :feature do
|
278
|
-
describe 'POST /api/v1/
|
278
|
+
describe 'POST /api/v1/user_tokens' do
|
279
279
|
let(:user) { create :user, password: '123456789' }
|
280
280
|
|
281
281
|
it 'returns created status' do
|
282
|
-
post '/api/v1/
|
282
|
+
post '/api/v1/user_tokens', params: { auth: { login: user.email, password: '123456789' } }
|
283
283
|
|
284
|
-
expect(response
|
284
|
+
expect(response[:status]).to eq 201
|
285
285
|
end
|
286
286
|
|
287
287
|
it 'returns token' do
|
288
|
-
post '/api/v1/
|
288
|
+
post '/api/v1/user_tokens', params: { auth: { login: user.email, password: '123456789' } }
|
289
289
|
|
290
290
|
expect(json_response[:auth_token].present?).to be_truthy
|
291
291
|
expect(json_response[:user]).to include_json({ email: user.email, uuid: user.uuid })
|
@@ -372,13 +372,13 @@ Then write test:
|
|
372
372
|
it 'returns status' do
|
373
373
|
get '/api/v1/records', params: { model: 'User' }, headers: headers
|
374
374
|
|
375
|
-
expect(response
|
375
|
+
expect(response[:status]).to eq 200
|
376
376
|
end
|
377
377
|
|
378
378
|
it 'returns needed count' do
|
379
379
|
get '/api/v1/records', params: { model: 'User' }, headers: headers
|
380
380
|
|
381
|
-
expect(json_response[:data].size).to eq User.
|
381
|
+
expect(json_response[:data].size).to eq User.count
|
382
382
|
end
|
383
383
|
```
|
384
384
|
|
@@ -455,7 +455,7 @@ RSpec.describe 'Post generate token', type: :feature do
|
|
455
455
|
it 'returns created status' do
|
456
456
|
post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
|
457
457
|
|
458
|
-
expect(response
|
458
|
+
expect(response[:status]).to eq 201
|
459
459
|
end
|
460
460
|
|
461
461
|
it 'returns token' do
|
@@ -16,7 +16,7 @@ module Tramway
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def authenticate
|
19
|
-
return if
|
19
|
+
return if current_tramway_user || params[:user_based_model].in?(Tramway::Api.user_based_models)
|
20
20
|
|
21
21
|
unauthorized
|
22
22
|
end
|
@@ -35,7 +35,7 @@ module Tramway
|
|
35
35
|
user_based_model = params[:user_based_model].constantize
|
36
36
|
@entity ||=
|
37
37
|
if user_based_model.respond_to? :from_token_request
|
38
|
-
user_based_model.
|
38
|
+
user_based_model.from_token_request request
|
39
39
|
else
|
40
40
|
params[:auth] && find_user_by_auth_attributes
|
41
41
|
end
|
@@ -44,7 +44,7 @@ module Tramway
|
|
44
44
|
def find_user_by_auth_attributes
|
45
45
|
user_based_model = params[:user_based_model].constantize
|
46
46
|
Tramway::Api.auth_attributes[params[:user_based_model]].each do |attribute|
|
47
|
-
object = user_based_model.
|
47
|
+
object = user_based_model.where.not(attribute => nil).find_by(attribute => auth_params[:login])
|
48
48
|
return object if object
|
49
49
|
end
|
50
50
|
nil
|
@@ -54,7 +54,7 @@ module Tramway
|
|
54
54
|
params[:auth]&.permit(:login, :password)
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def current_tramway_user
|
58
58
|
Tramway::Api.user_based_models.map do |user_based_model|
|
59
59
|
send("current_#{user_based_model.constantize.name.underscore}") unless user_based_model == User
|
60
60
|
end.compact.first
|
@@ -44,7 +44,7 @@ module Tramway
|
|
44
44
|
|
45
45
|
def check_available_model_class
|
46
46
|
unless model_class
|
47
|
-
head(:unauthorized) && return unless
|
47
|
+
head(:unauthorized) && return unless current_tramway_user
|
48
48
|
|
49
49
|
head(:unprocessable_entity) && return
|
50
50
|
end
|
@@ -53,7 +53,7 @@ module Tramway
|
|
53
53
|
def check_available_model_action_for_record
|
54
54
|
action_is_available = check_action
|
55
55
|
action_is_available.tap do
|
56
|
-
if action_is_available.is_a?(Proc) && !action_is_available.call(record,
|
56
|
+
if action_is_available.is_a?(Proc) && !action_is_available.call(record, current_tramway_user)
|
57
57
|
head(:unprocessable_entity) && return
|
58
58
|
end
|
59
59
|
end
|
@@ -63,7 +63,7 @@ module Tramway
|
|
63
63
|
action_is_available = check_action
|
64
64
|
return records if action_is_available == true
|
65
65
|
|
66
|
-
action_is_available.call records,
|
66
|
+
action_is_available.call records, current_tramway_user if action_is_available.is_a?(Proc)
|
67
67
|
end
|
68
68
|
|
69
69
|
def check_action
|
@@ -73,7 +73,7 @@ module Tramway
|
|
73
73
|
project: (@application_engine || application_name),
|
74
74
|
role: role,
|
75
75
|
model_name: params[:model],
|
76
|
-
|
76
|
+
current_tramway_user: current_tramway_user
|
77
77
|
)
|
78
78
|
end.compact.uniq - [false]
|
79
79
|
|
@@ -94,17 +94,17 @@ module Tramway
|
|
94
94
|
project: (@application_engine || application_name),
|
95
95
|
model_name: params[:model]
|
96
96
|
)
|
97
|
-
head(:unauthorized) && return if !
|
97
|
+
head(:unauthorized) && return if !current_tramway_user && !action_is_open
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
100
|
+
def available_models_for_current_tramway_user
|
101
101
|
checking_roles.reduce([]) do |models, role|
|
102
102
|
models += ::Tramway::Api.available_models(role: role).map(&:to_s)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
def checking_roles
|
107
|
-
[:open,
|
107
|
+
[:open, current_tramway_user&.role].compact
|
108
108
|
end
|
109
109
|
|
110
110
|
protected
|
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:
|
4
|
+
version: 2.0.0.1
|
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: 2022-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
119
|
+
rubygems_version: 3.1.6
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Engine for api
|