admission 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/admission.gemspec +2 -0
- data/lib/admission/version.rb +1 -1
- metadata +1 -94
- data/examples/rails5_feudalism/.gitignore +0 -19
- data/examples/rails5_feudalism/.ruby-version +0 -1
- data/examples/rails5_feudalism/Gemfile +0 -52
- data/examples/rails5_feudalism/README.md +0 -17
- data/examples/rails5_feudalism/Rakefile +0 -6
- data/examples/rails5_feudalism/app/assets/config/manifest.js +0 -3
- data/examples/rails5_feudalism/app/assets/images/.keep +0 -0
- data/examples/rails5_feudalism/app/assets/javascripts/application.js +0 -15
- data/examples/rails5_feudalism/app/assets/stylesheets/application.css +0 -15
- data/examples/rails5_feudalism/app/assets/stylesheets/scaffolds.scss +0 -84
- data/examples/rails5_feudalism/app/controllers/application_controller.rb +0 -13
- data/examples/rails5_feudalism/app/controllers/concerns/.keep +0 -0
- data/examples/rails5_feudalism/app/controllers/users_controller.rb +0 -75
- data/examples/rails5_feudalism/app/helpers/application_helper.rb +0 -2
- data/examples/rails5_feudalism/app/jobs/application_job.rb +0 -2
- data/examples/rails5_feudalism/app/models/application_record.rb +0 -3
- data/examples/rails5_feudalism/app/models/concerns/.keep +0 -0
- data/examples/rails5_feudalism/app/models/person.rb +0 -11
- data/examples/rails5_feudalism/app/models/possession.rb +0 -7
- data/examples/rails5_feudalism/app/models/trait.rb +0 -7
- data/examples/rails5_feudalism/app/models/user.rb +0 -17
- data/examples/rails5_feudalism/app/models/user_status.rb +0 -140
- data/examples/rails5_feudalism/app/views/admission/forbidden.html.erb +0 -14
- data/examples/rails5_feudalism/app/views/layouts/application.html.erb +0 -15
- data/examples/rails5_feudalism/app/views/users/_form.html.erb +0 -19
- data/examples/rails5_feudalism/app/views/users/_privilege_row.html.erb +0 -24
- data/examples/rails5_feudalism/app/views/users/_privileges_list.html.erb +0 -51
- data/examples/rails5_feudalism/app/views/users/edit.html.erb +0 -6
- data/examples/rails5_feudalism/app/views/users/index.html.erb +0 -25
- data/examples/rails5_feudalism/app/views/users/new.html.erb +0 -5
- data/examples/rails5_feudalism/app/views/users/show.html.erb +0 -4
- data/examples/rails5_feudalism/bin/bundle +0 -3
- data/examples/rails5_feudalism/bin/rails +0 -9
- data/examples/rails5_feudalism/bin/rake +0 -9
- data/examples/rails5_feudalism/bin/setup +0 -38
- data/examples/rails5_feudalism/bin/spring +0 -17
- data/examples/rails5_feudalism/bin/update +0 -29
- data/examples/rails5_feudalism/bin/yarn +0 -11
- data/examples/rails5_feudalism/config.ru +0 -5
- data/examples/rails5_feudalism/config/application.rb +0 -28
- data/examples/rails5_feudalism/config/boot.rb +0 -3
- data/examples/rails5_feudalism/config/database.yml +0 -85
- data/examples/rails5_feudalism/config/environment.rb +0 -5
- data/examples/rails5_feudalism/config/environments/development.rb +0 -49
- data/examples/rails5_feudalism/config/environments/production.rb +0 -82
- data/examples/rails5_feudalism/config/environments/test.rb +0 -36
- data/examples/rails5_feudalism/config/initializers/application_controller_renderer.rb +0 -8
- data/examples/rails5_feudalism/config/initializers/assets.rb +0 -14
- data/examples/rails5_feudalism/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/rails5_feudalism/config/initializers/cookies_serializer.rb +0 -5
- data/examples/rails5_feudalism/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/rails5_feudalism/config/initializers/inflections.rb +0 -16
- data/examples/rails5_feudalism/config/initializers/mime_types.rb +0 -4
- data/examples/rails5_feudalism/config/initializers/wrap_parameters.rb +0 -14
- data/examples/rails5_feudalism/config/locales/en.yml +0 -33
- data/examples/rails5_feudalism/config/puma.rb +0 -56
- data/examples/rails5_feudalism/config/routes.rb +0 -8
- data/examples/rails5_feudalism/config/secrets.yml +0 -32
- data/examples/rails5_feudalism/config/spring.rb +0 -6
- data/examples/rails5_feudalism/db/migrate/20171018085629_create_users.rb +0 -9
- data/examples/rails5_feudalism/db/migrate/20171019082044_create_people.rb +0 -9
- data/examples/rails5_feudalism/db/migrate/20171019082055_create_possessions.rb +0 -9
- data/examples/rails5_feudalism/db/migrate/20171019082059_create_traits.rb +0 -9
- data/examples/rails5_feudalism/db/schema.rb +0 -49
- data/examples/rails5_feudalism/db/seeds.rb +0 -7
- data/examples/rails5_feudalism/lib/assets/.keep +0 -0
- data/examples/rails5_feudalism/lib/tasks/.keep +0 -0
- data/examples/rails5_feudalism/log/.keep +0 -0
- data/examples/rails5_feudalism/package.json +0 -7
- data/examples/rails5_feudalism/public/404.html +0 -67
- data/examples/rails5_feudalism/public/422.html +0 -67
- data/examples/rails5_feudalism/public/500.html +0 -66
- data/examples/rails5_feudalism/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/rails5_feudalism/public/apple-touch-icon.png +0 -0
- data/examples/rails5_feudalism/public/favicon.ico +0 -0
- data/examples/rails5_feudalism/public/robots.txt +0 -1
- data/examples/rails5_feudalism/test/application_system_test_case.rb +0 -5
- data/examples/rails5_feudalism/test/controllers/.keep +0 -0
- data/examples/rails5_feudalism/test/fixtures/.keep +0 -0
- data/examples/rails5_feudalism/test/fixtures/files/.keep +0 -0
- data/examples/rails5_feudalism/test/fixtures/people.yml +0 -36
- data/examples/rails5_feudalism/test/fixtures/possessions.yml +0 -0
- data/examples/rails5_feudalism/test/fixtures/traits.yml +0 -0
- data/examples/rails5_feudalism/test/fixtures/users.yml +0 -0
- data/examples/rails5_feudalism/test/helpers/.keep +0 -0
- data/examples/rails5_feudalism/test/models/.keep +0 -0
- data/examples/rails5_feudalism/test/models/user_status/rules_test.rb +0 -152
- data/examples/rails5_feudalism/test/models/user_status/user_status_test.rb +0 -50
- data/examples/rails5_feudalism/test/system/.keep +0 -0
- data/examples/rails5_feudalism/test/test_helper.rb +0 -9
- data/examples/rails5_feudalism/tmp/.keep +0 -0
- data/examples/rails5_feudalism/vendor/.keep +0 -0
- data/examples/rails5_feudalism/yarn.lock +0 -7
File without changes
|
File without changes
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
jozka_mr:
|
3
|
-
name: Jozka
|
4
|
-
country: Moravia
|
5
|
-
|
6
|
-
klarka_mr:
|
7
|
-
name: Klarka
|
8
|
-
country: Moravia
|
9
|
-
|
10
|
-
ze_sovince_mr:
|
11
|
-
name: Pan ze Sovince
|
12
|
-
country: Moravia
|
13
|
-
|
14
|
-
pepik_bh:
|
15
|
-
name: Pepik
|
16
|
-
country: Bohemia
|
17
|
-
|
18
|
-
marenka_bh:
|
19
|
-
name: Marenka
|
20
|
-
country: Bohemia
|
21
|
-
|
22
|
-
zly_rodic_bh:
|
23
|
-
name: father of marenka & pepik
|
24
|
-
country: Bohemia
|
25
|
-
|
26
|
-
z_lipe_bh:
|
27
|
-
name: Pan z Lipe
|
28
|
-
country: Bohemia
|
29
|
-
|
30
|
-
z_lichnova_sl:
|
31
|
-
name: Pan z Lichnova
|
32
|
-
country: Silesia
|
33
|
-
|
34
|
-
premysl_otakar_II:
|
35
|
-
name: knize Premysl Otakar II
|
36
|
-
country: Bohemia
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class UserStatus::RulesTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
ALL_PRIVILEGES = []
|
6
|
-
Person::COUNTRIES.each do |country|
|
7
|
-
UserStatus.privileges_list.each do |privilege|
|
8
|
-
ALL_PRIVILEGES << privilege.dup_with_context(country)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
ALL_PRIVILEGES.freeze
|
12
|
-
|
13
|
-
def user_from *countries
|
14
|
-
countries = countries.flatten
|
15
|
-
countries.each do |country|
|
16
|
-
yield User.new(person: Person.new(country: country))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'persons:possessions scope - index' do
|
21
|
-
user_from Person::COUNTRIES do |user|
|
22
|
-
ALL_PRIVILEGES.each do |privilege|
|
23
|
-
assert_allows user, privilege, :index, :'persons:possessions'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'persons:possessions scope - create' do
|
29
|
-
cons, pros = ALL_PRIVILEGES.partition{|p| p.text_key == 'human'}
|
30
|
-
|
31
|
-
user_from Person::COUNTRIES do |user|
|
32
|
-
pros.each do |privilege|
|
33
|
-
assert_allows user, privilege, :create, :'persons:possessions'
|
34
|
-
end
|
35
|
-
|
36
|
-
cons.each do |privilege|
|
37
|
-
assert_not_allows user, privilege, :create, :'persons:possessions'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'persons:possessions scope - update' do
|
43
|
-
cons, pros = ALL_PRIVILEGES.partition{|p| p.text_key == 'human'}
|
44
|
-
|
45
|
-
user_from Person::COUNTRIES do |user|
|
46
|
-
same_person = user.person
|
47
|
-
other_person = Person.new country: user.person.country
|
48
|
-
|
49
|
-
ALL_PRIVILEGES.each do |privilege|
|
50
|
-
assert_not_allows user, privilege, :update, :'persons:possessions'
|
51
|
-
assert_not_allows user, privilege, :update, [other_person, :possessions]
|
52
|
-
end
|
53
|
-
|
54
|
-
pros.each do |privilege|
|
55
|
-
assert_allows user, privilege, :update, [same_person, :possessions]
|
56
|
-
end
|
57
|
-
|
58
|
-
cons.each do |privilege|
|
59
|
-
assert_not_allows user, privilege, :update, [same_person, :possessions]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'persons:possessions scope - impound' do
|
65
|
-
pros, cons = ALL_PRIVILEGES.partition{|p| p.text_key == 'lord'}
|
66
|
-
|
67
|
-
user_from Person::COUNTRIES do |user|
|
68
|
-
other_country_person = Person.new country: 'Austria'
|
69
|
-
|
70
|
-
ALL_PRIVILEGES.each do |privilege|
|
71
|
-
assert_not_allows user, privilege, :impound, :'persons:possessions'
|
72
|
-
assert_not_allows user, privilege, :impound, [other_country_person, :possessions]
|
73
|
-
end
|
74
|
-
|
75
|
-
pros.each do |privilege|
|
76
|
-
same_country_person = Person.new country: privilege.country
|
77
|
-
assert_allows user, privilege, :impound, [same_country_person, :possessions]
|
78
|
-
end
|
79
|
-
cons.each do |privilege|
|
80
|
-
same_country_person = Person.new country: privilege.country
|
81
|
-
assert_not_allows user, privilege, :impound, [same_country_person, :possessions]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'traits scope - index' do
|
87
|
-
user_from Person::COUNTRIES do |user|
|
88
|
-
ALL_PRIVILEGES.each do |privilege|
|
89
|
-
assert_allows user, privilege, :index, :traits
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
test 'traits scope - update' do
|
95
|
-
human, others = ALL_PRIVILEGES.partition{|p| p.text_key == 'human'}
|
96
|
-
lord_duke, other_humans = others.partition{|p| p.name == 'lord' || p.name == 'duke'}
|
97
|
-
|
98
|
-
user_from Person::COUNTRIES do |user|
|
99
|
-
same_person_trait = Trait.new person: user.person
|
100
|
-
other_person_trait = Trait.new person: Person.new(country: user.person.country)
|
101
|
-
other_country_trait = Trait.new person: Person.new(country: 'Austria')
|
102
|
-
|
103
|
-
ALL_PRIVILEGES.each do |privilege|
|
104
|
-
assert_not_allows user, privilege, :update, :'traits'
|
105
|
-
assert_not_allows user, privilege, :update, other_country_trait
|
106
|
-
end
|
107
|
-
|
108
|
-
human.each do |privilege|
|
109
|
-
assert_not_allows user, privilege, :update, same_person_trait
|
110
|
-
assert_not_allows user, privilege, :update, other_person_trait
|
111
|
-
end
|
112
|
-
|
113
|
-
other_humans.each do |privilege|
|
114
|
-
assert_allows user, privilege, :update, same_person_trait
|
115
|
-
assert_not_allows user, privilege, :update, other_person_trait
|
116
|
-
end
|
117
|
-
|
118
|
-
lord_duke.each do |privilege|
|
119
|
-
assert_allows user, privilege, :update, other_person_trait
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def assert_allows user, privilege, action, resource
|
125
|
-
arbitration = Admission::ResourceArbitration.new user, UserStatus.rules, action, resource
|
126
|
-
arbitration.prepare_sitting privilege.context
|
127
|
-
assert arbitration.rule_per_privilege(privilege).eql?(true), ->{
|
128
|
-
'Not allowed user from %s having privilege %s(%s) to %s over %s' % [
|
129
|
-
user.person.country,
|
130
|
-
privilege.text_key,
|
131
|
-
privilege.country,
|
132
|
-
action,
|
133
|
-
arbitration.scope_and_resource(resource).first
|
134
|
-
]
|
135
|
-
}
|
136
|
-
end
|
137
|
-
|
138
|
-
def assert_not_allows user, privilege, action, resource
|
139
|
-
arbitration = Admission::ResourceArbitration.new user, UserStatus.rules, action, resource
|
140
|
-
arbitration.prepare_sitting privilege.context
|
141
|
-
assert_not arbitration.rule_per_privilege(privilege).eql?(true), ->{
|
142
|
-
'Allowed user from %s having privilege %s(%s) to %s over %s' % [
|
143
|
-
user.person.country,
|
144
|
-
privilege.text_key,
|
145
|
-
privilege.country,
|
146
|
-
action,
|
147
|
-
arbitration.scope_and_resource(resource).first
|
148
|
-
]
|
149
|
-
}
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class UserStatusTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test 'privileges order not changed' do
|
6
|
-
privs = UserStatus.privileges_list
|
7
|
-
assert_equal [Admission::Privilege], privs.map(&:class).uniq
|
8
|
-
assert_equal %w[
|
9
|
-
duke
|
10
|
-
human
|
11
|
-
human-adult
|
12
|
-
human-adult_white_male
|
13
|
-
lord
|
14
|
-
], privs.map(&:text_key).sort
|
15
|
-
end
|
16
|
-
|
17
|
-
test '#dump_privileges' do
|
18
|
-
privs = UserStatus.privileges_list.sort_by(&:text_key)
|
19
|
-
privs = privs.each_with_index.map{|p, i| p.dup_with_context (i % 3).to_s}
|
20
|
-
hash = UserStatus.dump_privileges privs
|
21
|
-
expected_hash = {
|
22
|
-
"0"=> %w[duke human-adult_white_male],
|
23
|
-
"1"=> %w[human lord],
|
24
|
-
"2"=> %w[human-adult],
|
25
|
-
"_all"=> %w[duke human human-adult human-adult_white_male lord]
|
26
|
-
}
|
27
|
-
assert_equal expected_hash, hash
|
28
|
-
end
|
29
|
-
|
30
|
-
test '#parse_privileges' do
|
31
|
-
privs = {
|
32
|
-
"Bohemia"=> %w[duke human-adult_white_male],
|
33
|
-
"_all"=> %w[duke human-adult_white_male]
|
34
|
-
}
|
35
|
-
privs = UserStatus.parse_privileges privs
|
36
|
-
assert_equal 2, privs.length
|
37
|
-
duke, adult = privs.partition{|p| p.text_key == 'duke'}.map(&:first)
|
38
|
-
|
39
|
-
assert_not_nil duke
|
40
|
-
assert_equal :duke, duke.name
|
41
|
-
assert_equal :base, duke.level
|
42
|
-
assert_equal 'Bohemia', duke.context
|
43
|
-
|
44
|
-
assert_not_nil adult
|
45
|
-
assert_equal :human, adult.name
|
46
|
-
assert_equal :adult_white_male, adult.level
|
47
|
-
assert_equal 'Bohemia', adult.context
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
File without changes
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.expand_path('../../config/environment', __FILE__)
|
2
|
-
require 'rails/test_help'
|
3
|
-
|
4
|
-
class ActiveSupport::TestCase
|
5
|
-
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
6
|
-
fixtures :all
|
7
|
-
|
8
|
-
# Add more helper methods to be used by all tests here...
|
9
|
-
end
|
File without changes
|
File without changes
|