Skip to content

Commit 275a363

Browse files
authored
CV2-6700: expire api keys and delete webhooks for deactivated workspace (#2417)
* CV2-6700: expire api keys and delete webhooks for deactivated workspace * CV2-6700: print webhook settings
1 parent 15e6403 commit 275a363

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/tasks/data/team.rake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ namespace :check do
2626
task :deactivate, [:slugs] => :environment do |_t, args|
2727
slugs = args[:slugs].to_s.split('|')
2828
Team.where(slug: slugs, inactive: false).find_each do |team|
29+
puts "\nProcessing team #{team.slug}....\n"
2930
print '.'
31+
# Expire API keys
32+
date = Time.now - 1.month
33+
ApiKey.where(team_id: team.id).update_all(expire_at: date)
34+
# Delete webhooks
35+
webhook_installations = team.team_users.joins(:user).where('users.type' => 'BotUser', 'users.default' => false).select{ |team_user| team_user.user.events.present? && team_user.user.get_request_url.present? && !team_user.user.get_approved }
36+
webhook_installations.map(&:user).each do |bu|
37+
puts "\nDeleting webhook #{bu.name}....\n"
38+
puts "\nWebhook settings: #{bu.settings.inspect}"
39+
bu.destroy
40+
end
3041
team.inactive = true
3142
team.save!
3243
end

0 commit comments

Comments
 (0)