tramway-api 1.8.7.3 → 2.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/app/controllers/tramway/api/application_controller.rb +2 -2
- 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: 86dbb20f2ceaf8080df47a5437984da9242f4b04b093ba89ba7353af262c0761
|
4
|
+
data.tar.gz: d9ca7cf50ef790630662b3e69329e35798cda5dc8af8fb25790e56e6eaa644fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58861b209bffc3aee14d7d1ccccb8046d057bd655326aedd7dc3010b80b267a1a1633486187042f7a7d4f46d9f9f4444bc3758c9236387e97b8c8e6d08edf5d6
|
7
|
+
data.tar.gz: ca7d7c90b7b17dd89677fcb5a59ea32f94c3d5efc097240d844680fb7b47feea4135659f9939e9955f1a7ecca56f05acc486be03aca3bd72b4e94361e07805b2
|
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,7 +372,7 @@ 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
|
@@ -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
|
@@ -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
|
-
current_user:
|
76
|
+
current_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.2
|
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-08-18 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
|