Class: Decidim::Assemblies::Admin::AssembliesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Decidim::Admin::ParticipatorySpaceAdminBreadcrumb, Filterable
Defined in:
app/controllers/decidim/assemblies/admin/assemblies_controller.rb

Overview

Controller that allows managing assemblies.

Instance Method Summary collapse

Instance Method Details

#copyObject



68
69
70
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 68

def copy
  enforce_permission_to :create, :assembly, assembly: collection.find_by(id: params[:parent_id])
end

#createObject



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

def create
  enforce_permission_to :create, :assembly, assembly: parent_assembly
  @form = form(AssemblyForm).from_params(params)

  CreateAssembly.call(@form) do
    on(:ok) do |assembly|
      flash[:notice] = I18n.t("assemblies.create.success", scope: "decidim.admin")
      redirect_to assemblies_path(q: { parent_id_eq: assembly.parent_id })
    end

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

#editObject



42
43
44
45
46
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 42

def edit
  enforce_permission_to :update, :assembly, assembly: current_assembly
  @form = form(AssemblyForm).from_model(current_assembly)
  render layout: "decidim/admin/assembly"
end

#indexObject



14
15
16
17
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 14

def index
  enforce_permission_to :read, :assembly_list
  @assemblies = filtered_collection
end

#newObject



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

def new
  enforce_permission_to :create, :assembly, assembly: parent_assembly
  @form = form(AssemblyForm).instance
  @form.parent_id = params[:parent_id]
end

#updateObject



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

def update
  enforce_permission_to :update, :assembly, assembly: current_assembly
  @form = form(AssemblyForm).from_params(
    assembly_params,
    assembly_id: current_assembly.id
  )

  UpdateAssembly.call(@form, current_assembly) do
    on(:ok) do |assembly|
      flash[:notice] = I18n.t("assemblies.update.success", scope: "decidim.admin")
      redirect_to edit_assembly_path(assembly)
    end

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