Class: Decidim::Conferences::Admin::PartnersController

Inherits:
ApplicationController show all
Includes:
Concerns::ConferenceAdmin, Paginable
Defined in:
decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb

Overview

Controller that allows managing conference speakers.

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

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


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

def create
  enforce_permission_to :create, :partner
  @form = form(Decidim::Conferences::Admin::PartnerForm).from_params(params)

  CreatePartner.call(@form, current_user, current_conference) do
    on(:ok) do
      flash[:notice] = I18n.t("partners.create.success", scope: "decidim.admin")
      redirect_to conference_partners_path(current_conference)
    end

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

#destroyObject


64
65
66
67
68
69
70
71
72
73
74
# File 'decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb', line 64

def destroy
  @partner = collection.find(params[:id])
  enforce_permission_to :destroy, :partner, partner: @partner

  DestroyPartner.call(@partner, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("partners.destroy.success", scope: "decidim.admin")
      redirect_to conference_partners_path(current_conference)
    end
  end
end

#editObject


40
41
42
43
44
# File 'decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb', line 40

def edit
  @partner = collection.find(params[:id])
  enforce_permission_to :update, :partner, partner: @partner
  @form = form(Decidim::Conferences::Admin::PartnerForm).from_model(@partner)
end

#indexObject


12
13
14
15
16
# File 'decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb', line 12

def index
  enforce_permission_to :index, :partner

  @partners = paginate(collection)
end

#newObject


18
19
20
21
# File 'decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb', line 18

def new
  enforce_permission_to :create, :partner
  @form = form(Decidim::Conferences::Admin::PartnerForm).instance
end

#updateObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-conferences/app/controllers/decidim/conferences/admin/partners_controller.rb', line 46

def update
  @partner = collection.find(params[:id])
  enforce_permission_to :update, :partner, partner: @partner
  @form = form(Decidim::Conferences::Admin::PartnerForm).from_params(params)

  UpdatePartner.call(@form, @partner) do
    on(:ok) do
      flash[:notice] = I18n.t("partners.update.success", scope: "decidim.admin")
      redirect_to conference_partners_path(current_conference)
    end

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