Skip to content

Commit

Permalink
Add logging to permission removal Rake task
Browse files Browse the repository at this point in the history
This Rake task didn't have any count logging, so in order to be sure it
worked, you'd have to run some of the code after (and also ideally
before) running the Rake task to check the permission counts. This task
has already been run, but we may reuse it in future and/or use it as a
template for other similar Rake tasks, so we should make it more of a
best practice example now
  • Loading branch information
yndajas committed Jun 3, 2024
1 parent 6b53539 commit dffac05
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/tasks/permissions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ namespace :permissions do
supported_permission: whitehall_managing_editor_permission,
user_id: User.where.not(organisation_id: gds.id),
).pluck(:user_id)
user_editor_permissions_to_destroy_ids = UserApplicationPermission.where(
editor_permissions_to_destroy = UserApplicationPermission.where(
supported_permission: whitehall_editor_permission,
user_id: non_gds_users_with_managing_editor_permission_user_ids,
)

user_editor_permissions_to_destroy_ids.destroy_all
puts "Number of non-GDS users with both managing editor and editor permissions in Whitehall"
puts "Before removing permissions: #{editor_permissions_to_destroy.count}"

editor_permissions_to_destroy.destroy_all

count_of_remaining_users_with_both_permissions = UserApplicationPermission.where(
supported_permission: whitehall_editor_permission,
user_id: non_gds_users_with_managing_editor_permission_user_ids,
).count

puts "After removing permissions: #{count_of_remaining_users_with_both_permissions}"
end
end

0 comments on commit dffac05

Please sign in to comment.