Class: Decidim::ActionDelegator::Admin::ParticipantsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Paginable, NeedsPermission
Defined in:
app/controllers/decidim/action_delegator/admin/participants_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/participants_controller.rb', line 25

def create
  enforce_permission_to :create, :participant

  @form = form(ParticipantForm).from_params(params, setting: current_setting)

  CreateParticipant.call(@form) do
    on(:ok) do
      notice = I18n.t("participants.create.success", scope: "decidim.action_delegator.admin")
      redirect_to setting_participants_path(current_setting), notice: notice
    end

    on(:invalid) do |_error|
      flash.now[:error] = I18n.t("participants.create.error", scope: "decidim.action_delegator.admin")
      render :new
    end
  end
end

#destroyObject



66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/action_delegator/admin/participants_controller.rb', line 66

def destroy
  enforce_permission_to :destroy, :participant, resource: participant

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

#editObject



43
44
45
46
47
# File 'app/controllers/decidim/action_delegator/admin/participants_controller.rb', line 43

def edit
  enforce_permission_to :update, :participant

  @form = form(ParticipantForm).from_model(participant, setting: current_setting)
end

#indexObject



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

def index
  enforce_permission_to :index, :participant
end

#newObject



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

def new
  enforce_permission_to :create, :participant

  @form = form(ParticipantForm).instance(setting: current_setting)
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/decidim/action_delegator/admin/participants_controller.rb', line 49

def update
  enforce_permission_to :update, :participant

  @form = form(ParticipantForm).from_params(params, setting: current_setting)
  UpdateParticipant.call(@form, participant) do
    on(:ok) do
      notice = I18n.t("participants.update.success", scope: "decidim.action_delegator.admin")
      redirect_to setting_participants_path(current_setting), notice: notice
    end

    on(:invalid) do |_error|
      flash.now[:error] = I18n.t("participants.update.error", scope: "decidim.action_delegator.admin")
      render :edit
    end
  end
end