Class: Decidim::ActionDelegator::Verifications::DelegationsVerifier::AuthorizationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
FormFactory, Verifications::Renewable
Defined in:
app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb', line 39

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

  @form = form(DelegationsVerifierForm).from_params(params, setting: setting)
  participant = @form&.participant

  Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do
    on(:ok) do
      if setting.phone_required?
        flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.sms")
        authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name)
        redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url)
      else
        grant_and_redirect(participant)
      end
    end
    on(:invalid) do
      flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.sms")
      render :new
    end
  end
end

#destroyObject



87
88
89
90
91
92
93
94
# File 'app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb', line 87

def destroy
  enforce_permission_to :destroy, :authorization, authorization: authorization

  authorization.destroy!
  flash[:notice] = t("authorizations.destroy.success", scope: "decidim.verifications.sms")

  redirect_to action: :new
end

#editObject



62
63
64
65
66
# File 'app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb', line 62

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

  @form = form(Decidim::Verifications::Sms::ConfirmationForm).from_params(params)
end

#newObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb', line 20

def new
  @authorization.destroy! if authorization&.persisted? && !authorization&.granted?

  enforce_permission_to :create, :authorization, authorization: authorization
  @form = form(DelegationsVerifierForm).instance(setting: setting)
  participant = @form&.participant

  return unless ActionDelegator. && setting&.verify_with_email?

  Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do
    on(:ok) do
      grant_and_redirect(participant)
    end
    on(:invalid) do
      render :new
    end
  end
end

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb', line 68

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

  @form = form(Decidim::Verifications::Sms::ConfirmationForm).from_params(params)

  Decidim::Verifications::ConfirmUserAuthorization.call(authorization, @form, session) do
    on(:ok) do
      flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")

      redirect
    end

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