rails-rapido 0.9.4 → 0.9.5
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 +4 -4
- data/README.md +15 -1
- data/lib/rapido/api_controller.rb +10 -0
- data/lib/rapido/controller.rb +8 -0
- data/lib/rapido/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ad59d38c8d9c50021b6be12a144491e17d2025040f65c7714537ebe9831cf8e
|
4
|
+
data.tar.gz: b45ee3ef697c15438f7295704bcb4b0266a22612a9e59ddfb2c5f8e1c37a25c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bed2d6715e48d291343ae9dd18baed0feacbf9013372e518360c0df2ae0c02749f5b908d16de92756df30c2c3d2c889bfa91043def6571ce1127774e7c40b6c
|
7
|
+
data.tar.gz: '019ef8a8ff99a1c00a03e6ac395f435ee7ca96f1059afe2ef84b4ca1d0059703b0c8fbf05dd6f1ba3f4f10aed828902b70031f0ddae47dbf24ebf2e35ae47b63'
|
data/README.md
CHANGED
@@ -14,8 +14,14 @@ Below is a typical example of a class using Rapido. More examples are available
|
|
14
14
|
|
15
15
|
class DocumentsController < ApplicationController
|
16
16
|
include Rapido::ApiController
|
17
|
+
|
18
|
+
allow_if do
|
19
|
+
current_user.is_editor?
|
20
|
+
end
|
21
|
+
|
22
|
+
allow_only :create, :delete, :index, :show, :update
|
17
23
|
|
18
|
-
attr_permitted :file, file_name, :category
|
24
|
+
attr_permitted :file, :file_name, :category
|
19
25
|
|
20
26
|
belongs_to :user, getter: :current_user
|
21
27
|
|
@@ -46,6 +52,14 @@ end
|
|
46
52
|
|
47
53
|
## API
|
48
54
|
|
55
|
+
### `allow_if`
|
56
|
+
|
57
|
+
Accepts a method name as symbol or block. Method supplied or block must return true to allow the action to proceed, otherwise a status 401 is returned with no body.
|
58
|
+
|
59
|
+
### `allow_only`
|
60
|
+
|
61
|
+
Accepts a list of symbols. These symbols specify the controller actions that are allowed for this controller.
|
62
|
+
|
49
63
|
### `attr_permitted`
|
50
64
|
|
51
65
|
Accepts a list of symbols. These symbols specify the attributes that are supplied to StrongParameters as permitted parameters in `create` and `update` actions.
|
@@ -18,6 +18,8 @@ module Rapido
|
|
18
18
|
end
|
19
19
|
|
20
20
|
before_action :permit_only_allowed_actions
|
21
|
+
|
22
|
+
before_action :permit_only_if
|
21
23
|
end
|
22
24
|
|
23
25
|
def index
|
@@ -129,6 +131,14 @@ module Rapido
|
|
129
131
|
head :unauthorized unless allowed_actions.include?(params[:action].to_sym)
|
130
132
|
end
|
131
133
|
|
134
|
+
def permit_only_if
|
135
|
+
if(allow_if)
|
136
|
+
unless (allow_if.is_a?(Symbol) ? send(allow_if) : instance_eval(&allow_if))
|
137
|
+
head :unauthorized
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
132
142
|
def resource_presenter(new_resource = nil)
|
133
143
|
@resource_presenter ||= begin
|
134
144
|
args = presenter_args.nil? ? nil : presenter_args.map { |arg| params[arg] }
|
data/lib/rapido/controller.rb
CHANGED
@@ -28,6 +28,10 @@ module Rapido
|
|
28
28
|
@allowed_actions = ary
|
29
29
|
end
|
30
30
|
|
31
|
+
def allow_if(str = nil, &block)
|
32
|
+
@allow_if = str || block
|
33
|
+
end
|
34
|
+
|
31
35
|
def attr_permitted(*ary)
|
32
36
|
@resource_permitted_params = ary
|
33
37
|
end
|
@@ -101,6 +105,10 @@ module Rapido
|
|
101
105
|
setting(:allowed_actions)
|
102
106
|
end
|
103
107
|
|
108
|
+
def allow_if
|
109
|
+
setting(:allow_if)
|
110
|
+
end
|
111
|
+
|
104
112
|
def build_resource(params = {})
|
105
113
|
return owner.send('build_' + resource_class_name, params) if setting(:has_one)
|
106
114
|
return owner.send(resource_class_name.pluralize).build(params) if owner && owner.respond_to?(resource_class_name.pluralize)
|
data/lib/rapido/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rapido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Kirst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|