role_authorization 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -47,7 +47,7 @@ module RoleAuthorization
|
|
47
47
|
|
48
48
|
def authorized_action?(controller_klass, controller, action, id = nil)
|
49
49
|
# by default admins see everything
|
50
|
-
return true if admin?
|
50
|
+
return true if current_user && current_user.admin?
|
51
51
|
|
52
52
|
ruleset = self.class.ruleset[controller]
|
53
53
|
groups = RoleAuthorization::AllowGroup.get(self.class.allowable_groups[controller])
|
@@ -82,30 +82,49 @@ module RoleAuthorization
|
|
82
82
|
|
83
83
|
def authorized?(url, method = nil)
|
84
84
|
return false unless url
|
85
|
-
return true if admin?
|
85
|
+
return true if current_user && current_user.admin?
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
unless url.is_a?(Hash)
|
88
|
+
method ||= (params[:method] || request.method)
|
89
|
+
url_parts = URI::split(url.strip)
|
90
|
+
path = url_parts[5]
|
91
|
+
end
|
90
92
|
|
91
93
|
begin
|
92
|
-
hash =
|
93
|
-
|
94
|
+
hash = if url.is_a?(Hash)
|
95
|
+
url
|
96
|
+
else
|
97
|
+
Rails.application.routes.recognize_path(path, :method => method)
|
98
|
+
end
|
99
|
+
|
100
|
+
if hash
|
101
|
+
controller_klass = if self.controller_name == hash[:controller]
|
102
|
+
self
|
103
|
+
else
|
104
|
+
klass = (hash[:controller].camelize + "Controller").constantize.new
|
105
|
+
klass.params = hash
|
106
|
+
klass
|
107
|
+
end
|
108
|
+
|
109
|
+
return authorized_action?(controller_klass, hash[:controller], hash[:action].to_sym, hash[:id])
|
110
|
+
end
|
94
111
|
rescue Exception => e
|
95
112
|
Rails.logger.error e.inspect
|
96
113
|
e.backtrace.each {|line| Rails.logger.error line }
|
97
114
|
# continue on
|
98
115
|
end
|
99
116
|
|
100
|
-
|
101
|
-
|
117
|
+
unless url.is_a?(Hash)
|
118
|
+
# Mailto link
|
119
|
+
return true if url =~ /^mailto:/
|
102
120
|
|
103
|
-
|
104
|
-
|
105
|
-
|
121
|
+
# Public file
|
122
|
+
file = File.join(Rails.root, 'public', url)
|
123
|
+
return true if File.exists?(file)
|
106
124
|
|
107
|
-
|
108
|
-
|
125
|
+
# Passing in different domain
|
126
|
+
return remote_url?(url_parts[2])
|
127
|
+
end
|
109
128
|
end
|
110
129
|
|
111
130
|
def remote_url?(domain = nil)
|
@@ -72,7 +72,7 @@ module RoleAuthorization
|
|
72
72
|
|
73
73
|
[global_roles, object_roles.values].flatten.map do |role_name|
|
74
74
|
if persisted_roles.delete(role_name).nil?
|
75
|
-
klass.create(:name => role_name, :nickname => nicknames[role_name])
|
75
|
+
klass.create(:name => role_name.to_s, :nickname => nicknames[role_name].to_s)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -4,8 +4,24 @@ module RoleAuthorization
|
|
4
4
|
base.send :extend, ClassMethods
|
5
5
|
base.send :include, InstanceMethods
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
if defined?(ActiveRecord::Base)
|
8
|
+
base.class_eval do
|
9
|
+
serialize :serialized_roles
|
10
|
+
end
|
11
|
+
elsif defined?(Mongoid::Attributes)
|
12
|
+
base.class_eval do
|
13
|
+
set_callback(:save, :before) do |user|
|
14
|
+
write_attribute(:serialized_roles, YAML.dump(@serialized_roles || {}))
|
15
|
+
end
|
16
|
+
|
17
|
+
def serialized_roles
|
18
|
+
@serialized_roles ||= (YAML.load(read_attribute(:serialized_roles).to_s) || {})
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialized_roles=(value)
|
22
|
+
@serialized_roles = value
|
23
|
+
end
|
24
|
+
end
|
9
25
|
end
|
10
26
|
|
11
27
|
RoleAuthorization::Roles::Manager.user_klass = base
|
data/lib/role_authorization.rb
CHANGED
@@ -49,11 +49,9 @@ module RoleAuthorization
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def enable_view_security
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
ActionView::Base.class_eval { include RoleAuthorization::ViewSecurity }
|
56
|
-
end
|
52
|
+
require 'role_authorization/view_security'
|
53
|
+
unless ActionView::Base.instance_methods.include? :link_to_or_show
|
54
|
+
ActionView::Base.class_eval { include RoleAuthorization::ViewSecurity }
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: role_authorization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John 'asceth' Long
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-12 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|