Class: Webhooks::V1::Facebook::DataDeletionController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/webhooks/v1/facebook/data_deletion_controller.rb

Overview

Webhook controller: Facebook Data Deletion Callback.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /webhooks/v1/facebook/data_deletion



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/webhooks/v1/facebook/data_deletion_controller.rb', line 19

def create
  user_id = @signed_payload['user_id']
  if user_id.blank?
    Rails.logger.warn '[Webhooks::Facebook::DataDeletion] rejecting: missing_user_id'
    head :unauthorized
    return
  end

  # Idempotency: Meta retries on non-2xx responses. If we've already
  # received this UID, return the existing confirmation_code so the
  # user lands on the same status page. Backed by the unique
  # composite index on (source, external_user_id) so a race between
  # two parallel retries still resolves to a single row.
  request_row = Privacy::DeletionRequest.find_or_create_by!(
    source:           'facebook_callback',
    external_user_id: user_id
  ) do |req|
    req.data = @signed_payload
  end

  Privacy::DataDeletionWorker.perform_async(request_row.id) if request_row.previously_new_record?

  render json: {
    url:               status_url_for(request_row),
    confirmation_code: request_row.confirmation_code
  }, status: :ok
end