module MnoEnterprise::Concerns::Controllers::DeletionRequestsController

TODO: extract the request check to filter or block?

Public Instance Methods

checkout() click to toggle source

PATCH /deletion_requests/1/checkout

# File lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb, line 83
def checkout
  @deletion_request = current_user.deletion_request

  respond_to do |format|
    # Check that the user has a deletion_request in progress
    # and that the token provided (params[:id]) matches the
    # deletion_request token
    if @deletion_request.present? && @deletion_request.token == params[:id]
      # Check that the deletion_request has the right status
      if @deletion_request.status == 'account_frozen'
        # TODO:
        #   Attempt to update the credit cards first
        #   Finally Perform the checkout
        @deletion_request.status = 'account_checked_out'
        @deletion_request.save
        format.html { redirect_to @deletion_request, notice: 'Checkout has been performed successfully' }
      else
        format.html { redirect_to @deletion_request, alert: 'Invalid action' }
      end
    else
      format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
    end
  end
end
freeze_account() click to toggle source

PATCH /deletion_requests/1/freeze_account

# File lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb, line 60
def freeze_account
  @deletion_request = current_user.deletion_request

  respond_to do |format|
    # Check that the user has a deletion_request in progress
    # and that the token provided (params[:id]) matches the
    # deletion_request token
    if @deletion_request.present? && @deletion_request.token == params[:id]
      # Check that the deletion_request has the right status
      if @deletion_request.status == 'pending'
        @deletion_request.freeze_account!
        format.html { redirect_to @deletion_request, notice: 'Your account has been frozen' }
      else
        format.html { redirect_to @deletion_request, alert: 'Invalid action' }
      end
    else
      format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
      format.json { head :bad_request }
    end
  end
end
set_meta() click to toggle source
# File lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb, line 15
def set_meta
  @meta[:title] = "Account Termination"
  @meta[:description] = "Account Termination"
end
show() click to toggle source
Instance methods
GET /deletion_requests/1
# File lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb, line 34
def show
  # authorize! :manage_billing, current_user.organizations.find(@invoice.organization_id)
  @deletion_request = current_user.deletion_request

  respond_to do |format|
    # Check that the user has a deletion_request in progress
    # and that the token provided (params[:id]) matches the
    # deletion_request token
    if @deletion_request.present? && @deletion_request.token == params[:id]

      # Contextual assignments
      if ['account_frozen', 'account_checked_out'].include?(@deletion_request.status)
        # @final_invoices = current_user.final_invoices
        @final_invoices = []
      end

      format.html
      format.json { render json: @deletion_request }
    else
      format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
      format.json { head :bad_request }
    end
  end
end