Sha256: 8e9a773fdbba9d20cb9c005e5775e123d0924aa5364d8263d9b3913b1ad154de

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module Effective
  class CpdStatementsController < ApplicationController
    before_action(:authenticate_user!) if defined?(Devise)

    include Effective::WizardController
    include EffectiveCpdHelper

    resource_scope do
      cycle = Effective::CpdCycle.find(params[:cpd_cycle_id])
      EffectiveCpd.CpdStatement.deep.where(cpd_cycle: cycle, user: current_user)
    end

    after_save(if: -> { step == :start }) do
      CpdScorer.new(user: resource.user).score!
    end

    # Enforce cycle availability
    before_action(only: [:show, :update]) do
      cycle = resource.cpd_cycle

      unless cycle.available?
        flash[:danger] = begin
          if cycle.ended?
            "This #{cpd_cycle_label} has ended"
          elsif !cycle.started?
            "This #{cpd_cycle_label} has not yet started"
          else
            "This #{cpd_cycle_label} is unavailable"
          end
        end

        redirect_to(root_path)
      end
    end

    def permitted_params
      model = (params.key?(:effective_cpd_statement) ? :effective_cpd_statement : :cpd_statement)
      case step
      when :start
        params.require(model).permit(:current_step)
      when :activities
        params.require(model).permit(:current_step)
      when :agreements
        params.require(model).permit(:current_step, :confirm_read, :confirm_factual, files: [])
      when :submit
        params.require(model).permit(:current_step, :confirm_readonly)
      when :complete
        raise('unexpected post to complete')
      else
        raise('unexpected step')
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
effective_cpd-0.6.9 app/controllers/effective/cpd_statements_controller.rb