tramway-api 1.4.1 → 1.4.4

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: ec1302e6c87545200be1aafc619be2179f680ba24cbfa80b7876cbb66062411b
4
- data.tar.gz: ef2806fab92a090ee0524a855b6ece6960a349ec5952e7c4e76feb3b4c3f0469
3
+ metadata.gz: eed51b344d38bb111854f4e32d985856ea3504b76fbf901fee56735183eae415
4
+ data.tar.gz: d430ca30613c117aed36db0493885b4399d4015d53d12f34470fd8bf60fe7d71
5
5
  SHA512:
6
- metadata.gz: 9016f340db67e2c4a05a3ec3f13d57cc104c4354980c5f09111bc70b1c9cecd778e108998482e8b049c8a356490bb5170f27583554fd910216385d8847425408
7
- data.tar.gz: 23dd222a388b24c3d01ef0c27004ef3478ec8e7c9f82bf1462ae07ec3f027ac333df69d602c1259295f57f2f6d0a8314f918f7b38e6e754053725df6c67fcf9e
6
+ metadata.gz: f84dd206d408c41f1d3c230079418445ff4b7fffbb4808637297695c3f033dec031e3e7f3f29f699a58d865e950d1afac1d1f8a3f6116c1ea40469fabc06bf0d
7
+ data.tar.gz: c746cad5ecbce016799e6337ea9f23a38287bd2cbee543a9460a5750e301238e10459bd0f4da0cb0e9bb3f3fd885665daa998b4e59982f2cb014034a48297ed1
data/README.md CHANGED
@@ -89,7 +89,7 @@ Create file `config/initializers/tramway.rb`
89
89
 
90
90
  ```ruby
91
91
  ::Tramway::Api.auth_config = { user_model: User, auth_attributes: %i[email username] }
92
- ::Tramway::Api.set_available_models user: %i[create update]
92
+ ::Tramway::Api.set_available_models user: { open: %i[create], closed: %i[update] }
93
93
  ```
94
94
 
95
95
  Run `rails g tramway:core:install`
@@ -271,7 +271,10 @@ this model must have field `password_digest`, because we use `bcrypt` gem for au
271
271
 
272
272
  Sets ActiveRecord models which will be used in API
273
273
 
274
- Argument is a hash. Keys are underscored models names, values are arrays of available methods for every model.
274
+ Argument is a hash. Keys are underscored models names, values are hashes with actions of available methods for every model.
275
+ * `open` key means that this action will be used without authentication
276
+ * `closed` key means that this action will be used with authentication
277
+
275
278
 
276
279
  Enabled methods:
277
280
 
@@ -6,8 +6,10 @@ module Tramway::Api::V1
6
6
 
7
7
  def index
8
8
  records = model_class.active.order(id: :desc).send params[:scope] || :all
9
+ records = records.full_text_search params[:search] if params[:search]
9
10
  render json: records,
10
11
  each_serializer: serializer_class,
12
+ include: '*',
11
13
  status: :ok
12
14
  end
13
15
 
@@ -16,6 +18,7 @@ module Tramway::Api::V1
16
18
  if record_form.submit params[:data][:attributes]
17
19
  render json: record_form.model,
18
20
  serializer: serializer_class,
21
+ include: '*',
19
22
  status: :created
20
23
  else
21
24
  render_errors_for record_form
@@ -27,6 +30,7 @@ module Tramway::Api::V1
27
30
  if record_form.submit params[:data][:attributes]
28
31
  render json: record_form.model,
29
32
  serializer: serializer_class,
33
+ include: '*',
30
34
  status: :ok
31
35
  else
32
36
  render_errors_for record_form
@@ -37,6 +41,7 @@ module Tramway::Api::V1
37
41
  record = model_class.active.find params[:id]
38
42
  render json: record,
39
43
  serializer: serializer_class,
44
+ include: '*',
40
45
  status: :ok
41
46
  end
42
47
 
@@ -45,6 +50,7 @@ module Tramway::Api::V1
45
50
  record.remove
46
51
  render json: record,
47
52
  serializer: serializer_class,
53
+ include: '*',
48
54
  status: :no_content
49
55
  end
50
56
 
@@ -55,8 +61,9 @@ module Tramway::Api::V1
55
61
  end
56
62
 
57
63
  def check_available_model_action
58
- actions = Tramway::Api.available_models[model_class.to_s][:open]&.map(&:to_s) || [] + Tramway::Api.available_models[model_class.to_s][:closed]&.map(&:to_s) || []
59
- head :unprocessable_entity and return unless action_name.in? actions
64
+ open_actions = Tramway::Api.available_models[model_class.to_s][:open]&.map(&:to_s) || []
65
+ closed_actions = Tramway::Api.available_models[model_class.to_s][:closed]&.map(&:to_s) || []
66
+ head :unprocessable_entity and return unless action_name.in? open_actions + closed_actions
60
67
  end
61
68
 
62
69
  def authenticate_user_if_needed
@@ -67,7 +74,11 @@ module Tramway::Api::V1
67
74
 
68
75
  def model_class
69
76
  if params[:model].to_s.in? ::Tramway::Api.available_models.keys.map(&:to_s)
70
- params[:model].constantize
77
+ begin
78
+ params[:model].constantize
79
+ rescue ActiveSupport::Concern::MultipleIncludedBlocks => e
80
+ raise "#{e}. Maybe #{params[:model]} model doesn't exists or there is naming conflicts with it"
81
+ end
71
82
  end
72
83
  end
73
84
 
@@ -8,7 +8,7 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
8
8
  user_form = sign_up_form_class_name(Tramway::Api.user_based_model).new Tramway::Api.user_based_model.new
9
9
  # Implement JSON API spec here
10
10
  if user_form.submit params[Tramway::Api.user_based_model.name.underscore]
11
- token = ::Knock::AuthToken.new(payload: { sub: user_form.model.id }).token
11
+ token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uid }).token
12
12
  # FIXME refactor this bullshit
13
13
  serialized_user = OpenStruct.new(
14
14
  user_form.model.attributes.merge(
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.4'
4
4
  end
5
5
  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.4.1
4
+ version: 1.4.4
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-09-09 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: knock