active_policy 0.1.1 → 0.1.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 +1 -1
- data/lib/active_policy/active_policy_middleware.rb +17 -5
- data/lib/active_policy/base.rb +2 -1
- data/lib/active_policy/utilities/utilities.rb +1 -0
- data/lib/active_policy/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: c04bf53faa989871a87e71b0bb039b4d658cfd1814e2e8e998c5912a9219f126
|
4
|
+
data.tar.gz: a7af843ee06a3183fbdac52d15bf156366f7bec0a926394603409adb0039f5e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69aca67ba2de7e1a2acbb3be8c05f6102f2888bc1b4cf34d943f5d644c518848424ae9a1010222af646ddb8a7695d285ef14c4816182011c3e25f8e05e347026
|
7
|
+
data.tar.gz: ef32c5d997e12714bf9c8e24ad33d6df58236491200903a2470223c66d5f20e25a74823faacb7ac7d3a0130eeeb9dc309c7049c103ea0c419170a7f5699031c8
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/PanosCodes/active_policy.svg?branch=master)](https://travis-ci.org/PanosCodes/active_policy)
|
2
2
|
[![codecov](https://codecov.io/gh/PanosCodes/active_policy/branch/master/graph/badge.svg)](https://codecov.io/gh/PanosCodes/active_policy)
|
3
3
|
|
4
|
-
# ActivePolicy
|
4
|
+
# ⛩️ ActivePolicy
|
5
5
|
Active policy is meant to be a way to authorize a request before hitting the controller.
|
6
6
|
|
7
7
|
## Installation
|
@@ -18,14 +18,21 @@ class ActivePolicyMiddleware
|
|
18
18
|
)
|
19
19
|
|
20
20
|
if params.key?(:policy)
|
21
|
-
|
21
|
+
# @type [ActivePolicy::Base] policy
|
22
|
+
policy = params[:policy].new(current_user(env), request, params)
|
22
23
|
method_name = params[:action] + '?'
|
23
24
|
models = ActivePolicy::Utilities.models_from_route_params(params)
|
24
|
-
|
25
|
-
|
25
|
+
result = policy.send(method_name, *models)
|
26
|
+
|
27
|
+
if result
|
28
|
+
@app.call(env)
|
29
|
+
else
|
30
|
+
response = response()
|
31
|
+
response.finish
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@app.call(env)
|
26
35
|
end
|
27
|
-
|
28
|
-
@app.call(env)
|
29
36
|
end
|
30
37
|
|
31
38
|
private
|
@@ -40,4 +47,9 @@ class ActivePolicyMiddleware
|
|
40
47
|
|
41
48
|
nil
|
42
49
|
end
|
50
|
+
|
51
|
+
# @param [Rack::Response]
|
52
|
+
def response(status_code = 401, headers = {'content_type': 'application/json'}, body = [])
|
53
|
+
Rack::Response.new(body, status_code, headers)
|
54
|
+
end
|
43
55
|
end
|
data/lib/active_policy/base.rb
CHANGED
@@ -2,9 +2,10 @@ module ActivePolicy
|
|
2
2
|
class Base
|
3
3
|
# @param [User] current_user
|
4
4
|
# @param [ActionDispatch::Request]
|
5
|
-
def initialize(current_user, request)
|
5
|
+
def initialize(current_user, request, params)
|
6
6
|
@current_user = current_user
|
7
7
|
@request = request
|
8
|
+
@params = params
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -15,6 +15,7 @@ module ActivePolicy
|
|
15
15
|
def self.models_from_route_params(params)
|
16
16
|
models = []
|
17
17
|
raise 'policy_models is missing from route' if params[:policy_models].nil?
|
18
|
+
return [] if params[:policy_models].empty?
|
18
19
|
params[:policy_models].each do |key, value|
|
19
20
|
models << value.find(params[key])
|
20
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Panos Dalitsouris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Active policy is meant to be a way to authorize a request before hitting
|
14
14
|
the controller.
|