Sha256: b65d1af548b28555c8d278b21cd171a4c63475af925e4e1fcf90224af728d5fa

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

module MnoEnterprise::Concerns::Controllers::OrgInvitesController
  extend ActiveSupport::Concern

  #==================================================================
  # Included methods
  #==================================================================
  # 'included do' causes the included code to be evaluated in the
  # context where it is included rather than being executed in the module's context
  included do
    before_filter :authenticate_user!
  end

  #==================================================================
  # Class methods
  #==================================================================
  module ClassMethods
    # def some_class_method
    #   'some text'
    # end
  end

  #==================================================================
  # Instance methods
  #==================================================================
  # GET /org_invites/1?token=HJuiofjpa45A73255a74F534FDfds
  def show
    @current_user = current_user
    @org_invite = MnoEnterprise::OrgInvite.active.where(id: params[:id], token: params[:token]).first
    redirect_path = mnoe_home_path

    if @org_invite && !@org_invite.expired? && @org_invite.accept!(current_user)
      redirect_path += "#/?dhbRefId=#{ @org_invite.organization.id}"
      message = { notice: "You are now part of #{@org_invite.organization.name}" }
      yield(:success, @org_invite) if block_given?
    elsif @org_invite && @org_invite.expired?
      message = { alert: "It looks like this invite has expired. Please ask your company administrator to resend the invite." }
    else
      message = { alert: "Unfortunately, this invite does not seem to be valid." }
    end

    # Add flash msg in url fragment for the new frontend
    type, msg = message.first
    type = (type == :alert ? :error : :success)
    redirect_path = add_param_to_fragment(redirect_path.to_s, 'flash', [{msg: msg,  type: type}.to_json])

    redirect_to redirect_path, message
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mno-enterprise-api-3.0.2 lib/mno_enterprise/concerns/controllers/org_invites_controller.rb
mno-enterprise-api-2.0.2 lib/mno_enterprise/concerns/controllers/org_invites_controller.rb