Class: Decidim::Budgets::Admin::ProjectsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, Proposals::Admin::Picker
Defined in:
decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb

Overview

This controller allows an admin to manage projects from a Participatory Process

Instance Method Summary collapse

Methods included from Proposals::Admin::Picker

#proposals_picker

Methods included from ApplicationHelper

#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #resolve_presenter_class, #step_cta_url

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amenders_list_for, #amendments_enabled?, #amendments_for, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods inherited from ApplicationController

#budget

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

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 NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb', line 20

def create
  enforce_permission_to :create, :project

  @form = form(ProjectForm).from_params(params, budget: budget)

  CreateProject.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("projects.create.success", scope: "decidim.budgets.admin")
      redirect_to budget_projects_path(budget)
    end

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

#destroyObject


61
62
63
64
65
66
67
68
69
70
# File 'decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb', line 61

def destroy
  enforce_permission_to :destroy, :project, project: project

  DestroyProject.call(project, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("projects.destroy.success", scope: "decidim.budgets.admin")
      redirect_to budget_projects_path(budget)
    end
  end
end

#editObject


38
39
40
41
42
# File 'decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb', line 38

def edit
  enforce_permission_to :update, :project, project: project
  @form = form(ProjectForm).from_model(project)
  @form.attachment = form(AttachmentForm).instance
end

#newObject


13
14
15
16
17
18
# File 'decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb', line 13

def new
  enforce_permission_to :create, :project
  @form = form(ProjectForm).from_params(
    attachment: form(AttachmentForm).instance
  )
end

#updateObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'decidim-budgets/app/controllers/decidim/budgets/admin/projects_controller.rb', line 44

def update
  enforce_permission_to :update, :project, project: project
  @form = form(ProjectForm).from_params(params, budget: budget)

  UpdateProject.call(@form, project) do
    on(:ok) do
      flash[:notice] = I18n.t("projects.update.success", scope: "decidim.budgets.admin")
      redirect_to budget_projects_path(budget)
    end

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