Class: Decidim::AuthorizationsController

Inherits:
ApplicationController show all
Includes:
UserProfile
Defined in:
app/controllers/decidim/authorizations_controller.rb

Overview

This controller allows users to create and destroy their authorizations. It shouldn’t be necessary to expand it to add new authorization schemes.

Instance Method Summary collapse

Methods included from UserProfile

#available_authorization_handlers

Methods inherited from ApplicationController

#user_not_authorized_path

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/authorizations_controller.rb', line 25

def create
  AuthorizeUser.call(handler) do
    on(:ok) do
      flash[:notice] = t("authorizations.create.success", scope: "decidim")
      redirect_to 
    end

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

#destroyObject



39
40
41
42
43
44
45
46
# File 'app/controllers/decidim/authorizations_controller.rb', line 39

def destroy
  @authorization = current_user.authorizations.find(params[:id])
  authorize! :destroy, @authorization

  @authorization.destroy
  flash[:notice] = t("authorizations.destroy.success", scope: "decidim")
  redirect_to 
end

#first_loginObject



21
22
23
# File 'app/controllers/decidim/authorizations_controller.rb', line 21

def 
  redirect_to(action: :new, handler: handlers.first.handler_name) if handlers.length == 1
end

#handlerObject



48
49
50
# File 'app/controllers/decidim/authorizations_controller.rb', line 48

def handler
  @handler ||= AuthorizationHandler.handler_for(handler_name, handler_params)
end

#indexObject



17
18
19
# File 'app/controllers/decidim/authorizations_controller.rb', line 17

def index
  @authorizations = current_user.authorizations
end

#newObject



15
# File 'app/controllers/decidim/authorizations_controller.rb', line 15

def new; end