Skip to content

Commit

Permalink
add in support for detecting restricted models when globally enabled
Browse files Browse the repository at this point in the history
- check when ActiveRecord::Base.using_access_control is used
- filter out "observer" models
  • Loading branch information
urkle committed Sep 27, 2011
1 parent bbfddc8 commit 3eae8b1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/tasks/authorization_tasks.rake
Expand Up @@ -23,8 +23,15 @@ namespace :auth do
end
all += contr_perms.reject {|cp| cp[0].nil?}.collect {|cp| cp[0..1]}
end

model_files = `grep -l "^[[:space:]]*using_access_control" #{RAILS_ROOT}/app/models/*.rb`.split("\n")

model_all = `grep -l "Base\.using_access_control" #{RAILS_ROOT}/config/*.rb #{RAILS_ROOT}/config/initializers/*.rb`.split("\n")
if model_all.count > 0
model_files = Dir.glob( "#{RAILS_ROOT}/app/models/*.rb").reject do |item|
item.match(/_observer\.rb/)
end
else
model_files = `grep -l "^[[:space:]]*using_access_control" #{RAILS_ROOT}/app/models/*.rb`.split("\n")
end
models_with_ac = model_files.collect {|mf| mf.sub(/^.*\//, "").sub(".rb", "").tableize.to_sym}
model_security_privs = [:create, :read, :update, :delete]
models_with_ac.each {|m| perms += model_security_privs.collect{|msp| [msp, m]}}
Expand Down

0 comments on commit 3eae8b1

Please sign in to comment.