Skip to content

Commit

Permalink
omit validation to apply permissions to all editions, additionally co…
Browse files Browse the repository at this point in the history
…rrecting save_as_task! syntax
  • Loading branch information
baisa committed Nov 20, 2024
1 parent 2279393 commit b21951e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/tasks/access_and_permissions.rake
Original file line number Diff line number Diff line change
@@ -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|
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit b21951e

Please sign in to comment.