Module: MnoEnterprise::Concerns::Controllers::DeletionRequestsController

Extended by:
ActiveSupport::Concern
Included in:
DeletionRequestsController
Defined in:
lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb

Overview

TODO: extract the request check to filter or block?

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#checkoutObject

PATCH /deletion_requests/1/checkout



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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_accountObject

PATCH /deletion_requests/1/freeze_account



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb', line 60

def 
  @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

#showObject

Instance methods

GET /deletion_requests/1



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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