10
11
12
13
14
15
16
17
18
19
20
21
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
|
# File 'lib/isaca/rails/authorization.rb', line 10
def authorize_isaca_user(user = nil)
if (!user.nil? && user.admin?) || (!current_isaca_user.nil? && current_isaca_user.admin?)
if %w(index new show create update destroy).include?(action_name)
if %w(index show).include?(action_name)
behavior = 'read'
else
behavior = 'write'
end
else
if %w(GET).include?(request.method)
behavior = 'read'
else
behavior = 'write'
end
end
privilege = "#{behavior}_#{controller_name.underscore}".to_sym
unless user_has_privilege?(user, privilege)
respond_to do |format|
message = "#{t('isaca.rails.claims.admin_required')} Missing claim: #{privilege}."
format.html do
redirect_to root_path, alert: message
end
format.json do
render json: {error: message}.to_json, status: :forbidden
end
format.any do
redirect_to root_path, alert: message
end
end
end
else
respond_to do |format|
format.html do
redirect_to root_path, alert: t('isaca.rails.claims.admin_required')
end
format.json do
render json: {error: t('isaca.rails.claims.admin_required')}.to_json, status: :forbidden
end
format.any do
redirect_to root_path, alert: t('isaca.rails.claims.admin_required')
end
end
end
end
|