Class: Decidim::DecidimAwesome::Admin::AdminAuthorizationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
NeedsAwesomeConfig
Defined in:
app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb

Instance Method Summary collapse

Methods included from NeedsAwesomeConfig

extended, included

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#destroyObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb', line 53

def destroy
  message = if destroy_authorization
              render_to_string("callout", locals: { i18n_key: "authorization_destroyed", klass: "success" })
            else
              render_to_string("callout", locals: { i18n_key: "authorization_not_destroyed", klass: "alert" })
            end

  render json: {
    message:,
    granted: granted?,
    userId: user.id,
    handler: workflow.name
  }
end

#editObject



18
19
20
# File 'app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb', line 18

def edit
  render "authorization" if authorization
end

#updateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb', line 22

def update
  if conflict
    message = render_to_string("conflict")
  else
    message = render_to_string("callout", locals: { i18n_key: "user_authorized", klass: "success" })
    Decidim::Verifications::AuthorizeUser.call(handler, current_organization) do
      on(:transferred) do |transfer|
        message += render_to_string("callout", locals: { i18n_key: "authorization_transferred", klass: "success" }) if transfer.records.any?
      end
      on(:invalid) do
        if force_verification.present?
          create_forced_authorization
        else
          callout = render_to_string("callout", locals: { i18n_key: "user_not_authorized", klass: "alert" }, layout: false)
          message = render_to_string("edit", locals: { with_override: true, callout: })
        end
      end
      on(:ok) do
        Decidim::ActionLogger.log("admin_creates_authorization", current_user, user, nil, user_id: user.id, handler: workflow.name, handler_name: workflow.fullname)
      end
    end
  end

  render json: {
    message:,
    granted: granted?,
    userId: user.id,
    handler: workflow.name
  }
end