22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/authorized/authorization.rb', line 22
def method_missing_with_authorization(symb,*args, &block)
method_name = symb.to_s
if method_name =~ /^may_(not_)?(.+)_required$/
full_permission_name = "#{$1}#{$2}"
negate = !!$1 permission_name = $2
verb,target = permission_name.split(/_/,2)
if !target.blank? && target == target.singularize
unless permission = current_user.try(
"may_#{permission_name}?",
instance_variable_get("@#{target}")
)
message = "You don't have permission to " <<
"#{verb} this #{target}."
end
else
unless permission = current_user.try("may_#{permission_name}?")
message = "You don't have permission to " <<
"#{permission_name.gsub(/_/,' ')}."
end
end
unless negate ^ permission
message ||= "Access denied. May #{(negate)?'not ':''}" <<
"#{permission_name.gsub(/_/,' ')}."
ar = auth_redirections(full_permission_name)
access_denied(
(ar[:message]||message),
(ar[:redirect_to]||"/")
)
end
else
method_missing_without_authorization(symb, *args, &block)
end
end
|