Sha256: 19638cd429a6491a11b9e229f1679251707e43ac68d8e533ecf8e82ea1e4e4c4

Contents?: true

Size: 1.97 KB

Versions: 31

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # This controller allows an admin to manage Conference Diploma configuration
      class DiplomasController < Decidim::Conferences::Admin::ApplicationController
        include Concerns::ConferenceAdmin

        def edit
          enforce_permission_to :update, :conference, conference: current_conference

          @form = form(DiplomaForm).from_model(current_conference)
        end

        def update
          enforce_permission_to :update, :conference, conference: current_conference

          @form = form(DiplomaForm).from_params(diploma_params).with_context(conference: current_conference, current_organization: current_organization)

          UpdateDiploma.call(@form, current_conference) do
            on(:ok) do
              flash[:notice] = I18n.t("conferences.update.success", scope: "decidim.admin")
              redirect_to edit_conference_diploma_path(current_conference)
            end

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

        def send_diplomas
          enforce_permission_to :send_diplomas, :conference, conference: current_conference

          SendConferenceDiplomas.call(current_conference, current_user) do
            on(:ok) do
              flash[:notice] = I18n.t("send_diploma.success", scope: "decidim.conferences.admin")
              redirect_to edit_conference_diploma_path(current_conference)
            end

            on(:invalid) do
              flash[:alert] = I18n.t("send_diploma.error", scope: "decidim.conferences.admin")
              redirect_to edit_conference_diploma_path(current_conference)
            end
          end
        end

        private

        def diploma_params
          {
            id: params[:slug]
          }.merge(params[:conference].to_unsafe_h)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-conferences-0.27.9 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.8 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.7 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.6 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.10 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.9 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.5 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.8 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.4 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.3 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.7 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.5 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.2 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.1 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.4 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.0 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.3 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.0.rc2 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.27.0.rc1 app/controllers/decidim/conferences/admin/diplomas_controller.rb
decidim-conferences-0.26.2 app/controllers/decidim/conferences/admin/diplomas_controller.rb