Class: Decidim::ActionDelegator::Admin::DelegationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
NeedsPermission, Paginable
Defined in:
app/controllers/decidim/action_delegator/admin/delegations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/decidim/action_delegator/admin/delegations_controller.rb', line 25

def create
  enforce_permission_to :create, :delegation

  @form = DelegationForm.from_params(params)

  CreateDelegation.call(@form, current_user, current_setting) do
    on(:ok) do
      notice = I18n.t("delegations.create.success", scope: "decidim.action_delegator.admin")
      redirect_to setting_delegations_path(current_setting), notice: notice
    end

    on(:error) do |error|
      flash.now[:error] = error
      render :new
    end
  end
end

#destroyObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/decidim/action_delegator/admin/delegations_controller.rb', line 43

def destroy
  enforce_permission_to :destroy, :delegation, resource: delegation

  if delegation.destroy
    notice = I18n.t("delegations.destroy.success", scope: "decidim.action_delegator.admin")
    redirect_to setting_delegations_path(current_setting), notice: notice
  else
    error = I18n.t("delegations.destroy.error", scope: "decidim.action_delegator.admin")
    redirect_to setting_delegations_path(current_setting), flash: { error: error }
  end
end

#indexObject



15
16
17
# File 'app/controllers/decidim/action_delegator/admin/delegations_controller.rb', line 15

def index
  enforce_permission_to :index, :delegation
end

#newObject



19
20
21
22
23
# File 'app/controllers/decidim/action_delegator/admin/delegations_controller.rb', line 19

def new
  enforce_permission_to :create, :delegation

  @form = form(DelegationForm).instance
end