Last active
January 14, 2016 05:30
-
-
Save mccun934/9dba99caa1d2d75fea12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Create an Organization Administrator Role for each Organization defined' | |
task :create_org_admins => :environment do | |
puts "Creating Roles for every Organization with all Permissions except Organization and Role objects." | |
puts "" | |
orgs = Organization.all | |
for o in orgs | |
role_name = "Org Admin - #{o.name}" | |
puts " ** Creating ROLE: #{role_name}" | |
r = Role.new(:name => role_name) | |
r.save | |
# Iterate over all Permissions and setup map of Permissions to IDs | |
rtypes = {} | |
for p in Permission.all | |
# Skip Role and Organization permissions | |
if ['Role', 'Organization'].include? p.resource_type | |
next | |
end | |
if rtypes[p.resource_type].nil? | |
rtypes[p.resource_type] = [] | |
end | |
rtypes[p.resource_type] << p.id | |
end | |
puts " ** Adding Filters to ROLE: #{role_name}" | |
rtypes.each do |key, array| | |
f = Filter.new({"role_id"=>r.id, "permission_ids"=>array}) | |
f.save | |
end | |
end | |
puts "" | |
puts "Done creating new Roles with all Filters and Permissions except Organization and Role objects." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment