Class: Decidim::Assemblies::Admin::AssembliesTypesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb

Overview

Controller used to manage the available assemblies types for the current organization. As this substitues former i18n simple hash we need to keep these i18n keys for migrations and rollbakcs. So let i18n-tasks know about: i18n-tasks-use t(‘decidim.assemblies.assembly_types.government’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.commission’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.consultative_advisory’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.executive’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.others’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.participatory’) i18n-tasks-use t(‘decidim.assemblies.assembly_types.working_group’) This comment (and the i18n keys) may be removed in future versions

Instance Method Summary collapse

Instance Method Details

#createObject

POST /admin/assemblies_types



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 34

def create
  enforce_permission_to :create, :assembly_type
  @form = assembly_type_form.from_params(params)

  CreateAssembliesType.call(@form) do
    on(:ok) do |_assembly_type|
      flash[:notice] = I18n.t("assemblies_types.create.success", scope: "decidim.admin")
      redirect_to assemblies_types_path
    end

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

#destroyObject

DELETE /admin/assemblies_types/:id



80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 80

def destroy
  enforce_permission_to :destroy, :assembly_type, assembly_type: current_assembly_type

  DestroyAssembliesType.call(current_assembly_type, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("assemblies_types.destroy.success", scope: "decidim.admin")
      redirect_to assemblies_types_path
    end
  end
end

#editObject

GET /admin/assemblies_types/:id/edit



52
53
54
55
56
57
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 52

def edit
  enforce_permission_to :edit, :assembly_type, assembly_type: current_assembly_type
  @form = assembly_type_form
          .from_model(current_assembly_type,
                      assembly_type: current_assembly_type)
end

#indexObject

GET /admin/assemblies_types



23
24
25
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 23

def index
  enforce_permission_to :index, :assembly_type
end

#newObject

GET /admin/assemblies_types/new



28
29
30
31
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 28

def new
  enforce_permission_to :create, :assembly_type
  @form = assembly_type_form.instance
end

#updateObject

PUT /admin/assemblies_types/:id



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb', line 60

def update
  enforce_permission_to :update, :assembly_type, assembly_type: current_assembly_type

  @form = assembly_type_form
          .from_params(params, assembly_type: current_assembly_type)

  UpdateAssembliesType.call(current_assembly_type, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("assemblies_types.update.success", scope: "decidim.admin")
      redirect_to assemblies_types_path
    end

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