indulgence 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.rdoc +25 -0
- data/lib/active_record/acts/indulgent.rb +1 -0
- data/lib/indulgence/indulgent.rb +4 -0
- data/lib/indulgence/version.rb +3 -1
- data/test/db/test.sqlite3.db +0 -0
- data/test/units/thing_test.rb +36 -3
- metadata +7 -14
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGQ4NWQwM2JlNzE1OTgwZmU5MzczOTQwY2JhODMyNGU1NDMwZjBlYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTMyYzI5MWYyNzkwZTFjOGI5NWMwMWQ1NTk5NzI5N2NmZGQ2Yzc4Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjgxM2ZmOWNjMTkzNmEwMWZlNjY1MTUwYWViODcwMThjNjdjNzc0ODllMGQ5
|
10
|
+
YTU5YWY4NWJiYTQ1MWE3ZDI3ODg1YjA4NGI1ZTEyMzY0OGU3YjVjNDI4ZjU3
|
11
|
+
NzJkNjgwYTJmODZmMjUyMWI1Yjc4YjhiYjkxYTgyMmE1ZWM0MWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmFlMWUxMDgxYzI5MDBiMjY3ZGQ1NjVjZWJkZDI4MzU1ZDRmMzNmYmMwYzE0
|
14
|
+
ODg1NjUxNWZlYmQ5ZDRkNTYwOTMyY2FiZTVjOWIxOGQ2Njk0NDQ1MjJhOTY0
|
15
|
+
NWQxNDczNjBhMjA3YWJkMWQzMmU5ODc5MzlkYWQzY2VlODc2N2U=
|
data/README.rdoc
CHANGED
@@ -88,6 +88,13 @@ Simple true/false permission can be determined using the :indulge? method:
|
|
88
88
|
thing.indulge?(user, :update) == false
|
89
89
|
thing.indulge?(user, :delete) == false
|
90
90
|
|
91
|
+
=== indulge? as a class method
|
92
|
+
|
93
|
+
There is also a class :indulge? method. Calling this is the equivalent to
|
94
|
+
calling :indulge? on a new object.
|
95
|
+
|
96
|
+
Thing.indulge?(user, :create) == Thing.new.indulge?(user, :create)
|
97
|
+
|
91
98
|
== Filter many: indulgence
|
92
99
|
|
93
100
|
The :indulgence method is used as a where filter:
|
@@ -251,6 +258,22 @@ With that done:
|
|
251
258
|
Thing.indulgence(cicero, :update) == [thing]
|
252
259
|
Thing.indulgence(cicero, :delete) --> raises ActiveRecord::RecordNotFound
|
253
260
|
|
261
|
+
Notice how Thing.indulge? behaves:
|
262
|
+
|
263
|
+
Thing.indulge?(cicero, :create) == false
|
264
|
+
|
265
|
+
Thing.indulge? acts on a new instance of Thing where author_id will not be set.
|
266
|
+
If this is not the behaviour expected, the permission may need to be checked
|
267
|
+
at a stage after initialization, but before persisting:
|
268
|
+
|
269
|
+
thing = Thing.new(author: user)
|
270
|
+
if thing.indulge?(user, :create)
|
271
|
+
thing.save
|
272
|
+
end
|
273
|
+
|
274
|
+
In this example, the thing will be saved if the user is cicero, but not if
|
275
|
+
the user has the role 'pleb'.
|
276
|
+
|
254
277
|
=== Defining your own actions
|
255
278
|
|
256
279
|
The default actions on which indulgence is based are the CRUD operations:
|
@@ -345,6 +368,8 @@ With this used to define indulgence in Thing, we can do this:
|
|
345
368
|
thing.permit?(cicero, :update) == true
|
346
369
|
thing.permit?(cicero, :delete) == false
|
347
370
|
|
371
|
+
Thing.permit?(cicero, :update) == false
|
372
|
+
|
348
373
|
Thing.permitted(cicero, :create) == [thing]
|
349
374
|
Thing.permitted(cicero, :read) == Thing.all
|
350
375
|
|
@@ -13,6 +13,7 @@ module ActiveRecord
|
|
13
13
|
|
14
14
|
alias_method args[:compare_single_method], :indulge? if args[:compare_single_method]
|
15
15
|
singleton_class.send(:alias_method, args[:filter_many_method], :indulgence) if args[:filter_many_method]
|
16
|
+
singleton_class.send(:alias_method, args[:compare_single_method], :indulge?) if args[:compare_single_method]
|
16
17
|
self.indulgent_permission_class = args[:using]
|
17
18
|
end
|
18
19
|
|
data/lib/indulgence/indulgent.rb
CHANGED
data/lib/indulgence/version.rb
CHANGED
data/test/db/test.sqlite3.db
CHANGED
Binary file
|
data/test/units/thing_test.rb
CHANGED
@@ -47,8 +47,8 @@ class ThingTest < Test::Unit::TestCase
|
|
47
47
|
assert_equal(true, @thing.indulge?(@owner, :delete))
|
48
48
|
assert_equal(false, @other_thing.indulge?(@owner, :delete))
|
49
49
|
end
|
50
|
-
|
51
|
-
def
|
50
|
+
|
51
|
+
def test_indulge_via_entity_id
|
52
52
|
make_second_thing
|
53
53
|
@owner.update_attribute(:role, @thief)
|
54
54
|
assert_equal(true, @thing.indulge?(@owner, :read))
|
@@ -56,13 +56,40 @@ class ThingTest < Test::Unit::TestCase
|
|
56
56
|
assert_equal(false, @thing.indulge?(@owner, :delete))
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def test_indulge_via_entity_association
|
60
60
|
make_second_thing
|
61
61
|
@owner.update_attribute(:role, @friend)
|
62
62
|
assert_equal(true, @thing.indulge?(@owner, :read))
|
63
63
|
assert_equal(true, @thing.indulge?(@owner, :update))
|
64
64
|
assert_equal(false, @thing.indulge?(@owner, :delete))
|
65
65
|
end
|
66
|
+
|
67
|
+
def test_indulge_on_new_object
|
68
|
+
@thing = Thing.new(:name => 'New', :owner => @owner)
|
69
|
+
@owner.update_attribute(:role, @demigod)
|
70
|
+
assert_equal(true, @thing.indulge?(@owner, :create))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_indulge_on_new_object_where_ability_defined_by_relationshop_name
|
74
|
+
@thing = Thing.new(:name => 'New', :owner => @owner)
|
75
|
+
@owner.update_attribute(:role, @friend)
|
76
|
+
assert_equal(true, @thing.indulge?(@owner, :update))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_indulge_as_class_method
|
80
|
+
assert_equal(false, Thing.indulge?(@owner, :read))
|
81
|
+
@owner.update_attribute(:role, @god)
|
82
|
+
assert_equal(true, Thing.indulge?(@owner, :read))
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_indulge_as_class_method_with_custom_method
|
86
|
+
@owner.update_attribute(:role, @thief)
|
87
|
+
assert_equal(false, Thing.indulge?(@owner, :update))
|
88
|
+
@owner.update_attribute(:role, @friend)
|
89
|
+
assert_equal(false, Thing.indulge?(@owner, :update))
|
90
|
+
@owner.update_attribute(:role, @demigod)
|
91
|
+
assert_equal(false, Thing.indulge?(@owner, :update))
|
92
|
+
end
|
66
93
|
|
67
94
|
def test_indulge_other_thing
|
68
95
|
other_thing = OtherThing.create(:name => 'Other Stuff', :owner => @owner)
|
@@ -116,6 +143,12 @@ class ThingTest < Test::Unit::TestCase
|
|
116
143
|
assert_equal(false, @thing.permit?(@owner, :delete))
|
117
144
|
assert_equal(false, @other_thing.permit?(@owner, :delete))
|
118
145
|
end
|
146
|
+
|
147
|
+
def test_aliased_class_compare_single_method
|
148
|
+
assert_equal(false, Thing.permit?(@owner, :read))
|
149
|
+
@owner.update_attribute(:role, @god)
|
150
|
+
assert_equal(true, Thing.permit?(@owner, :read))
|
151
|
+
end
|
119
152
|
|
120
153
|
def test_aliased_filter_many_method
|
121
154
|
make_second_thing
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indulgence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rob Nichols
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: sqlite3
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: standalone_migrations
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -98,28 +91,28 @@ files:
|
|
98
91
|
- test/db/schema.rb
|
99
92
|
- test/test_helper.rb
|
100
93
|
homepage: https://github.com/reggieb/indulgence
|
101
|
-
licenses:
|
94
|
+
licenses:
|
95
|
+
- MIT-LICENSE
|
96
|
+
metadata: {}
|
102
97
|
post_install_message:
|
103
98
|
rdoc_options: []
|
104
99
|
require_paths:
|
105
100
|
- lib
|
106
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
102
|
requirements:
|
109
103
|
- - ! '>='
|
110
104
|
- !ruby/object:Gem::Version
|
111
105
|
version: '0'
|
112
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
107
|
requirements:
|
115
108
|
- - ! '>='
|
116
109
|
- !ruby/object:Gem::Version
|
117
110
|
version: '0'
|
118
111
|
requirements: []
|
119
112
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 2.1.10
|
121
114
|
signing_key:
|
122
|
-
specification_version:
|
115
|
+
specification_version: 4
|
123
116
|
summary: Yet another permissions gem
|
124
117
|
test_files:
|
125
118
|
- test/units/role_test.rb
|