tramway-api 1.2 → 1.4.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04f5055e00ef3608b436ae004240b26578fb7c9862eee1935e6fbfb6c299e1c6
|
4
|
+
data.tar.gz: 8269beafa9c7c8ca209d6eb4f35ce5ba7f7539106acd8e2ec1d984c386cff225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
@@ -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 :
|
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
|
-
|
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
|
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: 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-
|
11
|
+
date: 2019-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knock
|