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

Inherits:
ApplicationController show all
Includes:
Renewable
Defined in:
decidim-verifications/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

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#chooseObject


16
17
18
19
20
# File 'decidim-verifications/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 'decidim-verifications/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))

  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[:alert] = t("authorizations.create.error", scope: "decidim.verifications.id_documents")
      render action: :new
    end
  end
end

#editObject


48
49
50
51
52
# File 'decidim-verifications/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 'decidim-verifications/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: 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 'decidim-verifications/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_type,
      verification_attachment: params[:id_document_upload][:verification_attachment] || @authorization.verification_attachment
    )
  )

  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[:alert] = t("authorizations.update.error", scope: "decidim.verifications.id_documents")
      render action: :edit
    end
  end
end