app/controllers/cas/application_controller.rb in cas-cms-0.1.3 vs app/controllers/cas/application_controller.rb in cas-cms-1.0.0.alpha1

- old
+ new

@@ -3,10 +3,11 @@ protect_from_forgery with: :exception before_action :authenticate_user! before_action :set_current_user before_action :set_user_sites before_action :set_domain + before_action :set_site private def set_current_user @current_user = current_user @@ -19,9 +20,21 @@ def set_domain @domain ||= (ENV["DOMAIN"] || request.domain) if @domain.blank? || (ENV["DOMAIN"].blank? && @domain == "localhost") @domain = ::Cas::Site.first!.domains.first + end + rescue ActiveRecord::RecordNotFound => e + raise Cas::Exceptions::IncompleteSetup, "IncompleteSetup: check README.md. #{e.message}: #{e.inspect}" + end + + def set_site + if params[:site_id].present? + @site = ::Cas::Site.find_by!(slug: params[:site_id]) + else + @site = ::Cas::Site + .where("cas_sites.domains::text[] && '{#{@domain}}'::text[]") + .first! end end end end