diff --git a/lib/tasks/access_and_permissions.rake b/lib/tasks/access_and_permissions.rake index 09a6fd123..3fa649932 100644 --- a/lib/tasks/access_and_permissions.rake +++ b/lib/tasks/access_and_permissions.rake @@ -1,3 +1,5 @@ +require "csv" + namespace :permissions do desc "Add an organisation to an document's access permissions list" task :add_organisation_access, %i[document_content_id org_content_id] => :environment do |_, args| @@ -9,8 +11,9 @@ namespace :permissions do else Edition.where(panopticon_id: document.id).each do |edition| edition.owning_org_content_ids << args[:org_content_id] + edition.save!(validate: false) end - document.save_as_task("PermissionsAddition") + document.save_as_task!("PermissionsAddition") puts "Access permission successfully assigned" end end @@ -45,16 +48,15 @@ namespace :permissions do desc "Bulk process access permissions from CSV of URLs - See doc" task :bulk_process_access_flags, %i[csv_filename organisation_id] => :environment do |_, args| - csv = CSV.new(args[csv_filename]) - csv.each do |row| - path = row[0] + CSV.foreach(args[:csv_filename], headers: true) do |row| + path = row[1] path.slice! "https://www.gov.uk/" - document = Artefact.where(slug: path) + document = Artefact.find_by(slug: path) next if document.nil? Rake::Task["permissions:add_organisation_access"].reenable # I prefer to do this first but can be done after if cleaner - Rake::Task["permissions:add_organisation_access"].invoke(document.id, organisation_id) + Rake::Task["permissions:add_organisation_access"].invoke(document.id, args[:organisation_id]) end end end