Class: Decidim::Templates::Admin::BlockUserTemplatesController

Inherits:
ApplicationController show all
Includes:
Paginable, Decidim::TranslatableAttributes
Defined in:
decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods included from Decidim::TranslatableAttributes

#default_locale?

Methods inherited from ApplicationController

#permission_class_chain

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 RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#copyObject



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

def copy
  enforce_permission_to :copy, :template

  CopyTemplate.call(template, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("templates.copy.success", scope: "decidim.admin")
      redirect_to action: :index
    end

    on(:invalid) do
      flash[:alert] = I18n.t("templates.copy.error", scope: "decidim.admin")
      redirect_to action: :index
    end
  end
end

#createObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 73

def create
  enforce_permission_to :create, :template

  @form = form(TemplateForm).from_params(params)

  CreateBlockUserTemplate.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin")
      redirect_to action: :index
    end

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

#destroyObject



40
41
42
43
44
45
46
47
48
49
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 40

def destroy
  enforce_permission_to(:destroy, :template, template:)

  DestroyTemplate.call(template, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("templates.destroy.success", scope: "decidim.admin")
      redirect_to action: :index
    end
  end
end

#editObject



68
69
70
71
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 68

def edit
  enforce_permission_to(:update, :template, template:)
  @form = form(TemplateForm).from_model(template)
end

#fetchObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 10

def fetch
  enforce_permission_to(:read, :template, template:)

  response_object = {
    template: translated_attribute(template.description)
  }

  respond_to do |format|
    format.json do
      render json: response_object.to_json
    end
  end
end

#indexObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 96

def index
  enforce_permission_to :index, :templates
  @templates = paginate(collection)

  respond_to do |format|
    format.html { render :index }
    format.json do
      term = params[:term]

      @templates = search(term)

      render json: @templates.map { |t| { value: t.id, label: translated_attribute(t.name) } }
    end
  end
end

#newObject



91
92
93
94
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 91

def new
  enforce_permission_to :create, :template
  @form = form(TemplateForm).instance
end

#updateObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'decidim-templates/app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 51

def update
  enforce_permission_to(:update, :template, template:)
  @form = form(TemplateForm).from_params(params)
  UpdateTemplate.call(template, @form, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin")
      redirect_to action: :index
    end

    on(:invalid) do |template|
      @template = template
      flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin")
      render action: :edit
    end
  end
end