Class: Decidim::Elections::Admin::TrusteesParticipatorySpacesController

Inherits:
ApplicationController show all
Defined in:
decidim-elections/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb

Overview

This controller allows to add a user as trustee, update the status and remove a trustee from a participatory space.

Instance Method Summary collapse

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #set_component_breadcrumb_item, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-elections/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb', line 18

def create
  enforce_permission_to :create, :trustee_participatory_space
  @form = form(TrusteesParticipatorySpaceForm).from_params(params)

  AddUserAsTrustee.call(@form, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("trustees_participatory_spaces.create.success", scope: "decidim.elections.admin")
      redirect_to trustees_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("trustees_participatory_spaces.create.invalid", scope: "decidim.elections.admin")
      render action: "new"
    end

    on(:exists) do
      flash.now[:alert] = I18n.t("trustees_participatory_spaces.create.exists", scope: "decidim.elections.admin")
      render action: "new"
    end
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'decidim-elections/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb', line 56

def destroy
  enforce_permission_to(:delete, :trustee_participatory_space, trustee_participatory_space:)

  RemoveTrusteeFromParticipatorySpace.call(trustee_participatory_space) do
    on(:ok) do
      flash[:notice] = I18n.t("trustees_participatory_spaces.delete.success", scope: "decidim.elections.admin")
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("trustees_participatory_spaces.delete.invalid", scope: "decidim.elections.admin")
    end
  end

  redirect_to trustees_path
end

#editObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'decidim-elections/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb', line 40

def edit
  enforce_permission_to(:update, :trustee_participatory_space, trustee_participatory_space:)

  UpdateTrusteeParticipatorySpace.call(trustee_participatory_space) do
    on(:ok) do |trustee|
      flash[:notice] = I18n.t("trustees_participatory_spaces.update.success", scope: "decidim.elections.admin", trustee: trustee.user.name)
    end

    on(:invalid) do |trustee|
      flash.now[:alert] = I18n.t("trustees_participatory_spaces.update.invalid", scope: "decidim.elections.admin", trustee: trustee.user.name)
    end

    redirect_to trustees_path
  end
end

#newObject



13
14
15
16
# File 'decidim-elections/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb', line 13

def new
  enforce_permission_to :create, :trustee_participatory_space
  @form = form(TrusteesParticipatorySpaceForm).instance
end