Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rake Task to Remove Deprecated Permissions #832

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/tasks/data_cleanup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ namespace :data_cleanup do
p 'Done'
end

desc 'Remove deprecated permissions from users and delete them from perms table'
task remove_deprecated_perms: :environment do
deprecated_perms = Perm.where(name: %w[admin user org_admin])
deprecated_perms_ids = deprecated_perms.pluck(:id)
users_with_deprecated_perms = User.includes(:perms).where(perms: { id: deprecated_perms_ids })
p "#{users_with_deprecated_perms.count} users have deprecated permissions"
p '----------------------------------------------------------------------'
p 'Deleting the following deprecated permissions for the following users:'
users_with_deprecated_perms.each do |user|
perms_to_delete = user.perms.where(id: deprecated_perms_ids)
p "#{user.email}: #{perms_to_delete.pluck(:name)}"
p '----------------------------------------------------------------------'
user.perms.delete(perms_to_delete)
end
p "Removing #{deprecated_perms.count} deprecated permissions from perms table:"
p '----------------------------------------------------------------------'
deprecated_perms.destroy_all
p 'Done'
end

private

def report_known_invalidations(results, model_name, validation_error)
Expand Down
Loading