roled 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/roled/install_generator.rb +4 -0
- data/lib/generators/roled/templates/roled.rb +3 -0
- data/lib/roled.rb +1 -0
- data/lib/roled/acts_as.rb +6 -14
- data/lib/roled/core.rb +20 -8
- data/lib/roled/exceptions.rb +23 -0
- data/lib/roled/version.rb +1 -1
- metadata +4 -2
data/lib/roled.rb
CHANGED
data/lib/roled/acts_as.rb
CHANGED
@@ -6,29 +6,21 @@ module Roled
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def permission?(controller, action)
|
9
|
-
|
9
|
+
has_permission_to?(controller,action)
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_permission_to?(controller, action)
|
13
|
-
if !controller || !action
|
14
|
-
return false
|
15
|
-
end
|
16
|
-
|
13
|
+
return false if !controller || !action
|
17
14
|
options = self.class.global_options
|
18
|
-
|
19
|
-
|
15
|
+
if !options.blank?
|
16
|
+
groups = []
|
20
17
|
options.each do |key,name|
|
21
|
-
if key == :belongs_to
|
22
|
-
if(defined?(self.send(name)))
|
23
|
-
groups << self.send(name)
|
24
|
-
end
|
25
|
-
end
|
18
|
+
groups << self.send(name) if key == :belongs_to && defined?(self.send(name))
|
26
19
|
end
|
27
20
|
end
|
28
|
-
|
29
21
|
parent = "#{controller}_controller"
|
30
22
|
if !Aco.where(:parent => parent, :action => action).exists?
|
31
|
-
|
23
|
+
raise UnknownAro, "Action is undefined, run rake acos:generate"
|
32
24
|
end
|
33
25
|
|
34
26
|
ids = Aco.where("parent IN (?) AND action is NULL OR parent = ? AND action = ?", [parent,"all"], parent, action).order('action desc')
|
data/lib/roled/core.rb
CHANGED
@@ -5,24 +5,36 @@ module Roled
|
|
5
5
|
included do
|
6
6
|
end
|
7
7
|
|
8
|
-
def authorize_user!
|
9
|
-
if defined?(
|
10
|
-
|
8
|
+
def authorize_user!
|
9
|
+
if defined?(@@modules)
|
10
|
+
current = params[:controller].split('/', 2)[0]
|
11
|
+
if @@modules.include?(current.to_sym)
|
11
12
|
return
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
14
16
|
if(!user.blank?)
|
15
|
-
action = params[:action]
|
16
|
-
if(!action)
|
17
|
-
action = "index"
|
18
|
-
end
|
17
|
+
action = params[:action] || "index"
|
19
18
|
request = user.has_permission_to? params[:controller], action
|
20
19
|
if(request != nil && request)
|
21
20
|
else
|
22
|
-
|
21
|
+
raise Unauthorized
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
26
|
+
def self.user=(user)
|
27
|
+
@@user = user
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.skip_module=(modules)
|
31
|
+
@@modules = modules
|
32
|
+
end
|
33
|
+
|
34
|
+
def user
|
35
|
+
send(@@user)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
27
39
|
end
|
28
40
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Roled
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class UnknownAro < Error; end
|
6
|
+
|
7
|
+
class Unauthorized < Error
|
8
|
+
attr_reader :action, :subject
|
9
|
+
attr_writer :default_message
|
10
|
+
|
11
|
+
def initialize(message = nil, action = nil, subject = nil)
|
12
|
+
@message = message
|
13
|
+
@action = action
|
14
|
+
@subject = subject
|
15
|
+
@default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@message || @default_message
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/roled/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -53,8 +53,10 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- lib/generators/roled/install_generator.rb
|
55
55
|
- lib/generators/roled/templates/migration.rb
|
56
|
+
- lib/generators/roled/templates/roled.rb
|
56
57
|
- lib/roled/acts_as.rb
|
57
58
|
- lib/roled/core.rb
|
59
|
+
- lib/roled/exceptions.rb
|
58
60
|
- lib/roled/models/aco.rb
|
59
61
|
- lib/roled/models/acos_aro.rb
|
60
62
|
- lib/roled/models/aro.rb
|