Class: Decidim::Initiatives::Admin::InitiativesTypeScopesController

Inherits:
ApplicationController show all
Defined in:
decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb

Overview

Controller used to manage the available initiative type scopes

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permissions_context

Methods inherited from 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

#createObject

POST /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb', line 17

def create
  enforce_permission_to :create, :initiative_type_scope
  @form = initiative_type_scope_form
          .from_params(params, type_id: params[:initiatives_type_id])

  CreateInitiativeTypeScope.call(@form) do
    on(:ok) do |initiative_type_scope|
      flash[:notice] = I18n.t("decidim.initiatives.admin.initiatives_type_scopes.create.success")
      redirect_to edit_initiatives_type_path(initiative_type_scope.type)
    end

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

#destroyObject

DELETE /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id


60
61
62
63
64
65
66
67
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb', line 60

def destroy
  enforce_permission_to :destroy, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
  current_initiative_type_scope.destroy!

  redirect_to edit_initiatives_type_path(current_initiative_type_scope.type), flash: {
    notice: I18n.t("decidim.initiatives.admin.initiatives_type_scopes.destroy.success")
  }
end

#editObject

GET /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id/edit


36
37
38
39
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb', line 36

def edit
  enforce_permission_to :edit, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
  @form = initiative_type_scope_form.from_model(current_initiative_type_scope)
end

#newObject

GET /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/new


11
12
13
14
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb', line 11

def new
  enforce_permission_to :create, :initiative_type_scope
  @form = initiative_type_scope_form.instance
end

#updateObject

PUT /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb', line 42

def update
  enforce_permission_to :update, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
  @form = initiative_type_scope_form.from_params(params)

  UpdateInitiativeTypeScope.call(current_initiative_type_scope, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("decidim.initiatives.admin.initiatives_type_scopes.update.success")
      redirect_to edit_initiatives_type_path(initiative_type_scope.type)
    end

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