tramway-api 1.2 → 1.4.1.1

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: 4e41e964d3ade1c230c77385929ee24692558d8cf59571134ccd9da815db2295
4
- data.tar.gz: 9dc5042350b5a9deb0e2afda435797bec9015743eaa5bb0f184aaaa1ccfcbb21
3
+ metadata.gz: 04f5055e00ef3608b436ae004240b26578fb7c9862eee1935e6fbfb6c299e1c6
4
+ data.tar.gz: 8269beafa9c7c8ca209d6eb4f35ce5ba7f7539106acd8e2ec1d984c386cff225
5
5
  SHA512:
6
- metadata.gz: 7627d0d269ff690cddc29a5a78369f968701e3992cb53e0b1f7c5b61d7e9e2b99e7a5af343dd5266e762bc5aa786ecfb06573128930360279e98f1ed1f7fce7f
7
- data.tar.gz: ddebade027114042a877ff9a19a531bedd8787317bd8b3065b630a7fff9ba062262bfc719d94dc81bd514b9f4fef6790e46a34566510aa424db94421de362712
6
+ metadata.gz: 86986d7a77393d34502750ffeb93240c71acdba6666df665f33916a815ce25b25038296a0bd5b603acfdda793354c5497f5a3b3375feeb3b4d11bcdba4aa6388
7
+ data.tar.gz: a6aed10bc3451c21abf1528893e06f778beb2b669ac89a17b0ca04dc500bf098628e35d8c34f674e5a34ef00dcba3bd51b5dcaeeadc8a7686cfc476411ff0c8b
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
 
@@ -25,7 +25,7 @@ module Tramway
25
25
  if entity.respond_to? :to_token_payload
26
26
  ::Knock::AuthToken.new payload: entity.to_token_payload
27
27
  else
28
- ::Knock::AuthToken.new payload: { sub: entity.id }
28
+ ::Knock::AuthToken.new payload: { sub: entity.uid }
29
29
  end
30
30
  end
31
31
 
@@ -2,7 +2,7 @@ module Tramway::Api::V1
2
2
  class RecordsController < ::Tramway::Api::V1::ApplicationController
3
3
  before_action :check_available_model_class
4
4
  before_action :check_available_model_action
5
- before_action :authenticate_user
5
+ before_action :authenticate_user_if_needed
6
6
 
7
7
  def index
8
8
  records = model_class.active.order(id: :desc).send params[:scope] || :all
@@ -40,6 +40,14 @@ module Tramway::Api::V1
40
40
  status: :ok
41
41
  end
42
42
 
43
+ def destroy
44
+ record = model_class.active.find params[:id]
45
+ record.remove
46
+ render json: record,
47
+ serializer: serializer_class,
48
+ status: :no_content
49
+ end
50
+
43
51
  private
44
52
 
45
53
  def check_available_model_class
@@ -47,7 +55,15 @@ module Tramway::Api::V1
47
55
  end
48
56
 
49
57
  def check_available_model_action
50
- head :unprocessable_entity and return unless action_name.in? Tramway::Api.available_models[model_class.to_s].map(&:to_s)
58
+ open_actions = Tramway::Api.available_models[model_class.to_s][:open]&.map(&:to_s) || []
59
+ closed_actions = Tramway::Api.available_models[model_class.to_s][:closed]&.map(&:to_s) || []
60
+ head :unprocessable_entity and return unless action_name.in? open_actions + closed_actions
61
+ end
62
+
63
+ def authenticate_user_if_needed
64
+ if action_name.in? Tramway::Api::available_models[model_class.to_s][:closed]&.map(&:to_s) || []
65
+ authenticate_user
66
+ end
51
67
  end
52
68
 
53
69
  def model_class
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Api
3
- VERSION = '1.2'
3
+ VERSION = '1.4.1.1'
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.2'
4
+ version: 1.4.1.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: 2019-09-07 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: knock