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

Inherits:
ApplicationController show all
Includes:
Filterable
Defined in:
decidim-assemblies/app/controllers/decidim/assemblies/admin/assemblies_controller.rb

Overview

Controller that allows managing assemblies.

Instance Method Summary collapse

Methods inherited from Decidim::Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#copyObject


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

def copy
  enforce_permission_to :create, :assembly
end

#createObject


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

def create
  enforce_permission_to :create, :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


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

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

#indexObject


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

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

#newObject


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

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

#updateObject


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

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

  UpdateAssembly.call(current_assembly, @form) 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