rails-acu 3.0.8 → 4.0.0
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 +5 -5
- data/.travis.yml +4 -3
- data/Gemfile +2 -2
- data/Gemfile.lock +102 -80
- data/README.md +10 -7
- data/lib/acu/helpers/helpers.rb +0 -0
- data/lib/acu/monitor.rb +39 -25
- data/lib/acu/utilities.rb +0 -0
- data/lib/acu/version.rb +1 -1
- data/lib/generators/templates/rules.rb +4 -4
- data/rails-acu.gemspec +1 -1
- data/spec/dummy/app/assets/javascripts/admin/booking/chats.js +0 -0
- data/spec/dummy/app/assets/javascripts/admin/booking/lists.js +0 -0
- data/spec/dummy/app/assets/stylesheets/admin/booking/chats.css +0 -0
- data/spec/dummy/app/assets/stylesheets/admin/booking/lists.css +0 -0
- data/spec/dummy/app/controllers/admin/booking/chats_controller.rb +0 -0
- data/spec/dummy/app/controllers/admin/booking/lists_controller.rb +0 -0
- data/spec/dummy/app/helpers/admin/booking/chats_helper.rb +0 -0
- data/spec/dummy/app/helpers/admin/booking/lists_helper.rb +0 -0
- data/spec/dummy/app/models/admin/booking.rb +0 -0
- data/spec/dummy/app/models/admin/booking/chat.rb +0 -0
- data/spec/dummy/app/models/admin/booking/list.rb +0 -0
- data/spec/dummy/app/views/admin/booking/chats/_form.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/chats/edit.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/chats/index.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/chats/new.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/chats/show.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/lists/_form.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/lists/edit.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/lists/index.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/lists/new.html.erb +0 -0
- data/spec/dummy/app/views/admin/booking/lists/show.html.erb +0 -0
- data/spec/dummy/config/initializers/acu_rules.rb +6 -6
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -3
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/db/migrate/20170506054319_create_admin_booking_lists.rb +0 -0
- data/spec/dummy/db/migrate/20170506081928_create_admin_booking_chats.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/db/seeds.rb +26 -24
- data/spec/dummy/spec/controllers/admin/booking/chats_controller_spec.rb +0 -0
- data/spec/dummy/spec/controllers/admin/booking/lists_controller_spec.rb +2 -2
- data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +3 -3
- data/spec/dummy/spec/controllers/home_controller_spec.rb +93 -73
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f40e9fa79e4a513723d3c0a3a3474228a2ab23e1a4f5e94c6f166e91aa33297
|
4
|
+
data.tar.gz: be8ac9eb7ee156af85ffb4198784e65477e528e4959ebde574f56268256dd26c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40bc82e82afb5281a9664457c938c5f99da62fdf93616b34077b9c9d2a81b80a1c3209c6084d4a7eab447bb6acdbe2393b65c53234b42cc68f0963e8d8132b18
|
7
|
+
data.tar.gz: 2f678f43962ec1ee11197a4ba9f2be880309f590f3859923853fe4b6ab3a1009d1e9263d1a86822168c3635af8682ef84b43d817d807bb60e004cc3b8e80f75c
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.6.3
|
5
5
|
|
6
6
|
cache: bundler
|
7
7
|
|
@@ -14,8 +14,9 @@ matrix:
|
|
14
14
|
fast_finish: true
|
15
15
|
|
16
16
|
before_install:
|
17
|
-
- gem update --system
|
18
|
-
- gem install bundler -v
|
17
|
+
- gem update --system 3.0.3
|
18
|
+
- gem install bundler -v 2.0.2
|
19
|
+
- bundler install
|
19
20
|
|
20
21
|
script:
|
21
22
|
- export RAILS_ENV=test
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
ruby '2.
|
3
|
+
ruby '2.6.3'
|
4
4
|
|
5
5
|
git_source(:github) do |repo_name|
|
6
6
|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
@@ -26,7 +26,7 @@ gem 'sprockets', '~> 3.7.2'
|
|
26
26
|
group :development, :test do
|
27
27
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
28
28
|
gem 'byebug', platform: :mri
|
29
|
-
gem 'rspec-rails', '
|
29
|
+
gem 'rspec-rails', github: 'rspec/rspec-rails', :tag => "v4.0.0.beta2"
|
30
30
|
gem 'sqlite3'
|
31
31
|
gem 'awesome_print', github: 'awesome-print/awesome_print'
|
32
32
|
gem 'devise'
|
data/Gemfile.lock
CHANGED
@@ -4,79 +4,106 @@ GIT
|
|
4
4
|
specs:
|
5
5
|
awesome_print (1.8.0)
|
6
6
|
|
7
|
+
GIT
|
8
|
+
remote: https://github.com/rspec/rspec-rails.git
|
9
|
+
revision: 0919d6e0133b89c19a1518e3d82e014fd39bc06f
|
10
|
+
tag: v4.0.0.beta2
|
11
|
+
specs:
|
12
|
+
rspec-rails (4.0.0.beta2)
|
13
|
+
actionpack (>= 4.2)
|
14
|
+
activesupport (>= 4.2)
|
15
|
+
railties (>= 4.2)
|
16
|
+
rspec-core (~> 3.8)
|
17
|
+
rspec-expectations (~> 3.8)
|
18
|
+
rspec-mocks (~> 3.8)
|
19
|
+
rspec-support (~> 3.8)
|
20
|
+
|
7
21
|
PATH
|
8
22
|
remote: .
|
9
23
|
specs:
|
10
|
-
rails-acu (
|
11
|
-
rails (>=
|
24
|
+
rails-acu (4.0.0)
|
25
|
+
rails (~> 6.0, >= 6.0.0)
|
12
26
|
|
13
27
|
GEM
|
14
28
|
remote: https://rubygems.org/
|
15
29
|
specs:
|
16
|
-
actioncable (
|
17
|
-
actionpack (=
|
30
|
+
actioncable (6.0.0)
|
31
|
+
actionpack (= 6.0.0)
|
18
32
|
nio4r (~> 2.0)
|
19
33
|
websocket-driver (>= 0.6.1)
|
20
|
-
|
21
|
-
actionpack (=
|
22
|
-
|
23
|
-
|
34
|
+
actionmailbox (6.0.0)
|
35
|
+
actionpack (= 6.0.0)
|
36
|
+
activejob (= 6.0.0)
|
37
|
+
activerecord (= 6.0.0)
|
38
|
+
activestorage (= 6.0.0)
|
39
|
+
activesupport (= 6.0.0)
|
40
|
+
mail (>= 2.7.1)
|
41
|
+
actionmailer (6.0.0)
|
42
|
+
actionpack (= 6.0.0)
|
43
|
+
actionview (= 6.0.0)
|
44
|
+
activejob (= 6.0.0)
|
24
45
|
mail (~> 2.5, >= 2.5.4)
|
25
46
|
rails-dom-testing (~> 2.0)
|
26
|
-
actionpack (
|
27
|
-
actionview (=
|
28
|
-
activesupport (=
|
47
|
+
actionpack (6.0.0)
|
48
|
+
actionview (= 6.0.0)
|
49
|
+
activesupport (= 6.0.0)
|
29
50
|
rack (~> 2.0)
|
30
51
|
rack-test (>= 0.6.3)
|
31
52
|
rails-dom-testing (~> 2.0)
|
32
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
33
|
-
|
34
|
-
|
53
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
54
|
+
actiontext (6.0.0)
|
55
|
+
actionpack (= 6.0.0)
|
56
|
+
activerecord (= 6.0.0)
|
57
|
+
activestorage (= 6.0.0)
|
58
|
+
activesupport (= 6.0.0)
|
59
|
+
nokogiri (>= 1.8.5)
|
60
|
+
actionview (6.0.0)
|
61
|
+
activesupport (= 6.0.0)
|
35
62
|
builder (~> 3.1)
|
36
63
|
erubi (~> 1.4)
|
37
64
|
rails-dom-testing (~> 2.0)
|
38
|
-
rails-html-sanitizer (~> 1.
|
39
|
-
activejob (
|
40
|
-
activesupport (=
|
65
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
66
|
+
activejob (6.0.0)
|
67
|
+
activesupport (= 6.0.0)
|
41
68
|
globalid (>= 0.3.6)
|
42
|
-
activemodel (
|
43
|
-
activesupport (=
|
44
|
-
activerecord (
|
45
|
-
activemodel (=
|
46
|
-
activesupport (=
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
activerecord (=
|
69
|
+
activemodel (6.0.0)
|
70
|
+
activesupport (= 6.0.0)
|
71
|
+
activerecord (6.0.0)
|
72
|
+
activemodel (= 6.0.0)
|
73
|
+
activesupport (= 6.0.0)
|
74
|
+
activestorage (6.0.0)
|
75
|
+
actionpack (= 6.0.0)
|
76
|
+
activejob (= 6.0.0)
|
77
|
+
activerecord (= 6.0.0)
|
51
78
|
marcel (~> 0.3.1)
|
52
|
-
activesupport (
|
79
|
+
activesupport (6.0.0)
|
53
80
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
54
81
|
i18n (>= 0.7, < 2)
|
55
82
|
minitest (~> 5.1)
|
56
83
|
tzinfo (~> 1.1)
|
57
|
-
|
58
|
-
bcrypt (3.1.
|
84
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
85
|
+
bcrypt (3.1.13)
|
59
86
|
builder (3.2.3)
|
60
|
-
byebug (
|
61
|
-
concurrent-ruby (1.1.
|
87
|
+
byebug (11.0.1)
|
88
|
+
concurrent-ruby (1.1.5)
|
62
89
|
crass (1.0.4)
|
63
|
-
devise (4.
|
90
|
+
devise (4.7.1)
|
64
91
|
bcrypt (~> 3.0)
|
65
92
|
orm_adapter (~> 0.1)
|
66
|
-
railties (>= 4.1.0
|
93
|
+
railties (>= 4.1.0)
|
67
94
|
responders
|
68
95
|
warden (~> 1.2.3)
|
69
96
|
diff-lcs (1.3)
|
70
|
-
erubi (1.
|
97
|
+
erubi (1.9.0)
|
71
98
|
globalid (0.4.2)
|
72
99
|
activesupport (>= 4.2.0)
|
73
|
-
i18n (1.
|
100
|
+
i18n (1.6.0)
|
74
101
|
concurrent-ruby (~> 1.0)
|
75
|
-
jquery-rails (4.3.
|
102
|
+
jquery-rails (4.3.5)
|
76
103
|
rails-dom-testing (>= 1, < 3)
|
77
104
|
railties (>= 4.2.0)
|
78
105
|
thor (>= 0.14, < 2.0)
|
79
|
-
loofah (2.
|
106
|
+
loofah (2.3.0)
|
80
107
|
crass (~> 1.0.2)
|
81
108
|
nokogiri (>= 1.5.9)
|
82
109
|
mail (2.7.1)
|
@@ -85,28 +112,30 @@ GEM
|
|
85
112
|
mimemagic (~> 0.3.2)
|
86
113
|
method_source (0.9.2)
|
87
114
|
mimemagic (0.3.3)
|
88
|
-
mini_mime (1.0.
|
115
|
+
mini_mime (1.0.2)
|
89
116
|
mini_portile2 (2.4.0)
|
90
|
-
minitest (5.
|
91
|
-
nio4r (2.
|
92
|
-
nokogiri (1.10.
|
117
|
+
minitest (5.12.2)
|
118
|
+
nio4r (2.5.2)
|
119
|
+
nokogiri (1.10.4)
|
93
120
|
mini_portile2 (~> 2.4.0)
|
94
121
|
orm_adapter (0.5.0)
|
95
|
-
rack (2.0.
|
122
|
+
rack (2.0.7)
|
96
123
|
rack-test (1.1.0)
|
97
124
|
rack (>= 1.0, < 3)
|
98
|
-
rails (
|
99
|
-
actioncable (=
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
125
|
+
rails (6.0.0)
|
126
|
+
actioncable (= 6.0.0)
|
127
|
+
actionmailbox (= 6.0.0)
|
128
|
+
actionmailer (= 6.0.0)
|
129
|
+
actionpack (= 6.0.0)
|
130
|
+
actiontext (= 6.0.0)
|
131
|
+
actionview (= 6.0.0)
|
132
|
+
activejob (= 6.0.0)
|
133
|
+
activemodel (= 6.0.0)
|
134
|
+
activerecord (= 6.0.0)
|
135
|
+
activestorage (= 6.0.0)
|
136
|
+
activesupport (= 6.0.0)
|
108
137
|
bundler (>= 1.3.0)
|
109
|
-
railties (=
|
138
|
+
railties (= 6.0.0)
|
110
139
|
sprockets-rails (>= 2.0.0)
|
111
140
|
rails-controller-testing (1.0.4)
|
112
141
|
actionpack (>= 5.0.1.x)
|
@@ -115,35 +144,27 @@ GEM
|
|
115
144
|
rails-dom-testing (2.0.3)
|
116
145
|
activesupport (>= 4.2.0)
|
117
146
|
nokogiri (>= 1.6)
|
118
|
-
rails-html-sanitizer (1.0
|
147
|
+
rails-html-sanitizer (1.2.0)
|
119
148
|
loofah (~> 2.2, >= 2.2.2)
|
120
|
-
railties (
|
121
|
-
actionpack (=
|
122
|
-
activesupport (=
|
149
|
+
railties (6.0.0)
|
150
|
+
actionpack (= 6.0.0)
|
151
|
+
activesupport (= 6.0.0)
|
123
152
|
method_source
|
124
153
|
rake (>= 0.8.7)
|
125
|
-
thor (>= 0.
|
126
|
-
rake (
|
127
|
-
responders (
|
128
|
-
actionpack (>=
|
129
|
-
railties (>=
|
130
|
-
rspec-core (3.8.
|
154
|
+
thor (>= 0.20.3, < 2.0)
|
155
|
+
rake (13.0.0)
|
156
|
+
responders (3.0.0)
|
157
|
+
actionpack (>= 5.0)
|
158
|
+
railties (>= 5.0)
|
159
|
+
rspec-core (3.8.2)
|
131
160
|
rspec-support (~> 3.8.0)
|
132
|
-
rspec-expectations (3.8.
|
161
|
+
rspec-expectations (3.8.4)
|
133
162
|
diff-lcs (>= 1.2.0, < 2.0)
|
134
163
|
rspec-support (~> 3.8.0)
|
135
|
-
rspec-mocks (3.8.
|
164
|
+
rspec-mocks (3.8.1)
|
136
165
|
diff-lcs (>= 1.2.0, < 2.0)
|
137
166
|
rspec-support (~> 3.8.0)
|
138
|
-
rspec-
|
139
|
-
actionpack (>= 3.0)
|
140
|
-
activesupport (>= 3.0)
|
141
|
-
railties (>= 3.0)
|
142
|
-
rspec-core (~> 3.8.0)
|
143
|
-
rspec-expectations (~> 3.8.0)
|
144
|
-
rspec-mocks (~> 3.8.0)
|
145
|
-
rspec-support (~> 3.8.0)
|
146
|
-
rspec-support (3.8.0)
|
167
|
+
rspec-support (3.8.2)
|
147
168
|
sprockets (3.7.2)
|
148
169
|
concurrent-ruby (~> 1.0)
|
149
170
|
rack (> 1, < 3)
|
@@ -151,16 +172,17 @@ GEM
|
|
151
172
|
actionpack (>= 4.0)
|
152
173
|
activesupport (>= 4.0)
|
153
174
|
sprockets (>= 3.0.0)
|
154
|
-
sqlite3 (1.
|
175
|
+
sqlite3 (1.4.1)
|
155
176
|
thor (0.20.3)
|
156
177
|
thread_safe (0.3.6)
|
157
178
|
tzinfo (1.2.5)
|
158
179
|
thread_safe (~> 0.1)
|
159
180
|
warden (1.2.8)
|
160
181
|
rack (>= 2.0.6)
|
161
|
-
websocket-driver (0.7.
|
182
|
+
websocket-driver (0.7.1)
|
162
183
|
websocket-extensions (>= 0.1.0)
|
163
|
-
websocket-extensions (0.1.
|
184
|
+
websocket-extensions (0.1.4)
|
185
|
+
zeitwerk (2.1.10)
|
164
186
|
|
165
187
|
PLATFORMS
|
166
188
|
ruby
|
@@ -172,12 +194,12 @@ DEPENDENCIES
|
|
172
194
|
jquery-rails
|
173
195
|
rails-acu!
|
174
196
|
rails-controller-testing
|
175
|
-
rspec-rails
|
197
|
+
rspec-rails!
|
176
198
|
sprockets (~> 3.7.2)
|
177
199
|
sqlite3
|
178
200
|
|
179
201
|
RUBY VERSION
|
180
|
-
ruby 2.
|
202
|
+
ruby 2.6.3p62
|
181
203
|
|
182
204
|
BUNDLED WITH
|
183
|
-
|
205
|
+
2.0.2
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
[](https://travis-ci.org/alphamarket/rails-acu)
|
2
|
+
|
3
|
+
> ### Note:
|
4
|
+
> This branch is maintained for **Rails v6.*** and **Ruby v2.6.*** for *Rails v5.** please use `rails-5` branch.
|
2
5
|
|
3
6
|
# ACU
|
4
7
|
ACU is the acronym for **A**ccess **C**ontrol **U**nit, and it's designed to give the 100% control over permissions on multiple levels of rails application's structure.
|
@@ -45,11 +48,11 @@ in this gem, resource means any of `namespace`, `controller` and `action`. here
|
|
45
48
|
# config/initializers/acu_rules.rb
|
46
49
|
Acu::Rules.define do
|
47
50
|
# anyone makes a request could be count as everyone!
|
48
|
-
whois
|
51
|
+
whois(:everyone) { true }
|
49
52
|
|
50
|
-
whois
|
53
|
+
whois(:admin, args: [:user]) { |c| c and c.user_type == :ADMIN.to_s }
|
51
54
|
|
52
|
-
whois
|
55
|
+
whois(:client, args: [:user]) { |c| c and c.user_type == :PUBLIC.to_s }
|
53
56
|
|
54
57
|
# admin can access to everywhere
|
55
58
|
allow :admin
|
@@ -82,7 +85,7 @@ Acu::Rules.define do
|
|
82
85
|
end
|
83
86
|
|
84
87
|
controller :contact do
|
85
|
-
action
|
88
|
+
action(:support) {
|
86
89
|
allow :client
|
87
90
|
}
|
88
91
|
end
|
@@ -130,12 +133,12 @@ Although you can define a binary allow/deny access rule in the `acu_rules.rb` fi
|
|
130
133
|
For those situations you allow the entities to get access but limits their operations in the action/view/layout with the `acu_is?`, `acu_as` and `acu_except` helpers, here is some usage example of them:
|
131
134
|
|
132
135
|
```ruby
|
133
|
-
# return true if the entity `:admin`'s block in `whois
|
136
|
+
# return true if the entity `:admin`'s block in `whois(:admin)` return true, otherwise false
|
134
137
|
acu_is? :admin
|
135
138
|
# returns true if any of the given entity's block return true; if none of the was valid, returns false.
|
136
139
|
acu_is? [:admin, :client]
|
137
140
|
|
138
|
-
# executes the block if current user identified as an admin by `whois
|
141
|
+
# executes the block if current user identified as an admin by `whois(:admin)`
|
139
142
|
acu_as :admin do
|
140
143
|
puts 'You are identified as an `admin`'
|
141
144
|
end
|
data/lib/acu/helpers/helpers.rb
CHANGED
File without changes
|
data/lib/acu/monitor.rb
CHANGED
@@ -83,15 +83,20 @@ module Acu
|
|
83
83
|
_entitled_entities << entity.to_s
|
84
84
|
# current entity is granted to have the access?
|
85
85
|
if is_allowed? action
|
86
|
+
# cache the permision for the entity
|
87
|
+
cache_access _info, _entitled_entities[-1], Rules.GRANT_SYMBOL
|
86
88
|
# grant the access if already not denied
|
87
89
|
_granted = 1 if _granted == -1
|
88
90
|
else
|
91
|
+
# cache the permision for the entity
|
92
|
+
cache_access _info, _entitled_entities[-1], Rules.DENY_SYMBOL
|
89
93
|
# deny it, period!
|
90
94
|
_granted = 0
|
91
95
|
end
|
92
96
|
end
|
93
97
|
end
|
94
98
|
end
|
99
|
+
|
95
100
|
# if the access is granted? i.e if all the rules are satisfied with the request
|
96
101
|
return if _granted == 1 and access_granted _info, _entitled_entities
|
97
102
|
# if the access is denied? i.e at least one of rules are NOT satisfied with the request
|
@@ -103,13 +108,13 @@ module Acu
|
|
103
108
|
|
104
109
|
def valid_for? entity
|
105
110
|
# check for existance
|
106
|
-
raise Errors::MissingEntity.new("whois
|
111
|
+
raise Errors::MissingEntity.new("whois(:#{entity})?") if not Rules.entities[entity]
|
107
112
|
# fetch the entity's identity
|
108
113
|
e = Rules.entities[entity]
|
109
114
|
# fetch the related args to the entity from the `kwargs`
|
110
115
|
kwargs = @kwargs.reject { |x| !e[:args].include?(x) }
|
111
116
|
# if fetched args and pre-defined arg didn't match?
|
112
|
-
raise Errors::MissingData.new("at least one of arguments for `whois
|
117
|
+
raise Errors::MissingData.new("at least one of arguments for `whois(:#{entity})` is not provided!") if kwargs.length != e[:args].length
|
113
118
|
# send varibles in order the have defined
|
114
119
|
e[:callback].call(*e[:args].map { |i| kwargs[i] })
|
115
120
|
end
|
@@ -124,26 +129,26 @@ module Acu
|
|
124
129
|
def hit_cache _info
|
125
130
|
# return [didn't hit] if not allowed to use cache
|
126
131
|
return false if not Configs.get :use_cache
|
132
|
+
# fetched cached data for current info
|
133
|
+
cached_data = Rails.cache.read cache_name(_info), cache_options
|
134
|
+
# return not hit if no cached data found
|
135
|
+
return false if not cached_data
|
127
136
|
# fetch the relative entities to this request
|
128
|
-
_entitled_entities = Rules.entities.select { |name, _| valid_for? name }
|
129
|
-
#
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
# check if
|
134
|
-
if
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
access_denied _info, _entitled_entities.keys, from_cache: true
|
140
|
-
end
|
141
|
-
# hit the cache
|
142
|
-
return true
|
137
|
+
_entitled_entities = Rules.entities.select { |name, _| valid_for? name }.keys.map(&:to_sym)
|
138
|
+
# check if any of entities is among the should-denied ones?
|
139
|
+
denied = cached_data[Rules.DENY_SYMBOL] & _entitled_entities
|
140
|
+
# check if any of entities is among the should-grant ones?
|
141
|
+
granted = cached_data[Rules.GRANT_SYMBOL] & _entitled_entities
|
142
|
+
# check if we have any resons to deny the access?
|
143
|
+
return true if not denied.empty? and access_denied _info, denied, from_cache: true
|
144
|
+
# o.w. grant the access if any explicit rule
|
145
|
+
return true if not granted.empty? and access_granted _info, granted, from_cache: true
|
146
|
+
# if not granted nor denied by cache, discard the cache data & proceed
|
147
|
+
return false
|
143
148
|
end
|
144
149
|
|
145
|
-
def cache_name _info, entities
|
146
|
-
"%s-%s" %[_info.to_a.join('::'), (entities.kind_of?(Array) ? entities : entities.keys).join("-")]
|
150
|
+
def cache_name _info, entities = []
|
151
|
+
("%s-%s" %[_info.to_a.join('::'), (entities.kind_of?(Array) ? entities : entities.keys).sort.join("-")]).gsub(/-+$/, "")
|
147
152
|
end
|
148
153
|
|
149
154
|
def is_allowed? action
|
@@ -172,20 +177,29 @@ module Acu
|
|
172
177
|
Logger.new(Configs.get :audit_log_file).info(log) if file and not file.blank?
|
173
178
|
end
|
174
179
|
|
180
|
+
def cache_access _info, entities, symbol
|
181
|
+
if not Rails.cache.exist?(cache_name(_info), cache_options)
|
182
|
+
Rails.cache.write(cache_name(_info), {
|
183
|
+
Rules.DENY_SYMBOL => [],
|
184
|
+
Rules.GRANT_SYMBOL => []
|
185
|
+
}, cache_options)
|
186
|
+
end
|
187
|
+
cache_data = Rails.cache.read cache_name(_info), cache_options
|
188
|
+
cache_data[symbol] += [entities].flatten.map(&:to_sym)
|
189
|
+
cache_data[symbol] = cache_data[symbol].flatten.uniq
|
190
|
+
Rails.cache.write cache_name(_info), cache_data, cache_options
|
191
|
+
end
|
192
|
+
|
175
193
|
def access_granted _info, entities, by_default: false, from_cache: false
|
176
194
|
# log the event
|
177
|
-
log_audit ("[-]" + (from_cache ? '[c]' : '') + " access GRANTED to `#{_info}` as `:#{entities.uniq.join(", :")}`" + (by_default ? " [autherized by :allow_by_default]" : ""))
|
178
|
-
# cache the event if not already from cache
|
179
|
-
Rails.cache.write(cache_name(_info, entities), Rules.GRANT_SYMBOL, cache_options) if not from_cache and Configs.get :use_cache
|
195
|
+
log_audit ("[-]" + (from_cache ? '[c]' : '') + " access GRANTED to `#{_info}` as `:#{entities.uniq.sort.join(", :")}`" + (by_default ? " [autherized by :allow_by_default]" : ""))
|
180
196
|
# grant the access
|
181
197
|
true
|
182
198
|
end
|
183
199
|
|
184
200
|
def access_denied _info, entities, by_default: false, from_cache: false
|
185
201
|
# log the event
|
186
|
-
log_audit ("[x]" + (from_cache ? '[c]' : '') + " access DENIED to `#{_info}` as `:#{entities.uniq.join(", :")}`" + (by_default ? " [autherized by :allow_by_default]" : ""))
|
187
|
-
# cache the event if not already from cache
|
188
|
-
Rails.cache.write(cache_name(_info, entities), Rules.DENY_SYMBOL, cache_options) if not from_cache and Configs.get :use_cache
|
202
|
+
log_audit ("[x]" + (from_cache ? '[c]' : '') + " access DENIED to `#{_info}` as `:#{entities.uniq.sort.join(", :")}`" + (by_default ? " [autherized by :allow_by_default]" : ""))
|
189
203
|
# deny the access
|
190
204
|
raise Errors::AccessDenied.new("you don't have the enough access for process this request!")
|
191
205
|
end
|