Sha256: 8f8eed6e2dc5aea3b04f040e55685d80313204229b13661307371e56ba1b0101

Contents?: true

Size: 1.6 KB

Versions: 51

Compression:

Stored size: 1.6 KB

Contents

require_dependency "think_feel_do_engine/application_controller"

module ThinkFeelDoEngine
  # Allows a clinician to END a participant's study
  class MembershipsController < ApplicationController
    before_action :authenticate_user!, :load_and_authorize_update!

    rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

    def update
      if @membership.update(membership_params)
        flash[:notice] = "Membership successfully updated"
      else
        flash[:alert] = "Unable to save membership changes. End date cannot "\
        " be set prior to tomorrow's date. Please use [Discontinue] or "\
        "[Terminate Access]."
      end

      redirect_to coach_group_patient_dashboards_path(@membership.group)
    end

    def withdraw
      if @membership.withdraw
        flash[:notice] = "Membership successfully withdrawn"
      else
        flash[:alert] = @membership.errors.full_messages.to_sentence
      end

      redirect_to coach_group_patient_dashboards_path(@membership.group)
    end

    def discontinue
      if @membership.discontinue
        flash[:notice] = "Membership successfully ended"
      else
        flash[:alert] = @membership.errors.full_messages.to_sentence
      end

      redirect_to coach_group_patient_dashboards_path(@membership.group)
    end

    private

    def load_and_authorize_update!
      @membership = Membership.find(params[:id])
      authorize! :update, @membership
    end

    def membership_params
      params.require(:membership).permit(:end_date)
    end

    def record_not_found
      flash.now[:alert] = "Unable to find membership"
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
think_feel_do_engine-3.19.9 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.8 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.7 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.6 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.5 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.4 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.3 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.2 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.1 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.19.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.18.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.17.2 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.17.1 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.17.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.16.3 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.16.2 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.16.1 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.15.7 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.16.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.15.6 app/controllers/think_feel_do_engine/memberships_controller.rb