Class: Decidim::Verifications::IdDocuments::AuthorizationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Renewable
Defined in:
app/controllers/decidim/verifications/id_documents/authorizations_controller.rb

Overview

Handles verification by identity document upload

Instance Method Summary collapse

Methods inherited from ApplicationController

#renew

Instance Method Details

#chooseObject



16
17
18
19
20
# File 'app/controllers/decidim/verifications/id_documents/authorizations_controller.rb', line 16

def choose
  return redirect_to action: :new, using: verification_type if available_methods.count == 1

  render :choose
end

#createObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/decidim/verifications/id_documents/authorizations_controller.rb', line 30

def create
  enforce_permission_to :create, :authorization, authorization: @authorization

  @form = UploadForm.from_params(params.merge(user: current_user)).with_context(current_organization:)

  PerformAuthorizationStep.call(@authorization, @form) do
    on(:ok) do
      flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.id_documents")
      redirect_to decidim_verifications.authorizations_path
    end

    on(:invalid) do
      flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.id_documents")
      render action: :new
    end
  end
end

#editObject



48
49
50
51
52
# File 'app/controllers/decidim/verifications/id_documents/authorizations_controller.rb', line 48

def edit
  enforce_permission_to :update, :authorization, authorization: @authorization

  @form = UploadForm.from_model(@authorization)
end

#newObject

Raises:

  • (ActionController::RoutingError)


22
23
24
25
26
27
28
# File 'app/controllers/decidim/verifications/id_documents/authorizations_controller.rb', line 22

def new
  raise ActionController::RoutingError, "Method not available" unless available_methods.include?(verification_type)

  enforce_permission_to :create, :authorization, authorization: @authorization

  @form = UploadForm.from_params(id_document_upload: { verification_type: })
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/verifications/id_documents/authorizations_controller.rb', line 54

def update
  enforce_permission_to :update, :authorization, authorization: @authorization

  @form = UploadForm.from_params(
    params.merge(
      user: current_user,
      verification_type:,
      verification_attachment: params[:id_document_upload][:verification_attachment] || @authorization.verification_attachment.blob
    )
  ).with_context(current_organization:)

  PerformAuthorizationStep.call(@authorization, @form) do
    on(:ok) do
      flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.id_documents")
      redirect_to decidim_verifications.authorizations_path
    end

    on(:invalid) do
      flash.now[:alert] = t("authorizations.update.error", scope: "decidim.verifications.id_documents")
      render action: :edit
    end
  end
end