johnsbrn-has_permission 0.2.4 → 0.2.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.
- data/VERSION.yml +1 -1
- data/lib/has_permission.rb +4 -1
- data/test/has_permission_test.rb +23 -0
- data/test/test_helper.rb +61 -1
- metadata +4 -1
data/VERSION.yml
CHANGED
data/lib/has_permission.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'active_record/has/permission'
|
3
|
+
require 'action_controller'
|
4
|
+
require 'action_controller/has/permission'
|
3
5
|
require 'permission/base'
|
4
6
|
require 'permission_exception'
|
5
7
|
|
6
|
-
ActiveRecord::Base.send :include, ActiveRecord::Has::Permission
|
8
|
+
ActiveRecord::Base.send :include, ActiveRecord::Has::Permission
|
9
|
+
ActionController::Base.send :include, ActionController::Has::Permission
|
data/test/has_permission_test.rb
CHANGED
@@ -89,6 +89,29 @@ class HasPermissionTest < Test::Unit::TestCase
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
context "controller permission" do
|
93
|
+
setup do
|
94
|
+
@controller = ModelController.new
|
95
|
+
end
|
96
|
+
|
97
|
+
should "call access denied for index" do
|
98
|
+
@controller.expects(:access_denied).once
|
99
|
+
@controller.index
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with options" do
|
103
|
+
setup do
|
104
|
+
@controller2 = Model2Controller.new
|
105
|
+
end
|
106
|
+
|
107
|
+
should "call no access for index" do
|
108
|
+
@controller2.expects(:no_access).once
|
109
|
+
@controller2.index
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
92
115
|
should "use default namespace setting" do
|
93
116
|
assert_equal Permission::ModelPermission, Model.permission_class
|
94
117
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,6 +7,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
7
7
|
require 'has_permission'
|
8
8
|
|
9
9
|
# this doesn't seem like the best way to do this - maybe someone will suggest a better method
|
10
|
+
|
10
11
|
class Model
|
11
12
|
|
12
13
|
include ActiveRecord::Has::Permission
|
@@ -49,12 +50,27 @@ class ModelB
|
|
49
50
|
has_permission :namespace => ''
|
50
51
|
end
|
51
52
|
|
52
|
-
class ModelBPermission
|
53
|
+
class ModelBPermission < Permission::Base
|
54
|
+
def can_index?
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
def can_show?
|
59
|
+
true
|
60
|
+
end
|
53
61
|
end
|
54
62
|
|
55
63
|
module Permission
|
56
64
|
class ModelPermission < Permission::Base
|
57
65
|
|
66
|
+
def can_index?
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
def can_show?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
58
74
|
def can_read?(attr_name)
|
59
75
|
case attr_name
|
60
76
|
when :read_access : true
|
@@ -85,5 +101,49 @@ module Permission
|
|
85
101
|
end
|
86
102
|
end
|
87
103
|
|
104
|
+
class ModelController
|
105
|
+
include ActionController::Has::Permission
|
106
|
+
|
107
|
+
def controller_name
|
108
|
+
"model"
|
109
|
+
end
|
110
|
+
|
111
|
+
def index
|
112
|
+
"index"
|
113
|
+
end
|
114
|
+
|
115
|
+
def show
|
116
|
+
"show"
|
117
|
+
end
|
118
|
+
|
119
|
+
def current_user
|
120
|
+
nil
|
121
|
+
end
|
122
|
+
|
123
|
+
requires_permission :index, :show
|
124
|
+
end
|
125
|
+
|
126
|
+
class Model2Controller
|
127
|
+
include ActionController::Has::Permission
|
128
|
+
|
129
|
+
def controller_name
|
130
|
+
"model"
|
131
|
+
end
|
132
|
+
|
133
|
+
def index
|
134
|
+
"index"
|
135
|
+
end
|
136
|
+
|
137
|
+
def show
|
138
|
+
"show"
|
139
|
+
end
|
140
|
+
|
141
|
+
def current_user
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
|
145
|
+
requires_permission :index, :show, :access_denied => 'no_access', :class => ModelB
|
146
|
+
end
|
147
|
+
|
88
148
|
class Test::Unit::TestCase
|
89
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: johnsbrn-has_permission
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Johnson
|
@@ -23,6 +23,9 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- VERSION.yml
|
26
|
+
- lib/action_controller
|
27
|
+
- lib/action_controller/has
|
28
|
+
- lib/action_controller/has/permission.rb
|
26
29
|
- lib/active_record
|
27
30
|
- lib/active_record/has
|
28
31
|
- lib/active_record/has/permission.rb
|