Skip to content
Snippets Groups Projects

Sanitize existing TODOs for confidential notes

Merged Jan Provaznik requested to merge jp-clean-confnotes into master
Files
3
# frozen_string_literal: true
class SanitizeConfidentialNoteTodos < Gitlab::Database::Migration[2.0]
restrict_gitlab_migration gitlab_schema: :gitlab_main
def up
# This migration is not properly isolated. The reason for this is
# that we need to check permission for notes and it would be difficult
# to extract.
# Details in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87908#note_952459215
Note.where(confidential: true).each_batch(of: 100) do |notes|
todos = Todo.where(note_id: notes.select(:id)).includes(:note, :user)
delete_ids = todos.each_with_object([]) do |todo, ids|
ids << todo.id if invalid_todo?(todo)
end
next if delete_ids.empty?
Todo.where(id: delete_ids).delete_all
end
end
def down
# no-op
end
private
def invalid_todo?(todo)
return false unless todo.note
return false if Ability.allowed?(todo.user, :read_note, todo.note)
Gitlab::AppLogger.info(
message: "#{self.class.name} deleting invalid todo",
attributes: todo.attributes
)
true
end
end
Loading