Sha256: e884ccedab064bfe8a7de85f4e8fc9784b4c4fe167c0e47d3e5d74d96eed3b95

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
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

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.8 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.7 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.6 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.5 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.4 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.2 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.1 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.22.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.21.2 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.21.1 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.21.0 app/controllers/think_feel_do_engine/memberships_controller.rb
think_feel_do_engine-3.20.1 app/controllers/think_feel_do_engine/memberships_controller.rb